Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd --lint-fix option. #591
Conversation
This comment has been minimized.
This comment has been minimized.
Tests pass now! |
lib/linter/index.js
Outdated
if (result.hasOwnProperty('output')) { | ||
|
||
transformed.fix = { | ||
filePath: result.filePath, |
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
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.
This comment has been minimized.
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 });
This comment has been minimized.
This comment has been minimized.
How's this look? |
lib/lint.js
Outdated
linterOptions = JSON.parse(settings['lint-options']); | ||
} | ||
catch (err) { | ||
linterOptions = {}; |
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
geek
May 24, 2016
Member
can assign directly now that lint-fix is always a boolean:
linterOptions.fix = settings['lint-fix'];
This comment has been minimized.
This comment has been minimized.
OK see how you like this revision :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
wprl commentedMay 23, 2016
•
edited
This PR writes any fixes eslint detects to disk if
--lint-fix
is used.