Skip to content

Commit

Permalink
Add --plugin option
Browse files Browse the repository at this point in the history
So users can specify a custom plugin.

For user that need flowtype support, or whatever the new flavor of the
week will be in the future.

Fixes standard/standard#386
  • Loading branch information
feross committed Feb 4, 2016
1 parent 3b0caae commit f10e85a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
8 changes: 6 additions & 2 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function Cli (opts) {
alias: {
format: 'F',
global: 'globals',
plugin: 'plugins',
help: 'h',
verbose: 'v'
},
Expand All @@ -31,6 +32,7 @@ function Cli (opts) {
],
string: [
'global',
'plugin',
'parser'
]
})
Expand Down Expand Up @@ -77,6 +79,7 @@ function Cli (opts) {
-v, --verbose Show error codes. (so you can ignore specific rules)
--stdin Read file text from stdin.
--global Declare global variable
--plugin Use custom eslint plugin
--parser Use custom js parser (e.g. babel-eslint)
--version Show current version
-h, --help Show usage information
Expand All @@ -91,8 +94,9 @@ function Cli (opts) {
}

var lintOpts = {
parser: argv.parser,
global: argv.global
globals: argv.global,
plugins: argv.plugin,
parser: argv.parser
}

if (argv.stdin) {
Expand Down
26 changes: 18 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function Linter (opts) {

self.eslintConfig = defaults(opts.eslintConfig, {
useEslintrc: false,
globals: []
globals: [],
plugins: []
})
if (!self.eslintConfig) {
throw new Error('No eslintConfig passed.')
Expand All @@ -44,7 +45,8 @@ function Linter (opts) {
*
* @param {string} text file text to lint
* @param {Object=} opts options object
* @param {Array.<string>=} opts.globals global variables to declare
* @param {Array.<string>=} opts.globals custom global variables to declare
* @param {Array.<string>=} opts.plugins custom eslint plugins
* @param {string=} opts.parser custom js parser (e.g. babel-eslint)
* @param {function(Error, Object)} cb callback
*/
Expand All @@ -69,7 +71,8 @@ Linter.prototype.lintText = function (text, opts, cb) {
* @param {Object=} opts options object
* @param {Array.<string>=} opts.ignore file globs to ignore (has sane defaults)
* @param {string=} opts.cwd current working directory (default: process.cwd())
* @param {Array.<string>=} opts.globals global variables to declare
* @param {Array.<string>=} opts.globals custom global variables to declare
* @param {Array.<string>=} opts.plugins custom eslint plugins
* @param {string=} opts.parser custom js parser (e.g. babel-eslint)
* @param {function(Error, Object)} cb callback
*/
Expand Down Expand Up @@ -117,6 +120,7 @@ Linter.prototype.parseOpts = function (opts) {
opts.ignore = opts.ignore.concat(DEFAULT_IGNORE)

setGlobals(opts.globals || opts.global)
setPlugins(opts.plugins || opts.plugin)
setParser(opts.parser)

var root
Expand All @@ -126,20 +130,26 @@ Linter.prototype.parseOpts = function (opts) {

if (packageOpts) {
setGlobals(packageOpts.globals || packageOpts.global)
setPlugins(packageOpts.plugins || packageOpts.plugin)
if (!opts.parser) setParser(packageOpts.parser)
}
}

function setParser (parser) {
if (!parser) return
opts.eslintConfig.parser = parser
}

function setGlobals (globals) {
if (!globals) return
opts.eslintConfig.globals = self.eslintConfig.globals.concat(globals)
}

function setPlugins (plugins) {
if (!plugins) return
opts.eslintConfig.plugins = self.eslintConfig.plugins.concat(plugins)
}

function setParser (parser) {
if (!parser) return
opts.eslintConfig.parser = parser
}

return opts
}

Expand Down

0 comments on commit f10e85a

Please sign in to comment.