@@ -95,6 +95,14 @@ function Configuration() {
9595 */
9696 this . _fileExtensions = [ ] ;
9797
98+ /**
99+ * List of defined options (not complete).
100+ *
101+ * @protected
102+ * @type {Array }
103+ */
104+ this . _definedOptions = [ ] ;
105+
98106 /**
99107 * Default file extensions that would be checked.
100108 *
@@ -199,13 +207,31 @@ function Configuration() {
199207 */
200208Configuration . prototype . load = function ( config ) {
201209
202- // Apply all the options
210+ // Load all the options
203211 this . _processConfig ( config ) ;
204212
213+ // Load defaults if they weren't set
214+ this . _loadDefaults ( config ) ;
215+
205216 // Load and apply all the rules
206217 this . _useRules ( ) ;
207218} ;
208219
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+
209235/**
210236 * Returns resulting configuration after preset is applied and options are processed.
211237 *
@@ -437,13 +463,21 @@ Configuration.prototype._processConfig = function(config) {
437463 options . plugins . forEach ( function ( plugin ) {
438464 this . _loadPlugin ( plugin , options . configPath ) ;
439465 } , this ) ;
466+
467+ if ( ! this . _isDefined ( 'plugins' ) ) {
468+ this . _definedOptions . push ( 'plugins' ) ;
469+ }
440470 }
441471
442472 if ( options . hasOwnProperty ( 'additionalRules' ) ) {
443473 assert ( Array . isArray ( options . additionalRules ) , '`additionalRules` option requires array value' ) ;
444474 options . additionalRules . forEach ( function ( rule ) {
445475 this . _loadAdditionalRule ( rule , options . configPath ) ;
446476 } , this ) ;
477+
478+ if ( ! this . _isDefined ( 'additionalRules' ) ) {
479+ this . _definedOptions . push ( 'additionalRules' ) ;
480+ }
447481 }
448482
449483 if ( options . hasOwnProperty ( 'extract' ) ) {
@@ -452,18 +486,10 @@ Configuration.prototype._processConfig = function(config) {
452486
453487 if ( options . hasOwnProperty ( 'fileExtensions' ) ) {
454488 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 ) ;
459489 }
460490
461491 if ( options . hasOwnProperty ( 'excludeFiles' ) ) {
462492 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 ) ;
467493 }
468494
469495 if ( options . hasOwnProperty ( 'fix' ) ) {
@@ -543,6 +569,10 @@ Configuration.prototype._loadErrorFilter = function(errorFilter) {
543569 '`errorFilter` option requires a function or null value'
544570 ) ;
545571 this . _errorFilter = errorFilter ;
572+
573+ if ( ! this . _isDefined ( 'errorFilter' ) ) {
574+ this . _definedOptions . push ( 'errorFilter' ) ;
575+ }
546576} ;
547577
548578/**
@@ -557,6 +587,10 @@ Configuration.prototype._loadES3 = function(es3) {
557587 '`es3` option requires boolean or null value'
558588 ) ;
559589 this . _es3Enabled = Boolean ( es3 ) ;
590+
591+ if ( ! this . _isDefined ( 'es3' ) ) {
592+ this . _definedOptions . push ( 'es3' ) ;
593+ }
560594} ;
561595
562596/**
@@ -587,6 +621,10 @@ Configuration.prototype._loadMaxError = function(options) {
587621 ) ;
588622
589623 this . _maxErrors = maxErrors ;
624+
625+ if ( ! this . _isDefined ( 'fix' ) ) {
626+ this . _definedOptions . push ( 'fix' ) ;
627+ }
590628} ;
591629
592630/**
@@ -604,6 +642,10 @@ Configuration.prototype._loadFix = function(fix) {
604642 ) ;
605643
606644 this . _fix = fix ;
645+
646+ if ( ! this . _isDefined ( 'fix' ) ) {
647+ this . _definedOptions . push ( 'fix' ) ;
648+ }
607649} ;
608650
609651/**
@@ -631,6 +673,10 @@ Configuration.prototype._loadPreset = function(preset) {
631673 var presetData = this . _presets [ preset ] ;
632674 assert ( Boolean ( presetData ) , 'Preset "' + preset + '" does not exist' ) ;
633675
676+ if ( ! this . _isDefined ( 'preset' ) ) {
677+ this . _definedOptions . push ( 'preset' ) ;
678+ }
679+
634680 // Process config from the preset
635681 this . _processConfig ( this . _presets [ preset ] ) ;
636682} ;
@@ -646,9 +692,25 @@ Configuration.prototype._loadFileExtensions = function(extensions) {
646692 typeof extensions === 'string' || Array . isArray ( extensions ) ,
647693 '`fileExtensions` option requires string or array value'
648694 ) ;
695+
649696 this . _fileExtensions = this . _fileExtensions . concat ( extensions ) . map ( function ( ext ) {
650697 return ext . toLowerCase ( ) ;
651698 } ) ;
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 ;
652714} ;
653715
654716/**
@@ -666,6 +728,10 @@ Configuration.prototype._loadExcludedFiles = function(masks) {
666728 dot : true
667729 } ) ;
668730 } , this ) ;
731+
732+ if ( ! this . _isDefined ( 'excludeFiles' ) ) {
733+ this . _definedOptions . push ( 'excludeFiles' ) ;
734+ }
669735} ;
670736
671737/**
@@ -688,6 +754,10 @@ Configuration.prototype._loadExtract = function(masks) {
688754 dot : true
689755 } ) ;
690756 } , this ) ;
757+
758+ if ( ! this . _isDefined ( 'extract' ) ) {
759+ this . _definedOptions . push ( 'extract' ) ;
760+ }
691761} ;
692762
693763/**
0 commit comments