From f7e790fc8f7a5083653125ed5c5803c386747604 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Sun, 6 Mar 2016 19:15:31 +0100 Subject: [PATCH] Use "replaceall" for relative -> absolute path replacement replace() only replaces the first instance by default which is still causing the original issue if there is more than one file with a lint error --- index.js | 3 ++- package.json | 3 ++- tests/acceptance/acceptanceTest.js | 16 ++++++++++++++++ tests/fixtures/multiple-failing/lintFail.js | 3 +++ tests/fixtures/multiple-failing/lintFailTwo.js | 3 +++ tests/lint/multipleFailingLintTest.js | 8 ++++++++ 6 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/multiple-failing/lintFail.js create mode 100644 tests/fixtures/multiple-failing/lintFailTwo.js create mode 100644 tests/lint/multipleFailingLintTest.js diff --git a/index.js b/index.js index 6f7d3d2..0229c82 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ var CLIEngine = require('eslint').CLIEngine; var chalk = require('chalk'); var globAll = require('glob-all'); +var replaceAll = require("replaceall"); var cli = new CLIEngine({}); @@ -32,7 +33,7 @@ function test(p, opts) { throw new Error( chalk.red('Code did not pass lint rules') + // remove process.cwd() to convert absolute to relative paths - formatter(report.results).replace(process.cwd() + '/', '') + replaceAll(process.cwd() + '/', '', formatter(report.results)) ); } else if ( warn && diff --git a/package.json b/package.json index 065d14d..5cbe532 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "dependencies": { "chalk": "^1.1.0", "eslint": "^2.0.0", - "glob-all": "^3.0.1" + "glob-all": "^3.0.1", + "replaceall": "^0.1.6" }, "devDependencies": { "es6-promise": "^3.1.2", diff --git a/tests/acceptance/acceptanceTest.js b/tests/acceptance/acceptanceTest.js index bdca76b..3e2d0be 100644 --- a/tests/acceptance/acceptanceTest.js +++ b/tests/acceptance/acceptanceTest.js @@ -29,6 +29,22 @@ describe('Acceptance: mocha-eslint', function () { }); }); + it('should fail test for multiple-failing fixture', function () { + return runTest('tests/lint/multipleFailingLintTest.js').then(function (results) { + if (results[4].indexOf('1 failing') === -1) { + throw new Error('Did not get a failing test'); + } + + var reasonsCount = results[6].split('\n') + .filter(function(line) { return line.indexOf('Code did not pass lint rules') !== -1; }) + .length; + + if (reasonsCount !== 1) { + throw new Error('Counted ' + reasonsCount + " failure reasons"); + } + }); + }); + it('should test multiple paths correctly', function () { return runTest('tests/lint/multiplePathTest.js').then(function (results) { if (results[3].indexOf('1 passing') === -1 || diff --git a/tests/fixtures/multiple-failing/lintFail.js b/tests/fixtures/multiple-failing/lintFail.js new file mode 100644 index 0000000..983e7e9 --- /dev/null +++ b/tests/fixtures/multiple-failing/lintFail.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log("this should fail quote rule"); diff --git a/tests/fixtures/multiple-failing/lintFailTwo.js b/tests/fixtures/multiple-failing/lintFailTwo.js new file mode 100644 index 0000000..983e7e9 --- /dev/null +++ b/tests/fixtures/multiple-failing/lintFailTwo.js @@ -0,0 +1,3 @@ +'use strict'; + +console.log("this should fail quote rule"); diff --git a/tests/lint/multipleFailingLintTest.js b/tests/lint/multipleFailingLintTest.js new file mode 100644 index 0000000..ac5718e --- /dev/null +++ b/tests/lint/multipleFailingLintTest.js @@ -0,0 +1,8 @@ +/*eslint-env node, mocha */ +'use strict'; + +var lint = require('../../index.js'); +var paths = ['tests/fixtures/multiple-failing']; +var options = { formatter: 'stylish' }; + +lint(paths, options);