Skip to content

Commit

Permalink
Add --fix option (uses eslint's --fix)
Browse files Browse the repository at this point in the history
Fixes #107
  • Loading branch information
feross committed Jul 12, 2016
1 parent 06e820a commit 6d2e0c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
20 changes: 15 additions & 5 deletions bin/cmd.js
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
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

0 comments on commit 6d2e0c1

Please sign in to comment.