-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nick Iaconis
committed
Mar 10, 2016
1 parent
55d9773
commit 1b21462
Showing
5 changed files
with
81 additions
and
36 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function noNewLineBeforeReturn() { | ||
const foo = 'foo'; | ||
|
||
console.log(foo); | ||
} | ||
|
||
noNewLineBeforeReturn(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const broccoli = require('broccoli'); | ||
const eslint = require('../../index'); | ||
|
||
module.exports = function runEslint(path, _options) { | ||
const options = _options || {}; | ||
const buildLog = []; | ||
const consoleLog = console.log; | ||
|
||
// stub console.log so we can get the formatter's output | ||
console.log = function appendToBuildLog(...args) { | ||
const text = args.join(' '); | ||
|
||
buildLog.push(text); | ||
}; | ||
|
||
// default options | ||
options.format = options.format || 'eslint/lib/formatters/compact'; | ||
options.options = options.options || {}; | ||
options.options.ignore = options.options.ignore || false; | ||
|
||
const tree = eslint(path, options); | ||
const builder = new broccoli.Builder(tree); | ||
const promise = builder.build().then(function builderThen() { | ||
return buildLog.join('\n'); | ||
}); | ||
|
||
promise.finally(function builderCleanup() { | ||
builder.cleanup(); | ||
|
||
// restore the original console.log | ||
console.log = consoleLog; | ||
}); | ||
|
||
return promise; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,43 @@ | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const rimraf = require('rimraf'); | ||
const runEslint = require('./helpers/run-eslint'); | ||
const NOT_FOUND = -1; | ||
const FIXTURES = 'test/fixture'; | ||
|
||
afterEach(function afterEach() { | ||
rimraf.sync('temp'); | ||
rimraf.sync('broccoli-build.out'); | ||
|
||
it('should report errors', function shouldReportErrors() { | ||
|
||
// lint test fixtures | ||
const promise = runEslint(FIXTURES); | ||
|
||
return promise.then(function assertLinting(buildLog) { | ||
assert(buildLog.indexOf('(camelcase)') !== NOT_FOUND, 'Used eslint validation - camel case'); | ||
assert(buildLog.indexOf('fixture/1.js') !== NOT_FOUND, 'Shows filepath'); | ||
assert(buildLog.indexOf('(no-console)') !== NOT_FOUND, 'Used relative eslint config file'); | ||
}); | ||
}); | ||
|
||
it('should accept rule paths', function shouldAcceptRulePaths() { | ||
// lint test fixtures using a custom rule | ||
const promise = runEslint(FIXTURES, { | ||
options: { | ||
rulePaths: ['conf/rules'] | ||
} | ||
}); | ||
|
||
return promise.then(function assertLinting(buildLog) { | ||
assert(buildLog.indexOf('testing custom rules') !== NOT_FOUND, 'Used custom rule'); | ||
}); | ||
}); | ||
|
||
it('should reported errors', function shouldReportErrors() { | ||
const buildLog = fs.readFileSync('broccoli-build.out').toString(); | ||
const NOT_FOUND = -1; | ||
it('should accept config file path', function shouldAcceptConfigFile() { | ||
// lint test fixtures using a config file at a non-default path | ||
const promise = runEslint(FIXTURES, { | ||
options: { | ||
configFile: 'conf/eslint.json' | ||
} | ||
}); | ||
|
||
assert(buildLog.indexOf('Strings must use doublequote.') !== NOT_FOUND, 'Used eslint validation - strings'); | ||
assert(buildLog.indexOf('is not in camel case') !== NOT_FOUND, 'Used eslint validation - camel case'); | ||
assert(buildLog.indexOf('testing custom rules') !== NOT_FOUND, 'Used custom rulesdir rules'); | ||
assert(buildLog.indexOf('fixture/1.js') !== NOT_FOUND, 'Shows filepath'); | ||
return promise.then(function assertLinting(buildLog) { | ||
assert(buildLog.indexOf('Strings must use doublequote.') !== NOT_FOUND, 'Used alternate config'); | ||
}); | ||
}); |