Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --lint-fix option. #591

Merged
merged 1 commit into from May 24, 2016

Conversation

@wprl
Copy link
Contributor

wprl commented May 23, 2016

This PR writes any fixes eslint detects to disk if --lint-fix is used.

@wprl wprl force-pushed the wprl:master branch from df61b50 to 3d285fa May 23, 2016
@wprl wprl changed the title Respect eslint "fix" option and write any fix output back to disk. Add --lint-fix option. May 23, 2016
@wprl

This comment has been minimized.

Copy link
Contributor Author

wprl commented May 23, 2016

Tests pass now!

if (result.hasOwnProperty('output')) {

transformed.fix = {
filePath: result.filePath,

This comment has been minimized.

Copy link
@geek

geek May 23, 2016

Member

shouldn't need filePath set here, can use the filename property of transformed

lib/lint.js Outdated

lint.totalErrors = errors;
lint.totalWarnings = warnings;
result.totalErrors += errors;
result.totalWarnings += warnings;

if (lint.fix) {
Fs.writeFileSync(lint.fix.filePath, lint.fix.output);

This comment has been minimized.

Copy link
@geek

geek May 23, 2016

Member

can use lint.filename

lib/lint.js Outdated
@@ -14,10 +15,22 @@ const internals = {

exports.lint = function (settings, callback) {

const linterOptions = settings['lint-options'] ? [settings['lint-options']] : ['{}'];

This comment has been minimized.

Copy link
@geek

geek May 23, 2016

Member

Can this be changed to something like

let linterOptions = JSON.parse(settings['lint-options'] || '{}');
linterOptions = Object.assign(linterOptions, { fix: !!settings['lint-fix'] });
const linterPath = (settings.linter && settings.linter !== 'eslint') ? settings.linter : internals.linter;

const child = ChildProcess.fork(linterPath, [JSON.stringify(linterOptions)], { cwd: settings.lintingPath });
@geek

This comment has been minimized.

Copy link
Member

geek commented May 23, 2016

@wprl you will need to update the cli definition with the new flag

lab/lib/cli.js

Line 134 in 71b927b

const definition = {
Please also indicate in the readme that the default is to not fix files.

@wprl wprl force-pushed the wprl:master branch from 3d285fa to 1faefd2 May 24, 2016
@wprl

This comment has been minimized.

Copy link
Contributor Author

wprl commented May 24, 2016

How's this look?

lib/lint.js Outdated
linterOptions = JSON.parse(settings['lint-options']);
}
catch (err) {
linterOptions = {};

This comment has been minimized.

Copy link
@geek

geek May 24, 2016

Member

In this case we should throw with an error informing the user that lint-options couldn't be parsed.

lib/lint.js Outdated
}

if (settings['lint-fix']) {
linterOptions.fix = true;

This comment has been minimized.

Copy link
@geek

geek May 24, 2016

Member

can assign directly now that lint-fix is always a boolean:

linterOptions.fix = settings['lint-fix'];
@wprl wprl force-pushed the wprl:master branch from 1faefd2 to 526c992 May 24, 2016
@wprl

This comment has been minimized.

Copy link
Contributor Author

wprl commented May 24, 2016

OK see how you like this revision :)

@geek geek added this to the 10.7.0 milestone May 24, 2016
@geek geek self-assigned this May 24, 2016
@geek geek merged commit b24daf4 into hapijs:master May 24, 2016
2 checks passed
2 checks passed
Node Security No known vulnerabilities found
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.