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

Allow reporterOptions to be passed from the CLI #454

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ you can also ping me [here](https://gitter.im/rossPatton/stylint)

`stylint --reporter stylint-reporter-module` Run stylint with [custom reporter](#custom-reporters) module

`stylint --reporterOptions {"columns": ["file", "lineData", "rule"]}` Run stylint with custom reporterOptions setting

`stylint styl/ --watch -c path/to/config/.configrc` Watch dir, use custom config


Expand Down
8 changes: 7 additions & 1 deletion bin/stylint
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ var options = yargs
type: 'string',
requiresArg: true
} )
.option( 'reporterOptions', {
describe: 'Reporter Options (overrides reporterOptions in .stylintrc)',
type: 'string',
requiresArg: true
} )
.version( function() {
return 'Stylint version: ' + require( '../package' ).version
} )
Expand All @@ -43,5 +48,6 @@ stylint().create( {}, {
watch: options.watch,
config: options.config,
strict: options.strict,
reporter: options.reporter
reporter: options.reporter,
reporterOptions: options.reporterOptions
}, options._.length > 1 ? options._ : options._[0] )
5 changes: 5 additions & 0 deletions src/core/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ var defaultOptions = {
var init = function( options, pathPassed ) {
options = defaults( options || {}, defaultOptions )

if ( options.reporterOptions ) {
this.reporterOptions = options.reporterOptions
}

this.config = this.setConfig( options.config )

// if you want to use transparent mixins, pass in an array of them
Expand Down Expand Up @@ -45,6 +49,7 @@ var init = function( options, pathPassed ) {
return this.watch()
}


return this.read()
}

Expand Down
16 changes: 11 additions & 5 deletions src/utils/setConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ var Glob = require( 'glob' ).Glob
/**
* @description overrides default config with a new config object
* many potential code paths here.
* 1: user passed in config object via function param
* 2: user passes location of .stylintrc file to use via cli
* 3: user has options obj in package.json or path to
* 4: none of the above, fallback to initial config
* 5: user has a .stylintrc file in a dir but doesnt pass anything
* 1: user passed in reporterOptions via cli, plus...
* 2: user passed in config object via function param
* 3: user passes location of .stylintrc file to use via cli
* 4: user has options obj in package.json or path to
* 5: none of the above, fallback to initial config
* 6: user has a .stylintrc file in a dir but doesnt pass anything
* @param {String} [configpath] If defined, the path to a config-file to read
* @returns {Function} kick off linter again
*/
Expand Down Expand Up @@ -148,6 +149,11 @@ var setConfig = function( configpath ) {
// make sure indentPref is set no matter what
returnConfig.indentPref = returnConfig.indentPref || false

// add reporterOptions from the CLI if they exist
if ( this.reporterOptions ) {
returnConfig.reporterOptions = JSON.parse( this.reporterOptions )
}

// 5, just return the default config if nothing found
return returnConfig
}
Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,17 @@ describe( 'Utility Methods: ', function() {
'setConfig err. Expected string, but received: ' + typeof dir
)
} )

it( 'override reporter options via CLI arguments', function() {
var reporterOptions = {
columns: ['file', 'lineData', 'severity', 'rule', 'description'],
columnSplitter: '|'
}
app.init( { reporterOptions: JSON.stringify( reporterOptions ) } )
var actual = app.setConfig( '.stylintrc' )
var expected = Object.assign( {}, testConfig, { reporterOptions: reporterOptions } )
assert.deepEqual( actual, expected )
} )
} )

describe( 'Get Files should: ', function() {
Expand Down