22var path = require ( 'path' ) ;
33var gutil = require ( 'gulp-util' ) ;
44var through = require ( 'through2' ) ;
5+ var tildify = require ( 'tildify' ) ;
56var Checker = require ( 'jscs' ) ;
67var loadConfigFile = require ( 'jscs/lib/cli-config' ) ;
7- var assign = require ( 'object-assign' ) ;
8- var tildify = require ( 'tildify' ) ;
9-
10- module . exports = function ( options ) {
11- options = options || '.jscsrc' ;
12-
13- if ( typeof options === 'string' ) {
14- options = { configPath : options } ;
15- }
168
17- options = assign ( { } , options ) ;
9+ module . exports = function ( opts ) {
10+ opts = opts || { } ;
1811
1912 var checker = new Checker ( ) ;
2013
2114 checker . registerDefaultRules ( ) ;
2215
23- var configPath = options . configPath ;
24- var shouldFix = options . fix ;
25-
26- delete options . configPath ;
27- delete options . fix ;
16+ try {
17+ checker . configure ( loadConfigFile . load ( opts . configPath ) ) ;
18+ } catch ( err ) {
19+ err . message = 'Unable to load JSCS config file' ;
2820
29- if ( configPath ) {
30- if ( typeof options === 'object' && Object . keys ( options ) . length ) {
31- throw new Error ( 'configPath option is not compatible with code style options' ) ;
21+ if ( opts . configPath ) {
22+ err . message += ' at ' + tildify ( path . resolve ( opts . configPath ) ) ;
3223 }
3324
34- try {
35- checker . configure ( loadConfigFile . load ( configPath ) ) ;
36- } catch ( err ) {
37- err . message = 'Unable to load JSCS config file at ' + tildify ( path . resolve ( configPath ) ) + '\n' + err . message ;
38- throw err ;
39- }
40- } else {
41- checker . configure ( options ) ;
25+ err . message += '\n' + err . message ;
26+
27+ throw err ;
4228 }
4329
4430 return through . obj ( function ( file , enc , cb ) {
@@ -61,7 +47,7 @@ module.exports = function (options) {
6147 var errors ;
6248 var contents = file . contents . toString ( ) ;
6349
64- if ( shouldFix ) {
50+ if ( opts . fix ) {
6551 fixResults = checker . fixString ( contents , file . relative ) ;
6652 errors = fixResults . errors ;
6753 file . contents = new Buffer ( fixResults . output ) ;
0 commit comments