From 8f99fa89aac6fcc58f975cb73271d3a3d3c2bf94 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Mon, 21 Mar 2016 23:43:58 +0800 Subject: [PATCH] populate eslint with common rules --- .eslintrc.json | 81 +++++++++++++++++++++++++++++++++++++++++++- assets/master.js | 4 +-- benchmark.js | 2 +- cli.js | 1 + dist/htmlminifier.js | 10 +++--- src/htmlminifier.js | 2 +- src/htmlparser.js | 8 ++--- tests/minifier.js | 30 ++++++++-------- 8 files changed, 109 insertions(+), 29 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index f4f0f74..8d33bb5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,6 +4,7 @@ }, "extends": "eslint:recommended", "rules": { + "block-scoped-var": "error", "brace-style": [ "error", "stroustrup", @@ -11,7 +12,85 @@ "allowSingleLine": true } ], + "comma-spacing": "error", + "comma-style": [ + "error", + "last" + ], + "curly": "error", + "eol-last": "error", + "eqeqeq": "error", + "indent": [ + "error", + 2, + { + "SwitchCase": 1, + "VariableDeclarator": 2 + } + ], + "key-spacing": [ + "error", + { + "beforeColon": false, + "afterColon": true, + "mode": "minimum" + } + ], + "keyword-spacing": "error", + "new-parens": "error", + "no-array-constructor": "error", "no-console": "off", - "no-throw-literal": "error" + "no-floating-decimal": "error", + "no-lone-blocks": "error", + "no-lonely-if": "error", + "no-multiple-empty-lines": "error", + "no-multi-spaces": "error", + "no-new-object": "error", + "no-path-concat": "error", + "no-process-env": "error", + "no-return-assign": "error", + "no-self-compare": "error", + "no-sequences": "error", + "no-spaced-func": "error", + "no-throw-literal": "error", + "no-trailing-spaces": "error", + "no-unused-expressions": "error", + "no-useless-call": "error", + "no-useless-concat": "error", + "no-void": "error", + "object-curly-spacing": [ + "error", + "always" + ], + "operator-assignment": [ + "error", + "always" + ], + "quote-props": [ + "error", + "as-needed" + ], + "quotes": [ + "error", + "single" + ], + "semi": "error", + "semi-spacing": "error", + "space-before-blocks": "error", + "space-unary-ops": "error", + "spaced-comment": [ + "error", + "always", + { + "markers": [ + "!" + ] + } + ], + "wrap-iife": [ + "error", + "inside" + ], + "yoda": "error" } } diff --git a/assets/master.js b/assets/master.js index 084f198..0c06a39 100644 --- a/assets/master.js +++ b/assets/master.js @@ -32,7 +32,7 @@ minifyJS: byId('minify-js').checked, processScripts: byId('minify-js-templates').checked ? byId('minify-js-templates-type').value : false, minifyCSS: byId('minify-css').checked, - minifyURLs: byId('minify-urls').checked ? { site:byId('minify-urls-siteurl').value } : false, + minifyURLs: byId('minify-urls').checked ? { site: byId('minify-urls-siteurl').value } : false, lint: byId('use-htmllint').checked ? new HTMLLint() : null, maxLineLength: parseInt(byId('max-line-length').value, 10) }; @@ -113,6 +113,6 @@ _gaq.push(['_trackPageview']); var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + ga.src = (document.location.protocol === 'https:' ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; document.getElementsByTagName('head')[0].appendChild(ga); })(); diff --git a/benchmark.js b/benchmark.js index 0b5310b..07beea8 100644 --- a/benchmark.js +++ b/benchmark.js @@ -277,7 +277,7 @@ run(fileNames.map(function (fileName) { } }); }).end(querystring.stringify({ - code_type:'html', + code_type: 'html', verbose: 1, html_level: 1, minimize_style: 1, diff --git a/cli.js b/cli.js index 521234e..7582313 100755 --- a/cli.js +++ b/cli.js @@ -176,6 +176,7 @@ cli.main(function(args, options) { if (minified !== null) { // Write the output try { + // eslint-disable-next-line eqeqeq if (output != null) { fs.writeFileSync(path.resolve(output), minified); } diff --git a/dist/htmlminifier.js b/dist/htmlminifier.js index 42df7cd..d6d1758 100644 --- a/dist/htmlminifier.js +++ b/dist/htmlminifier.js @@ -340,7 +340,7 @@ name: name, value: value, customAssign: customAssign || '=', - customOpen: customOpen || '', + customOpen: customOpen || '', customClose: customClose || '', quote: quote || '' }; @@ -448,8 +448,8 @@ } var elems = [], - documentElement = doc.documentElement || - doc.getDocumentElement && doc.getDocumentElement(); + documentElement = doc.documentElement || + doc.getDocumentElement && doc.getDocumentElement(); // If we're dealing with an empty document then we // need to pre-populate it with the HTML document structure @@ -511,7 +511,7 @@ chars: function( text ) { curParentNode.appendChild( doc.createTextNode( text ) ); }, - comment: function( /*text*/ ) { + comment: function( /* text */ ) { // create comment node }, ignore: function( /* text */ ) { @@ -1698,7 +1698,7 @@ return minify(value, options); }; -}(typeof exports === 'undefined' ? this : exports)); +})(typeof exports === 'undefined' ? this : exports); /*! * HTMLLint (to be used in conjunction with HTMLMinifier) diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 12ccba1..c131982 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -1164,4 +1164,4 @@ return minify(value, options); }; -}(typeof exports === 'undefined' ? this : exports)); +})(typeof exports === 'undefined' ? this : exports); diff --git a/src/htmlparser.js b/src/htmlparser.js index f2bbaa5..c7046cf 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -335,7 +335,7 @@ name: name, value: value, customAssign: customAssign || '=', - customOpen: customOpen || '', + customOpen: customOpen || '', customClose: customClose || '', quote: quote || '' }; @@ -443,8 +443,8 @@ } var elems = [], - documentElement = doc.documentElement || - doc.getDocumentElement && doc.getDocumentElement(); + documentElement = doc.documentElement || + doc.getDocumentElement && doc.getDocumentElement(); // If we're dealing with an empty document then we // need to pre-populate it with the HTML document structure @@ -506,7 +506,7 @@ chars: function( text ) { curParentNode.appendChild( doc.createTextNode( text ) ); }, - comment: function( /*text*/ ) { + comment: function( /* text */ ) { // create comment node }, ignore: function( /* text */ ) { diff --git a/tests/minifier.js b/tests/minifier.js index 2eeae18..55bc612 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -777,21 +777,21 @@ output = '
$foo = "baz";
'; equal(minify(input, { collapseWhitespace: true, caseSensitive: true }), output); - input = '' + - '' + - '
' + - '
' + - '' + - '
' + - '
       \r\nxxxx
x Hello billy ' + + input = '' + + ''+ + '
' + + '
' + + '' + + '
' + + '
       \r\nxxxx
x Hello billy ' + '
';
     equal(minify(input, { collapseWhitespace: true }), output);
 
-- 
2.34.1