diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 00000000..ed77db98 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,155 @@ +{ + // "disallowCommaBeforeLineBreak": true, + "disallowDanglingUnderscores": { + "allExcept": ["_exception"] + }, + "disallowEmptyBlocks": true, + "disallowImplicitTypeConversion": [ + "binary", + "boolean", + "numeric", + "string" + ], + "disallowKeywords": [ + "with" + ], + "disallowKeywordsOnNewLine": [ + "else" + ], + "disallowMixedSpacesAndTabs": true, + "disallowMultipleLineStrings": true, + "disallowMultipleSpaces": true, + "disallowMultipleVarDecl": true, + "disallowNewlineBeforeBlockStatements": true, + // "disallowPaddingNewlinesInBlock": true, + "disallowQuotedKeysInObjects": true, + "disallowSpaceAfterObjectKeys": true, + "disallowSpaceAfterPrefixUnaryOperators": [ + "++", + "--", + "+", + "-", + "~", + "!" + ], + "disallowSpaceBeforePostfixUnaryOperators": [ + "++", + "--" + ], + "disallowSpacesInCallExpression": true, + "disallowSpacesInsideArrayBrackets": "all", + "disallowSpacesInsideObjectBrackets": true, + "disallowSpacesInsideParentheses": true, + "disallowTrailingComma": true, + "disallowTrailingWhitespace": true, + "disallowYodaConditions": true, + // "maximumLineLength": 80, + // "requireBlocksOnNewline": true, + // "requireCamelCaseOrUpperCaseIdentifiers": true, + "requireCapitalizedConstructors": true, + "requireCommaBeforeLineBreak": true, + "requireCurlyBraces": [ + "if", + "else", + "for", + "while", + "do", + "try", + "catch", + "case", + "default" + ], + "requireDollarBeforejQueryAssignment": true, + "requireDotNotation": true, + // "requireKeywordsOnNewLine": [ + // "else" + // ], + "requireLineBreakAfterVariableAssignment": true, + "requireLineFeedAtFileEnd": true, + "requireOperatorBeforeLineBreak": [ + "?", + "=", + "+", + "-", + "/", + "*", + "==", + "===", + "!=", + "!==", + ">", + ">=", + "<", + "<=" + ], + "requireParenthesesAroundIIFE": true, + "requireSemicolons": true, + "requireSpaceAfterBinaryOperators": [ + "=", + ",", + "+", + "-", + "/", + "*", + "==", + "===", + "!=", + "!==" + ], + "requireSpaceAfterKeywords": [ + "do", + "for", + "if", + "else", + "switch", + "case", + "try", + "catch", + "void", + "while", + "with", + "return", + "typeof", + "function" + ], + "requireSpaceAfterLineComment": true, + "requireSpaceBeforeBinaryOperators": [ + "=", + "+", + "-", + "/", + "*", + "==", + "===", + "!=", + "!==" + ], + "requireSpaceBeforeBlockStatements": true, + "requireSpaceBeforeKeywords": [ + "else", + "while", + "catch" + ], + "requireSpaceBeforeObjectValues": true, + "requireSpaceBetweenArguments": true, + "requireSpacesInAnonymousFunctionExpression": { + "beforeOpeningRoundBrace": true, + "beforeOpeningCurlyBrace": true + }, + "requireSpacesInConditionalExpression": { + "afterTest": true, + "beforeConsequent": true, + "afterConsequent": true, + "beforeAlternate": true + }, + "requireSpacesInForStatement": true, + "validateIndentation": 4, + "validateJSDoc": { + "checkParamNames": true, + "checkRedundantParams": true, + "requireParamTypes": true + }, + "validateLineBreaks": "LF", + "validateParameterSeparator": ", ", + "validateQuoteMarks": "'" +} diff --git a/src/_h5ai/client/js/inc/core/format.js b/src/_h5ai/client/js/inc/core/format.js index 5a3abca5..2e237734 100644 --- a/src/_h5ai/client/js/inc/core/format.js +++ b/src/_h5ai/client/js/inc/core/format.js @@ -59,10 +59,11 @@ modulejs.define('core/format', ['_'], function (_) { function formatNumber(number, padding) { + var str = String(number); if (padding) { - number = ('000' + number).substr(-padding); + str = ('000' + str).substr(-padding); } - return '' + number; + return str; } function formatDate(millis, format) { diff --git a/src/_h5ai/client/js/inc/core/location.js b/src/_h5ai/client/js/inc/core/location.js index b178d3fe..ab2ed992 100644 --- a/src/_h5ai/client/js/inc/core/location.js +++ b/src/_h5ai/client/js/inc/core/location.js @@ -43,12 +43,12 @@ modulejs.define('core/location', ['_', 'modernizr', 'core/settings', 'core/event var hrefsAreDecoded = (function () { - var testpathname = '/a b'; - var a = doc.createElement('a'); + var testpathname = '/a b'; + var a = doc.createElement('a'); - a.href = testpathname; - return uriToPathname(a.href) === testpathname; - }()); + a.href = testpathname; + return uriToPathname(a.href) === testpathname; + }()); function encodedHref(href) { diff --git a/src/_h5ai/client/js/inc/core/types.js b/src/_h5ai/client/js/inc/core/types.js index bd99f4a3..a2a2175e 100644 --- a/src/_h5ai/client/js/inc/core/types.js +++ b/src/_h5ai/client/js/inc/core/types.js @@ -6,8 +6,8 @@ modulejs.define('core/types', ['config', '_'], function (config, _) { function escapeRegExp(sequence) { - return sequence.replace(/[\-\[\]\/\{\}\(\)\+\?\.\\\^\$]/g, "\\$&"); - // return sequence.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); + return sequence.replace(/[\-\[\]\/\{\}\(\)\+\?\.\\\^\$]/g, '\\$&'); + // return sequence.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); } function parse(types) { diff --git a/src/_h5ai/client/js/inc/core/util.js b/src/_h5ai/client/js/inc/core/util.js index ff8bc6fa..74ed06fc 100644 --- a/src/_h5ai/client/js/inc/core/util.js +++ b/src/_h5ai/client/js/inc/core/util.js @@ -24,15 +24,16 @@ modulejs.define('core/util', [], function () { var hre = /^0x[0-9a-f]+$/i; var ore = /^0/; // convert all to strings strip whitespace - var x = ('' + val1).replace(sre, ''); - var y = ('' + val2).replace(sre, ''); + var x = String(val1).replace(sre, ''); + var y = String(val2).replace(sre, ''); // chunk/tokenize - var xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'); - var yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'); + var xN = x.replace(re, '\0$1\0').replace(/\0$/, '').replace(/^\0/, '').split('\0'); + var yN = y.replace(re, '\0$1\0').replace(/\0$/, '').replace(/^\0/, '').split('\0'); // numeric, hex or date detection var xD = parseInt(x.match(hre), 10) || (xN.length !== 1 && x.match(dre) && Date.parse(x)); var yD = parseInt(y.match(hre), 10) || xD && y.match(dre) && Date.parse(y) || null; - var oFxNcL, oFyNcL; + var oFxNcL; + var oFyNcL; // first try and sort Hex codes or Dates if (yD) { if (xD < yD) { @@ -42,14 +43,15 @@ modulejs.define('core/util', [], function () { } } // natural sorting through split numeric strings and default strings - for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc += 1) { + for (var cLoc = 0, numS = Math.max(xN.length, yN.length); cLoc < numS; cLoc += 1) { // find floats not starting with '0', string or 0 if not defined (Clint Priest) oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0; oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0; // handle numeric vs string comparison - number < string - (Kyle Adams) - if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { return (isNaN(oFxNcL)) ? 1 : -1; } - // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2' - else if (typeof oFxNcL !== typeof oFyNcL) { + if (isNaN(oFxNcL) !== isNaN(oFyNcL)) { + return (isNaN(oFxNcL)) ? 1 : -1; + } else if (typeof oFxNcL !== typeof oFyNcL) { + // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2' oFxNcL += ''; oFyNcL += ''; } diff --git a/src/_h5ai/client/js/inc/ext/contextmenu.js b/src/_h5ai/client/js/inc/ext/contextmenu.js index 099cd98f..a15519ec 100644 --- a/src/_h5ai/client/js/inc/ext/contextmenu.js +++ b/src/_h5ai/client/js/inc/ext/contextmenu.js @@ -41,15 +41,13 @@ modulejs.define('ext/contextmenu', ['_', '$', 'core/settings', 'core/resource'], if (entry.type === '-') { $(templateSep).appendTo($ul); - } - else if (entry.type === 'l') { + } else if (entry.type === 'l') { $(templateLabel) .find('.cm-text').text(entry.text).end() .appendTo($ul); - } - else if (entry.type === 'e') { + } else if (entry.type === 'e') { $li = $(templateEntry) .data('cm-id', entry.id) .find('.cm-text').text(entry.text).end() diff --git a/src/_h5ai/client/js/inc/ext/custom.js b/src/_h5ai/client/js/inc/ext/custom.js index 384c815e..e9e503c4 100644 --- a/src/_h5ai/client/js/inc/ext/custom.js +++ b/src/_h5ai/client/js/inc/ext/custom.js @@ -3,7 +3,8 @@ modulejs.define('ext/custom', ['_', '$', 'marked', 'core/settings', 'core/server var settings = _.extend({ enabled: false }, allsettings.custom); - var $header, $footer; + var $header; + var $footer; var duration = 200; @@ -11,7 +12,10 @@ modulejs.define('ext/custom', ['_', '$', 'marked', 'core/settings', 'core/server server.request({action: 'get', custom: true, customHref: item.absHref}, function (response) { - var has_header, has_footer, data, content; + var hasHeader; + var hasFooter; + var data; + var content; if (response) { data = response.custom; @@ -19,26 +23,26 @@ modulejs.define('ext/custom', ['_', '$', 'marked', 'core/settings', 'core/server if (data.header) { content = data.header; if (data.header_type === 'md') { - content = marked(content); + content = marked(content); } $header.html(content).stop().slideDown(duration); - has_header = true; + hasHeader = true; } if (data.footer) { content = data.footer; if (data.footer_type === 'md') { - content = marked(content); + content = marked(content); } $footer.html(content).stop().slideDown(duration); - has_footer = true; + hasFooter = true; } } - if (!has_header) { + if (!hasHeader) { $header.stop().slideUp(duration); } - if (!has_footer) { + if (!hasFooter) { $footer.stop().slideUp(duration); } }); diff --git a/src/_h5ai/client/js/inc/ext/filter.js b/src/_h5ai/client/js/inc/ext/filter.js index eebd6c6d..5a87134a 100644 --- a/src/_h5ai/client/js/inc/ext/filter.js +++ b/src/_h5ai/client/js/inc/ext/filter.js @@ -10,7 +10,9 @@ modulejs.define('ext/filter', ['_', '$', 'core/settings', 'core/resource', 'core ''; var noMatchTemplate = '
'; var inputIsVisible = false; - var $filter, $input, $noMatch; + var $filter; + var $input; + var $noMatch; function filter(re) { diff --git a/src/_h5ai/client/js/inc/ext/google-analytics.js b/src/_h5ai/client/js/inc/ext/google-analytics.js index 5aa55f62..4f629462 100644 --- a/src/_h5ai/client/js/inc/ext/google-analytics.js +++ b/src/_h5ai/client/js/inc/ext/google-analytics.js @@ -16,7 +16,8 @@ modulejs.define('ext/google-analytics-ua', ['_', 'core/settings', 'core/event'], return; } - var el, firstScriptElement; + var el; + var firstScriptElement; win.GoogleAnalyticsObject = id; win[id] = win[id] || function () { diff --git a/src/_h5ai/client/js/inc/ext/info.js b/src/_h5ai/client/js/inc/ext/info.js index ccbca4eb..2a18a483 100644 --- a/src/_h5ai/client/js/inc/ext/info.js +++ b/src/_h5ai/client/js/inc/ext/info.js @@ -4,7 +4,7 @@ modulejs.define('ext/info', ['_', '$', 'modernizr', 'core/settings', 'core/resou enabled: false, show: false, qrcode: true, - qrColor: "#999" + qrColor: '#999' }, allsettings.info); var template = '
' + @@ -29,7 +29,14 @@ modulejs.define('ext/info', ['_', '$', 'modernizr', 'core/settings', 'core/resou '
'; var sepTemplate = ''; var storekey = 'ext/info'; - var $img, $label, $time, $size, $content, $folders, $files, $qrcode; + var $img; + var $label; + var $time; + var $size; + var $content; + var $folders; + var $files; + var $qrcode; var currentFolder; // @@ -49,7 +56,7 @@ modulejs.define('ext/info', ['_', '$', 'modernizr', 'core/settings', 'core/resou function update(item) { var src = item.thumbRational || item.icon; - var isThumb = !!item.thumbRational; + var isThumb = Boolean(item.thumbRational); if (item.isCurrentFolder() || !src) { src = resource.icon('folder'); @@ -143,7 +150,7 @@ modulejs.define('ext/info', ['_', '$', 'modernizr', 'core/settings', 'core/resou }); // ensure stored value is boolean, otherwise set default - if (typeof(store.get(storekey)) !== 'boolean') { + if (typeof (store.get(storekey)) !== 'boolean') { store.put(storekey, settings.show); } updateSettings(); diff --git a/src/_h5ai/client/js/inc/ext/peer5.js b/src/_h5ai/client/js/inc/ext/peer5.js index 5ad43ae9..c20f45ae 100644 --- a/src/_h5ai/client/js/inc/ext/peer5.js +++ b/src/_h5ai/client/js/inc/ext/peer5.js @@ -18,11 +18,11 @@ modulejs.define('ext/peer5', ['_', '$', 'core/settings'], function (_, $, allset $.ajax({ url: peer5js, dataType: 'script', - cache:true + cache: true }); // attach to file items, once the DOM is ready - $(function() { + $(function () { $('body').on('click', '.item.file > a', function (e) { diff --git a/src/_h5ai/client/js/inc/ext/piwik-analytics.js b/src/_h5ai/client/js/inc/ext/piwik-analytics.js index bd047f0b..c80eec0c 100755 --- a/src/_h5ai/client/js/inc/ext/piwik-analytics.js +++ b/src/_h5ai/client/js/inc/ext/piwik-analytics.js @@ -15,7 +15,7 @@ modulejs.define('ext/piwik-analytics', ['_', '$', 'core/settings'], function (_, // reference: http://piwik.org/docs/javascript-tracking/ - var pkBaseURL = (("https:" === document.location.protocol) ? "https://" : "http://") + settings.baseURL + '/'; + var pkBaseURL = ((document.location.protocol === 'https:') ? 'https://' : 'http://') + settings.baseURL + '/'; $('