@@ -95,6 +95,14 @@ function Configuration() {
95
95
*/
96
96
this . _fileExtensions = [ ] ;
97
97
98
+ /**
99
+ * List of defined options (not complete).
100
+ *
101
+ * @protected
102
+ * @type {Array }
103
+ */
104
+ this . _definedOptions = [ ] ;
105
+
98
106
/**
99
107
* Default file extensions that would be checked.
100
108
*
@@ -199,13 +207,31 @@ function Configuration() {
199
207
*/
200
208
Configuration . prototype . load = function ( config ) {
201
209
202
- // Apply all the options
210
+ // Load all the options
203
211
this . _processConfig ( config ) ;
204
212
213
+ // Load defaults if they weren't set
214
+ this . _loadDefaults ( config ) ;
215
+
205
216
// Load and apply all the rules
206
217
this . _useRules ( ) ;
207
218
} ;
208
219
220
+ /**
221
+ * Load default values for options which were not defined
222
+ *
223
+ * @private
224
+ */
225
+ Configuration . prototype . _loadDefaults = function ( ) {
226
+ if ( ! this . _isDefined ( 'excludeFiles' ) ) {
227
+ this . _loadExcludedFiles ( this . _defaultExcludedFileMasks ) ;
228
+ }
229
+
230
+ if ( ! this . _isDefined ( 'fileExtensions' ) ) {
231
+ this . _loadFileExtensions ( this . _defaultFileExtensions ) ;
232
+ }
233
+ } ;
234
+
209
235
/**
210
236
* Returns resulting configuration after preset is applied and options are processed.
211
237
*
@@ -437,13 +463,21 @@ Configuration.prototype._processConfig = function(config) {
437
463
options . plugins . forEach ( function ( plugin ) {
438
464
this . _loadPlugin ( plugin , options . configPath ) ;
439
465
} , this ) ;
466
+
467
+ if ( ! this . _isDefined ( 'plugins' ) ) {
468
+ this . _definedOptions . push ( 'plugins' ) ;
469
+ }
440
470
}
441
471
442
472
if ( options . hasOwnProperty ( 'additionalRules' ) ) {
443
473
assert ( Array . isArray ( options . additionalRules ) , '`additionalRules` option requires array value' ) ;
444
474
options . additionalRules . forEach ( function ( rule ) {
445
475
this . _loadAdditionalRule ( rule , options . configPath ) ;
446
476
} , this ) ;
477
+
478
+ if ( ! this . _isDefined ( 'additionalRules' ) ) {
479
+ this . _definedOptions . push ( 'additionalRules' ) ;
480
+ }
447
481
}
448
482
449
483
if ( options . hasOwnProperty ( 'extract' ) ) {
@@ -452,18 +486,10 @@ Configuration.prototype._processConfig = function(config) {
452
486
453
487
if ( options . hasOwnProperty ( 'fileExtensions' ) ) {
454
488
this . _loadFileExtensions ( options . fileExtensions ) ;
455
-
456
- // Set default extensions if there is no presets that could define their own
457
- } else if ( ! options . hasOwnProperty ( 'preset' ) ) {
458
- this . _loadFileExtensions ( this . _defaultFileExtensions ) ;
459
489
}
460
490
461
491
if ( options . hasOwnProperty ( 'excludeFiles' ) ) {
462
492
this . _loadExcludedFiles ( options . excludeFiles ) ;
463
-
464
- // Set default masks if there is no presets that could define their own
465
- } else if ( ! options . hasOwnProperty ( 'preset' ) ) {
466
- this . _loadExcludedFiles ( this . _defaultExcludedFileMasks ) ;
467
493
}
468
494
469
495
if ( options . hasOwnProperty ( 'fix' ) ) {
@@ -543,6 +569,10 @@ Configuration.prototype._loadErrorFilter = function(errorFilter) {
543
569
'`errorFilter` option requires a function or null value'
544
570
) ;
545
571
this . _errorFilter = errorFilter ;
572
+
573
+ if ( ! this . _isDefined ( 'errorFilter' ) ) {
574
+ this . _definedOptions . push ( 'errorFilter' ) ;
575
+ }
546
576
} ;
547
577
548
578
/**
@@ -557,6 +587,10 @@ Configuration.prototype._loadES3 = function(es3) {
557
587
'`es3` option requires boolean or null value'
558
588
) ;
559
589
this . _es3Enabled = Boolean ( es3 ) ;
590
+
591
+ if ( ! this . _isDefined ( 'es3' ) ) {
592
+ this . _definedOptions . push ( 'es3' ) ;
593
+ }
560
594
} ;
561
595
562
596
/**
@@ -587,6 +621,10 @@ Configuration.prototype._loadMaxError = function(options) {
587
621
) ;
588
622
589
623
this . _maxErrors = maxErrors ;
624
+
625
+ if ( ! this . _isDefined ( 'fix' ) ) {
626
+ this . _definedOptions . push ( 'fix' ) ;
627
+ }
590
628
} ;
591
629
592
630
/**
@@ -604,6 +642,10 @@ Configuration.prototype._loadFix = function(fix) {
604
642
) ;
605
643
606
644
this . _fix = fix ;
645
+
646
+ if ( ! this . _isDefined ( 'fix' ) ) {
647
+ this . _definedOptions . push ( 'fix' ) ;
648
+ }
607
649
} ;
608
650
609
651
/**
@@ -631,6 +673,10 @@ Configuration.prototype._loadPreset = function(preset) {
631
673
var presetData = this . _presets [ preset ] ;
632
674
assert ( Boolean ( presetData ) , 'Preset "' + preset + '" does not exist' ) ;
633
675
676
+ if ( ! this . _isDefined ( 'preset' ) ) {
677
+ this . _definedOptions . push ( 'preset' ) ;
678
+ }
679
+
634
680
// Process config from the preset
635
681
this . _processConfig ( this . _presets [ preset ] ) ;
636
682
} ;
@@ -646,9 +692,25 @@ Configuration.prototype._loadFileExtensions = function(extensions) {
646
692
typeof extensions === 'string' || Array . isArray ( extensions ) ,
647
693
'`fileExtensions` option requires string or array value'
648
694
) ;
695
+
649
696
this . _fileExtensions = this . _fileExtensions . concat ( extensions ) . map ( function ( ext ) {
650
697
return ext . toLowerCase ( ) ;
651
698
} ) ;
699
+
700
+ if ( ! this . _isDefined ( 'fileExtensions' ) ) {
701
+ this . _definedOptions . push ( 'fileExtensions' ) ;
702
+ }
703
+ } ;
704
+
705
+ /**
706
+ * Is option defined?
707
+ *
708
+ * @param {String } name - name of the option
709
+ *
710
+ * @return {Boolean }
711
+ */
712
+ Configuration . prototype . _isDefined = function ( name ) {
713
+ return this . _definedOptions . indexOf ( name ) > - 1 ;
652
714
} ;
653
715
654
716
/**
@@ -666,6 +728,10 @@ Configuration.prototype._loadExcludedFiles = function(masks) {
666
728
dot : true
667
729
} ) ;
668
730
} , this ) ;
731
+
732
+ if ( ! this . _isDefined ( 'excludeFiles' ) ) {
733
+ this . _definedOptions . push ( 'excludeFiles' ) ;
734
+ }
669
735
} ;
670
736
671
737
/**
@@ -688,6 +754,10 @@ Configuration.prototype._loadExtract = function(masks) {
688
754
dot : true
689
755
} ) ;
690
756
} , this ) ;
757
+
758
+ if ( ! this . _isDefined ( 'extract' ) ) {
759
+ this . _definedOptions . push ( 'extract' ) ;
760
+ }
691
761
} ;
692
762
693
763
/**
0 commit comments