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 --fix option (uses eslint's --fix) #112

Merged
merged 1 commit into from
Jul 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function Cli (opts) {
verbose: 'v'
},
boolean: [
'fix',
'format',
'help',
'stdin',
Expand Down Expand Up @@ -77,19 +78,22 @@ function Cli (opts) {
If FILES is omitted, then all JavaScript source files (*.js, *.jsx) in the current
working directory are checked, recursively.

Certain paths (node_modules/, .git/, coverage/, *.min.js, bundle.js) are
Certain paths (node_modules/, .git/, coverage/, *.min.js, bundle.js, vendor/) are
automatically ignored.

Flags:
%s
-v, --verbose Show error codes. (so you can ignore specific rules)
--stdin Read file text from stdin.
-v, --verbose Show rule names for errors (to ignore specific rules)
--fix Automatically fix problems
--version Show current version
-h, --help Show usage information

Flags (advanced):
--stdin Read file text from stdin
--global Declare global variable
--plugin Use custom eslint plugin
--env Use custom eslint environment
--parser Use custom js parser (e.g. babel-eslint)
--version Show current version
-h, --help Show usage information
*/
}), opts.cmd, fmtMsg)
exit(0)
Expand All @@ -103,6 +107,7 @@ function Cli (opts) {
}

var lintOpts = {
fix: argv.fix,
globals: argv.global,
plugins: argv.plugin,
envs: argv.env,
Expand Down Expand Up @@ -131,6 +136,11 @@ function Cli (opts) {

function onResult (err, result) {
if (err) return onError(err)

if (argv.fix && !argv.stdin) {
opts.eslint.CLIEngine.outputFixes(result)
}

if (!result.errorCount && !result.warningCount) {
exit(0)
return
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function Linter (opts) {

self.eslintConfig = defaults(opts.eslintConfig, {
envs: [],
fix: false,
globals: [],
ignore: false,
plugins: [],
Expand Down Expand Up @@ -124,6 +125,8 @@ Linter.prototype.parseOpts = function (opts) {
if (!opts.ignore) opts.ignore = []
opts.ignore = opts.ignore.concat(DEFAULT_IGNORE)

if (opts.fix != null) opts.eslintConfig.fix = opts.fix

setGlobals(opts.globals || opts.global)
setPlugins(opts.plugins || opts.plugin)
setEnvs(opts.envs || opts.env)
Expand Down