broccoli-lint-eslint
Advanced tools
Comparing version 0.1.2 to 0.1.3
var eslint = require('./lib/index'), | ||
mergeTrees = require('broccoli-merge-trees'); | ||
mergeTrees = require('broccoli-merge-trees'); | ||
@@ -10,6 +10,6 @@ // lint plugin code | ||
var test = eslint('test', { | ||
rulePaths: ['conf/rules'], | ||
format: 'eslint/lib/formatters/compact' | ||
rulePaths: ['conf/rules'], | ||
format: 'eslint/lib/formatters/compact' | ||
}); | ||
module.exports = mergeTrees([plugin, test], { overwrite: true }); |
110
lib/index.js
@@ -7,19 +7,19 @@ var Filter = require('broccoli-filter'), | ||
* @param {Array} result Eslint verify result array | ||
* @return {Number} If the returned number is greater than 0 the result contains errors. | ||
* @returns {Number} If the returned number is greater than 0 the result contains errors. | ||
*/ | ||
function getResultSeverity (result) { | ||
'use strict'; | ||
'use strict'; | ||
// count all errors | ||
return result.reduce(function (previous, message) { | ||
if (message.fatal) { | ||
return previous + 1; | ||
} | ||
// count all errors | ||
return result.reduce(function (previous, message) { | ||
if (message.fatal) { | ||
return previous + 1; | ||
} | ||
if (message.severity === 2) { | ||
return previous + 1; | ||
} | ||
if (message.severity === 2) { | ||
return previous + 1; | ||
} | ||
return previous; | ||
}, 0); | ||
return previous; | ||
}, 0); | ||
} | ||
@@ -35,31 +35,31 @@ | ||
var EslintValidationFilter = function(inputTree, options, internalOptions) { | ||
'use strict'; | ||
var config = {}; | ||
'use strict'; | ||
var config = {}; | ||
if (!(this instanceof EslintValidationFilter)) { | ||
return new EslintValidationFilter(inputTree, options, internalOptions); | ||
} | ||
this.internalOptions = internalOptions || {}; | ||
// set inputTree | ||
this.inputTree = inputTree; | ||
if (!(this instanceof EslintValidationFilter)) { | ||
return new EslintValidationFilter(inputTree, options, internalOptions); | ||
} | ||
this.internalOptions = internalOptions || {}; | ||
// set inputTree | ||
this.inputTree = inputTree; | ||
options = options || {}; | ||
options = options || {}; | ||
// set formatter | ||
this.formatter = require(options.format || 'eslint/lib/formatters/stylish'); | ||
// set formatter | ||
this.formatter = require(options.format || 'eslint/lib/formatters/stylish'); | ||
this.cleanup = function () {}; | ||
this.cleanup = function () {}; | ||
config.rulePaths = options.rulesdir ? [options.rulesdir] : []; | ||
if ('config' in options) { | ||
config.rulePaths = options.config; | ||
} | ||
config.rulePaths = options.rulesdir ? [options.rulesdir] : []; | ||
if ('config' in options) { | ||
config.rulePaths = options.config; | ||
} | ||
this.cli = new CLIEngine(options); | ||
this.cli = new CLIEngine(options); | ||
this.testGenerator = options.testGenerator; | ||
if (this.testGenerator) { | ||
this.targetExtension = 'eslint-test.js'; | ||
} | ||
this.testGenerator = options.testGenerator; | ||
if (this.testGenerator) { | ||
this.targetExtension = 'eslint-test.js'; | ||
} | ||
}; | ||
@@ -73,33 +73,33 @@ | ||
EslintValidationFilter.prototype.processString = function (content, relativePath) { | ||
'use strict'; | ||
'use strict'; | ||
var messages = []; | ||
var messages = []; | ||
// verify file content | ||
var result = this.cli.executeOnText(content).results[0].messages; | ||
// verify file content | ||
var result = this.cli.executeOnText(content).results[0].messages; | ||
// if verification has result | ||
if (result.length) { | ||
// if verification has result | ||
if (result.length) { | ||
// prepare message format | ||
messages.push({ | ||
filePath: relativePath, | ||
messages: result | ||
}); | ||
// prepare message format | ||
messages.push({ | ||
filePath: relativePath, | ||
messages: result | ||
}); | ||
// log formatter output | ||
console.log(this.formatter(messages)); | ||
// log formatter output | ||
console.log(this.formatter(messages)); | ||
if (getResultSeverity(result) > 0 && 'throwOnError' in this.internalOptions && this.internalOptions.throwOnError === true) { | ||
// throw error if severe messages exist | ||
throw 'severe rule errors'; | ||
} | ||
if (getResultSeverity(result) > 0 && 'throwOnError' in this.internalOptions && this.internalOptions.throwOnError === true) { | ||
// throw error if severe messages exist | ||
throw 'severe rule errors'; | ||
} | ||
} | ||
if (this.testGenerator) { | ||
return this.testGenerator(relativePath, result); | ||
} | ||
if (this.testGenerator) { | ||
return this.testGenerator(relativePath, result); | ||
} | ||
// return unmodified string | ||
return content; | ||
// return unmodified string | ||
return content; | ||
}; |
{ | ||
"name": "broccoli-lint-eslint", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "broccoli filter that runs eslint", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -37,8 +37,8 @@ # [broccoli](https://github.com/joliss/broccoli)-lint-eslint | ||
##### rulesdir | ||
##### rulePaths | ||
Type: `String` | ||
Type: `Array` | ||
Default: [built-in rules directory](https://github.com/eslint/eslint/tree/master/lib/rules) | ||
Path to a directory with custom rules. Your custom rules will be used in addition to the built-in ones. | ||
Paths to a directory with custom rules. Your custom rules will be used in addition to the built-in ones. | ||
@@ -45,0 +45,0 @@ Recommended read: [Working with Rules](https://github.com/eslint/eslint/blob/master/docs/developer-guide/working-with-rules.md) |
20
test.js
'use strict'; | ||
var assert = require('assert'), | ||
fs = require('fs'), | ||
rimraf = require('rimraf'); | ||
fs = require('fs'), | ||
rimraf = require('rimraf'); | ||
afterEach(function () { | ||
rimraf.sync('temp'); | ||
rimraf.sync('broccoli-build.out'); | ||
rimraf.sync('temp'); | ||
rimraf.sync('broccoli-build.out'); | ||
}); | ||
it('should reported errors', function () { | ||
var buildLog = fs.readFileSync('broccoli-build.out').toString(); | ||
var buildLog = fs.readFileSync('broccoli-build.out').toString(); | ||
assert(buildLog.indexOf('Strings must use doublequote.') !== -1, 'Used eslint validation'); | ||
assert(buildLog.indexOf('is not in camel case') !== -1, 'Used eslint validation'); | ||
assert(buildLog.indexOf('testing custom rules') !== -1, 'Used custom rulesdir rules'); | ||
assert(buildLog.indexOf('fixture/1.js') !== -1, 'Shows filepath'); | ||
}); | ||
assert(buildLog.indexOf('Strings must use doublequote.') !== -1, 'Used eslint validation'); | ||
assert(buildLog.indexOf('is not in camel case') !== -1, 'Used eslint validation'); | ||
assert(buildLog.indexOf('testing custom rules') !== -1, 'Used custom rulesdir rules'); | ||
assert(buildLog.indexOf('fixture/1.js') !== -1, 'Shows filepath'); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15356
14
232