-
-
Notifications
You must be signed in to change notification settings - Fork 69
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 --fix-to-stdout #53
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ function translateOptions(cliOptions, cwd) { | |
cache: cliOptions.cache, | ||
cacheFile: cliOptions.cacheFile, | ||
cacheLocation: cliOptions.cacheLocation, | ||
fix: cliOptions.fix, | ||
fix: cliOptions.fix || cliOptions.fixToStdout, | ||
allowInlineConfig: cliOptions.inlineConfig, | ||
printConfig: cliOptions.printConfig, | ||
cwd: cwd | ||
|
@@ -49,7 +49,12 @@ module.exports = function (cwd, args, text) { | |
})) | ||
}; | ||
} | ||
var currentOptions = options.parse([0, 0].concat(args)); | ||
var currentOptions; | ||
try { | ||
currentOptions = options.parse([0, 0].concat(args)); | ||
} catch (e) { | ||
return e.message + '\n# exit 1'; | ||
} | ||
cwdDeps.chalk.enabled = currentOptions.color; | ||
var files = currentOptions._; | ||
var stdin = currentOptions.stdin; | ||
|
@@ -74,12 +79,19 @@ module.exports = function (cwd, args, text) { | |
|
||
return JSON.stringify(fileConfig, null, ' '); | ||
} | ||
if (currentOptions.fixToStdout && !stdin) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I see. Checking for |
||
return 'The --fix-to-stdout option must be used with --stdin.' | ||
+ '\n# exit 1'; | ||
} | ||
var report; | ||
if (stdin && text) { | ||
if (stdin) { | ||
report = engine.executeOnText(text, currentOptions.stdinFilename); | ||
} else { | ||
report = engine.executeOnFiles(files); | ||
} | ||
if (currentOptions.fixToStdout) { | ||
return report.results[0].output || text; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to above, there's an edge case here if a user passes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the new option should only allow a single file if not used with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there an easy way to detect a single file? does eslint_d expand globs/directories or does it let eslint do that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Globs are expanded by eslint. Let's take the easy path then and only support |
||
} | ||
if (currentOptions.fix) { | ||
cwdDeps.eslint.CLIEngine.outputFixes(report); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,12 @@ module.exports = optionator({ | |
default: false, | ||
description: 'Automatically fix problems' | ||
}, | ||
{ | ||
option: 'fix-to-stdout', | ||
type: 'Boolean', | ||
description: 'Print the fix results to stdout instead of regular output, ' | ||
+ 'must be used with --stdin' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we assume --stdin or just require it? |
||
}, | ||
{ | ||
option: 'debug', | ||
type: 'Boolean', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aaronjensen Why don't you
let
-bind this variable? It's not a good idea to justsetq
variables this way.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually you could just use
save-excursion
here, if I'm not mistaken. That'll restorepoint
automatically afterwards. Did you try it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately,
save-excursion
doesn't work w/shell-command-on-region
, that was the first I tried. Good idea onlet
though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, too bad, didn't know that.