From f0a111f0966779ca432c8467c3b417557ef6c36c Mon Sep 17 00:00:00 2001 From: Alexey Yaroshevich Date: Tue, 19 Apr 2016 03:37:36 +0300 Subject: [PATCH] chore(lint): add eslint --- .eslintrc | 9 +++++++++ error.js | 6 +++--- index.js | 20 ++++++++++++++------ package.json | 2 ++ test/.eslintrc | 9 +++++++++ 5 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 .eslintrc create mode 100644 test/.eslintrc diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..a99f8e4 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,9 @@ +{ + "parserOptions": { + "ecmaVersion": 6 + }, + "env": { + "node": true + }, + "extends": "pedant" +} diff --git a/error.js b/error.js index 36221dc..31812b3 100644 --- a/error.js +++ b/error.js @@ -6,9 +6,9 @@ var util = require('util'); var format = util.format; /** - * @param {Object} err - * @param {String} code - * @param {String} filepath + * @param {{description: string, column: number, lineNumber: number}} err - Error data + * @param {String} code - Code sample + * @param {String} filepath - Path to the file * @return {String|Object} */ module.exports = function (err, code, filepath) { diff --git a/index.js b/index.js index d08310f..7f7157f 100644 --- a/index.js +++ b/index.js @@ -19,7 +19,8 @@ var pluginName = path.basename(__dirname); /** * bem-xjst templates compiler. * - * @param {Object} options + * @param {{extension: string}} options - Options for generator. + * @param {String} engine - bemhtml or bemtree. * @returns {Stream} */ module.exports = function(options, engine) { @@ -64,7 +65,7 @@ module.exports.bemtree = function(options) { }; module.exports.toHtml = function(tmpl) { - return geval().pipe(through.obj(function(bemjsonFile, encoding, callback) { + return geval().pipe(through.obj(function(bemjsonFile, _, callback) { if (bemjsonFile.isNull()) { return callback(null, bemjsonFile); } @@ -80,11 +81,11 @@ module.exports.toHtml = function(tmpl) { var n = 0; tmpl - .pipe(through.obj(function(file, encoding, callback){ + .pipe(through.obj(function(file, __, tmplCallback){ if (file.isStream()) { - return callback(new PluginError(pluginName, 'Substreaming not supported')); + return tmplCallback(new PluginError(pluginName, 'Substreaming not supported')); } - return callback(null, file); + return tmplCallback(null, file); })) .pipe(geval()) .pipe(through.obj(function(file) { @@ -92,7 +93,7 @@ module.exports.toHtml = function(tmpl) { return callback(null, file); } - var html = tryCatch(_ => file.data.apply(bemjsonFile.data), callback); + var html = tryCatch(() => file.data.apply(bemjsonFile.data), callback); if (!html) { return callback(null); } @@ -108,6 +109,13 @@ module.exports.toHtml = function(tmpl) { })); }; +/** + * Try to run function and call handler if it throws. + * + * @param {Function} fn - Unsafe function body + * @param {Function} cb - Error handler + * @returns {*} + */ function tryCatch(fn, cb) { try { return fn(); diff --git a/package.json b/package.json index df328af..680e541 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,8 @@ "vinyl": "^1.1.1" }, "devDependencies": { + "eslint": "^2.8.0", + "eslint-config-pedant": "^0.3.0", "expect.js": "^0.3.1", "mocha": "^2.1.0" } diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 0000000..e0779d5 --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,9 @@ +{ + "extends": "../.eslintrc", + "env": { + "mocha": true + }, + "rules": { + "no-eval": [1] + } +}