Permalink
Browse files

enforce more eslint rules

  • Loading branch information...
1 parent 1152404 commit 8d428bc7922f1f7841b64a6c0a11f907ae5248a4 @alexlamsl alexlamsl committed Apr 8, 2016
Showing with 311 additions and 302 deletions.
  1. +48 −1 .eslintrc.json
  2. +1 −1 README.md
  3. +1 −1 backtest.js
  4. +40 −40 benchmark.js
  5. +8 −10 cli.js
  6. +46 −64 dist/htmlminifier.js
  7. +3 −3 dist/htmlminifier.min.js
  8. +17 −30 src/htmlminifier.js
  9. +29 −34 src/htmlparser.js
  10. +118 −118 tests/minifier.js
View
@@ -5,6 +5,7 @@
"extends": "eslint:recommended",
"rules": {
"array-bracket-spacing": "error",
+ "array-callback-return": "error",
"block-scoped-var": "error",
"block-spacing": "error",
"brace-style": [
@@ -21,8 +22,17 @@
],
"computed-property-spacing": "error",
"curly": "error",
+ "dot-location": [
+ "error",
+ "property"
+ ],
+ "dot-notation": "error",
"eol-last": "error",
"eqeqeq": "error",
+ "func-style": [
+ "error",
+ "declaration"
+ ],
"indent": [
"error",
2,
@@ -40,28 +50,57 @@
}
],
"keyword-spacing": "error",
+ "linebreak-style": "error",
"new-parens": "error",
"no-array-constructor": "error",
+ "no-caller": "error",
"no-console": "off",
+ "no-else-return": "error",
+ "no-eq-null": "error",
+ "no-eval": "error",
+ "no-extend-native": "error",
+ "no-extra-bind": "error",
+ "no-extra-label": "error",
"no-extra-parens": "error",
"no-floating-decimal": "error",
+ "no-implied-eval": "error",
+ "no-iterator": "error",
"no-lone-blocks": "error",
"no-lonely-if": "error",
"no-multiple-empty-lines": "error",
"no-multi-spaces": "error",
+ "no-multi-str": "error",
+ "no-native-reassign": "error",
+ "no-negated-condition": "error",
+ "no-new-wrappers": "error",
"no-new-object": "error",
+ "no-octal-escape": "error",
"no-path-concat": "error",
"no-process-env": "error",
+ "no-proto": "error",
"no-return-assign": "error",
+ "no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "error",
+ "no-shadow-restricted-names": "error",
"no-spaced-func": "error",
"no-throw-literal": "error",
"no-trailing-spaces": "error",
+ "no-undef-init": "error",
+ "no-undefined": "error",
+ "no-unmodified-loop-condition": "error",
+ "no-unneeded-ternary": "error",
"no-unused-expressions": "error",
+ "no-use-before-define": [
+ "error",
+ "nofunc"
+ ],
"no-useless-call": "error",
"no-useless-concat": "error",
+ "no-useless-escape": "error",
"no-void": "error",
+ "no-whitespace-before-property": "error",
+ "no-with": "error",
"object-curly-spacing": [
"error",
"always"
@@ -70,6 +109,10 @@
"error",
"always"
],
+ "operator-linebreak": [
+ "error",
+ "after"
+ ],
"quote-props": [
"error",
"as-needed"
@@ -81,9 +124,13 @@
"semi": "error",
"semi-spacing": "error",
"space-before-blocks": "error",
+ "space-before-function-paren": [
+ "error",
+ "never"
+ ],
+ "space-in-parens": "error",
"space-infix-ops": "error",
"space-unary-ops": "error",
- "space-in-parens": "error",
"spaced-comment": [
"error",
"always",
View
@@ -43,7 +43,7 @@ How does HTMLMinifier compare to other solutions — [HTML Minifier from Will Pe
| `collapseWhitespace` | [Collapse white space that contributes to text nodes in a document tree](http://perfectionkills.com/experimenting-with-html-minifier/#collapse_whitespace) | `false` |
| `conservativeCollapse` | Always collapse to 1 space (never remove it entirely). Must be used in conjunction with `collapseWhitespace=true` | `false` |
| `customAttrAssign` | Arrays of regex'es that allow to support custom attribute assign expressions (e.g. `'<div flex?="{{mode != cover}}"></div>'`) | `[ ]` |
-| `customAttrCollapse` | Regex that specifies custom attribute to strip newlines from (e.g. `/ng\-class/`) | |
+| `customAttrCollapse` | Regex that specifies custom attribute to strip newlines from (e.g. `/ng-class/`) | |
| `customAttrSurround` | Arrays of regex'es that allow to support custom attribute surround expressions (e.g. `<input {{#if value}}checked="checked"{{/if}}>`) | `[ ]` |
| `customEventAttributes` | Arrays of regex'es that allow to support custom event attributes for `minifyJS` (e.g. `ng-click`) | `[ /^on[a-z]{3,}$/ ]` |
| `decodeEntities` | Use direct Unicode characters whenever possible | `false` |
View
@@ -30,7 +30,7 @@ function readText(filePath, callback) {
}
function writeText(filePath, data) {
- fs.writeFile(filePath, data, { encoding: 'utf8' }, function (err) {
+ fs.writeFile(filePath, data, { encoding: 'utf8' }, function(err) {
if (err) {
throw err;
}
View
@@ -54,7 +54,7 @@ function blueTime(time) {
}
function readBuffer(filePath, callback) {
- fs.readFile(filePath, function (err, data) {
+ fs.readFile(filePath, function(err, data) {
if (err) {
throw new Error('There was an error reading ' + filePath);
}
@@ -63,7 +63,7 @@ function readBuffer(filePath, callback) {
}
function readText(filePath, callback) {
- fs.readFile(filePath, { encoding: 'utf8' }, function (err, data) {
+ fs.readFile(filePath, { encoding: 'utf8' }, function(err, data) {
if (err) {
throw new Error('There was an error reading ' + filePath);
}
@@ -72,7 +72,7 @@ function readText(filePath, callback) {
}
function writeBuffer(filePath, data, callback) {
- fs.writeFile(filePath, data, function (err) {
+ fs.writeFile(filePath, data, function(err) {
if (err) {
throw new Error('There was an error writing ' + filePath);
}
@@ -81,7 +81,7 @@ function writeBuffer(filePath, data, callback) {
}
function writeText(filePath, data, callback) {
- fs.writeFile(filePath, data, { encoding: 'utf8' }, function (err) {
+ fs.writeFile(filePath, data, { encoding: 'utf8' }, function(err) {
if (err) {
throw new Error('There was an error writing ' + filePath);
}
@@ -90,7 +90,7 @@ function writeText(filePath, data, callback) {
}
function readSize(filePath, callback) {
- fs.stat(filePath, function (err, stats) {
+ fs.stat(filePath, function(err, stats) {
if (err) {
throw new Error('There was an error reading ' + filePath);
}
@@ -120,8 +120,8 @@ function run(tasks, done) {
}
var rows = {};
-run(fileNames.map(function (fileName) {
- return function (done) {
+run(fileNames.map(function(fileName) {
+ return function(done) {
progress.tick(0, { fileName: fileName });
var filePath = path.join('benchmarks/', fileName + '.html');
var original = {
@@ -131,7 +131,7 @@ run(fileNames.map(function (fileName) {
brFilePath: path.join('benchmarks/generated/', fileName + '.html.br')
};
var infos = {};
- ['minifier', 'minimize', 'willpeavy', 'compressor'].forEach(function (name) {
+ ['minifier', 'minimize', 'willpeavy', 'compressor'].forEach(function(name) {
infos[name] = {
filePath: path.join('benchmarks/generated/', fileName + '.' + name + '.html'),
gzFilePath: path.join('benchmarks/generated/', fileName + '.' + name + '.html.gz'),
@@ -144,27 +144,27 @@ run(fileNames.map(function (fileName) {
info.endTime = Date.now();
run([
// Apply Gzip on minified output
- function (done) {
- gzip(info.filePath, info.gzFilePath, function () {
+ function(done) {
+ gzip(info.filePath, info.gzFilePath, function() {
info.gzTime = Date.now();
// Open and read the size of the minified+gzip output
- readSize(info.gzFilePath, function (size) {
+ readSize(info.gzFilePath, function(size) {
info.gzSize = size;
done();
});
});
},
// Apply LZMA on minified output
- function (done) {
- readBuffer(info.filePath, function (data) {
- lzma.compress(data, 1, function (result, error) {
+ function(done) {
+ readBuffer(info.filePath, function(data) {
+ lzma.compress(data, 1, function(result, error) {
if (error) {
throw error;
}
- writeBuffer(info.lzFilePath, new Buffer(result), function () {
+ writeBuffer(info.lzFilePath, new Buffer(result), function() {
info.lzTime = Date.now();
// Open and read the size of the minified+lzma output
- readSize(info.lzFilePath, function (size) {
+ readSize(info.lzFilePath, function(size) {
info.lzSize = size;
done();
});
@@ -173,22 +173,22 @@ run(fileNames.map(function (fileName) {
});
},
// Apply Brotli on minified output
- function (done) {
- readBuffer(info.filePath, function (data) {
+ function(done) {
+ readBuffer(info.filePath, function(data) {
var output = new Buffer(brotli.compress(data, true).buffer);
- writeBuffer(info.brFilePath, output, function () {
+ writeBuffer(info.brFilePath, output, function() {
info.brTime = Date.now();
// Open and read the size of the minified+brotli output
- readSize(info.brFilePath, function (size) {
+ readSize(info.brFilePath, function(size) {
info.brSize = size;
done();
});
});
});
},
// Open and read the size of the minified output
- function (done) {
- readSize(info.filePath, function (size) {
+ function(done) {
+ readSize(info.filePath, function(size) {
info.size = size;
done();
});
@@ -200,41 +200,41 @@ run(fileNames.map(function (fileName) {
var info = infos.minifier;
info.startTime = Date.now();
var args = [filePath, '-c', 'sample-cli-config-file.conf', '--minify-urls', urls[fileName], '-o', info.filePath];
- fork('./cli', args).on('exit', function () {
+ fork('./cli', args).on('exit', function() {
readSizes(info, done);
});
}
function testMinimize(done) {
- readBuffer(filePath, function (data) {
- minimize.parse(data, function (error, data) {
+ readBuffer(filePath, function(data) {
+ minimize.parse(data, function(error, data) {
var info = infos.minimize;
- writeBuffer(info.filePath, data, function () {
+ writeBuffer(info.filePath, data, function() {
readSizes(info, done);
});
});
});
}
function testWillPeavy(done) {
- readText(filePath, function (data) {
+ readText(filePath, function(data) {
var options = url.parse('http://www.willpeavy.com/minifier/');
options.method = 'POST';
options.headers = {
'Content-Type': 'application/x-www-form-urlencoded'
};
- http.request(options, function (res) {
+ http.request(options, function(res) {
res.setEncoding('utf8');
var response = '';
- res.on('data', function (chunk) {
+ res.on('data', function(chunk) {
response += chunk;
- }).on('end', function () {
+ }).on('end', function() {
// Extract result from <textarea/>
var start = response.indexOf('>', response.indexOf('<textarea'));
var end = response.lastIndexOf('</textarea>');
var result = response.slice(start + 1, end).replace(/<\\\//g, '</');
var info = infos.willpeavy;
- writeText(info.filePath, result, function () {
+ writeText(info.filePath, result, function() {
readSizes(info, done);
});
});
@@ -245,26 +245,26 @@ run(fileNames.map(function (fileName) {
}
function testHTMLCompressor(done) {
- readText(filePath, function (data) {
+ readText(filePath, function(data) {
var options = url.parse('http://htmlcompressor.com/compress_ajax_v2.php');
options.method = 'POST';
options.headers = {
'Accept-Encoding': 'gzip',
'Content-Type': 'application/x-www-form-urlencoded'
};
- http.request(options, function (res) {
+ http.request(options, function(res) {
if (res.headers['content-encoding'] === 'gzip') {
res = res.pipe(zlib.createGunzip());
}
res.setEncoding('utf8');
var response = '';
- res.on('data', function (chunk) {
+ res.on('data', function(chunk) {
response += chunk;
- }).on('end', function () {
+ }).on('end', function() {
response = JSON.parse(response);
var info = infos.compressor;
if (response.success) {
- writeText(info.filePath, response.result, function () {
+ writeText(info.filePath, response.result, function() {
readSizes(info, done);
});
}
@@ -294,14 +294,14 @@ run(fileNames.map(function (fileName) {
}
run([
- function (done) {
+ function(done) {
readSizes(original, done);
},
testHTMLMinifier,
testMinimize,
testWillPeavy,
testHTMLCompressor
- ], function () {
+ ], function() {
var row = [
[fileName, '+ gzip', '+ lzma', '+ brotli'].join('\n'),
[redSize(original.size), redSize(original.gzSize), redSize(original.lzSize), redSize(original.brSize)].join('\n')
@@ -329,8 +329,8 @@ run(fileNames.map(function (fileName) {
done();
});
};
-}), function () {
- fileNames.forEach(function (fileName) {
+}), function() {
+ fileNames.forEach(function(fileName) {
table.push(rows[fileName]);
});
console.log();
Oops, something went wrong.

0 comments on commit 8d428bc

Please sign in to comment.