Skip to content

Commit

Permalink
Respect eslint "fix" option and write any fix output back to disk.
Browse files Browse the repository at this point in the history
  • Loading branch information
william-riley-land committed May 23, 2016
1 parent 71b927b commit df61b50
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/linter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ exports.lint = function () {
const engine = new Eslint.CLIEngine(configuration);
const results = engine.executeOnFiles(['.']);

Eslint.CLIEngine.outputFixes(results);

return results.results.map((result) => {

return {
Expand Down
14 changes: 14 additions & 0 deletions test/lint/eslint/fix/success.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

// Load modules


// Declare internals

const internals = {};


exports.method = function (value) {

return value;
};
29 changes: 29 additions & 0 deletions test/linters.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Path = require('path');
const _Lab = require('../test_runner');
const Code = require('code');
const Linters = require('../lib/lint');
const Fs = require('fs');


// Test shortcuts
Expand Down Expand Up @@ -151,6 +152,34 @@ describe('Linters - eslint', () => {
done();
});
});

it('should work with fix option', (done) => {

// I would like to intercept a later call to writeFileSync and
// test that it is called correctly, then set `Fs.writeFileSync`
// back to its original function. However, it seems I have
// a different copy of `Fs` here than the code being tested uses.
// To demonstrate this, I've set the value to null, which should
// cause the test to fail, but instead the test passes and changes
// to `test/lint/eslint/fix/success.js` are written to disk.
Fs.writeFileSync = null;

const lintOptions = JSON.stringify({ fix: true, dry: true });
const path = Path.join(__dirname, 'lint', 'eslint', 'fix');
Linters.lint({ lintingPath: path, linter: 'eslint', 'lint-options': lintOptions }, (err, result) => {

expect(err).to.not.exist();
expect(result).to.include('lint');

const eslintResults = result.lint;
expect(eslintResults).to.have.length(1);
expect(eslintResults[0]).to.include({
totalErrors: 0,
totalWarnings: 0
});
done();
});
});
});

describe('Linters - custom', () => {
Expand Down

0 comments on commit df61b50

Please sign in to comment.