Skip to content

Commit

Permalink
Assign default properties to generated config
Browse files Browse the repository at this point in the history
  • Loading branch information
Palle Zingmark committed Oct 30, 2017
1 parent 6fc8f7e commit a190c55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/utils/setConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var path = require( 'path' )
var userHome = require( 'user-home' )
var pathIsAbsolute = require( 'path-is-absolute' )
var stripJsonComments = require( 'strip-json-comments' )
var defaults = require( 'lodash.defaults' )
var Glob = require( 'glob' ).Glob

// @TODO i just this sloppy just to fix some stuff
Expand Down Expand Up @@ -146,10 +147,11 @@ var setConfig = function( configpath ) {
} ).minimatch
} )

// make sure indentPref is set no matter what
returnConfig.indentPref = returnConfig.indentPref || false
// assign default properties to generated config
// to make sure all properties are present
returnConfig = defaults( returnConfig, this.config || {} )

// 5, just return the default config if nothing found
// 5, return complete config
return returnConfig
}

Expand Down
10 changes: 6 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
* lets pull in what we're testing here
*/

var fs = require( 'fs' )
var assert = require( 'assert' )
require( 'chai' ).should() // add should assertions on top
var chokidar = require( 'chokidar' )
var touch = require( 'touch' )
var sinon = require( 'sinon' )
var app = require( '../index' )().create()
var stripJsonComments = require( 'strip-json-comments' )

// turn on strict mode from this point and turn off unnecessary logging
app.state.quiet = true
Expand Down Expand Up @@ -387,10 +385,14 @@ describe( 'Utility Methods: ', function() {
process.argv[2] = '-c'
process.argv[3] = '.stylintrc'
var testMethod = app.setConfig( '.stylintrc' )
var testConfig = JSON.parse( stripJsonComments( fs.readFileSync( process.cwd() + '/.stylintrc', 'utf-8' ) ) )
var testConfig = app.setConfig( process.cwd() + '/.stylintrc' )

it( 'return complete config when not complete config is passed in', function() {
assert.ok( testConfig.reporter )
} )

it( 'update config state if passed a valid path', function() {
assert.deepEqual( testMethod, testConfig )
assert.equal( Object.keys( testConfig ).length, Object.keys( testMethod ).length )
} )

it( 'throw if passed invalid path', function() {
Expand Down

0 comments on commit a190c55

Please sign in to comment.