Skip to content

Commit

Permalink
Merge pull request #4 from gulp-bem/linting
Browse files Browse the repository at this point in the history
Chore: add eslint
  • Loading branch information
qfox committed Apr 26, 2016
2 parents 2e7a346 + f0a111f commit dacf05f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
9 changes: 9 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"node": true
},
"extends": "pedant"
}
6 changes: 3 additions & 3 deletions error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 14 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -80,19 +81,19 @@ 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) {
if (file.isNull()) {
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);
}
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
9 changes: 9 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../.eslintrc",
"env": {
"mocha": true
},
"rules": {
"no-eval": [1]
}
}

0 comments on commit dacf05f

Please sign in to comment.