Skip to content

Commit bc444ff

Browse files
committed
eslint/vue: tweak WebpackConfig#enableEslintLoader()
1 parent bdf8ba4 commit bc444ff

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

lib/WebpackConfig.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ class WebpackConfig {
133133
this.vueOptions = {
134134
useJsx: false,
135135
};
136+
this.eslintOptions = {
137+
lintVue: false,
138+
};
136139

137140
// Features/Loaders options callbacks
138141
this.postCssLoaderOptionsCallback = () => {};
@@ -686,31 +689,33 @@ class WebpackConfig {
686689
this.vueOptions = vueOptions;
687690
}
688691

689-
enableEslintLoader(eslintLoaderOptionsOrCallback = () => {}) {
692+
enableEslintLoader(eslintLoaderOptionsOrCallback = () => {}, eslintOptions = {}) {
690693
this.useEslintLoader = true;
691694

692695
if (typeof eslintLoaderOptionsOrCallback === 'function') {
693696
this.eslintLoaderOptionsCallback = eslintLoaderOptionsOrCallback;
694-
return;
695-
}
696-
697-
if (typeof eslintLoaderOptionsOrCallback === 'string') {
697+
} else if (typeof eslintLoaderOptionsOrCallback === 'string') {
698698
logger.deprecation('enableEslintLoader: Extending from a configuration is deprecated, please use a configuration file instead. See https://eslint.org/docs/user-guide/configuring for more information.');
699699

700700
this.eslintLoaderOptionsCallback = (options) => {
701701
options.extends = eslintLoaderOptionsOrCallback;
702702
};
703-
return;
704-
}
705-
706-
if (typeof eslintLoaderOptionsOrCallback === 'object') {
703+
} else if (typeof eslintLoaderOptionsOrCallback === 'object') {
707704
this.eslintLoaderOptionsCallback = (options) => {
708705
Object.assign(options, eslintLoaderOptionsOrCallback);
709706
};
710-
return;
707+
} else {
708+
throw new Error('Argument 1 to enableEslintLoader() must be either a string, object or callback function.');
709+
}
710+
711+
// Check allowed keys
712+
for (const key of Object.keys(eslintOptions)) {
713+
if (!(key in this.eslintOptions)) {
714+
throw new Error(`"${key}" is not a valid key for enableEslintLoader(). Valid keys: ${Object.keys(this.eslintOptions).join(', ')}.`);
715+
}
711716
}
712717

713-
throw new Error('Argument 1 to enableEslintLoader() must be either a string, object or callback function.');
718+
this.eslintOptions = eslintOptions;
714719
}
715720

716721
enableBuildNotifications(enabled = true, notifierPluginOptionsCallback = () => {}) {

test/WebpackConfig.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,4 +1277,16 @@ describe('WebpackConfig object', () => {
12771277
expect(() => config.enableIntegrityHashes(true, ['sha1', 'foo', 'sha256'])).to.throw('Invalid hash algorithm "foo"');
12781278
});
12791279
});
1280+
1281+
describe('enableEslintLoader', () => {
1282+
it('Should validate Encore-specific options', () => {
1283+
const config = createConfig();
1284+
1285+
expect(() => {
1286+
config.enableEslintLoader(() => {}, {
1287+
notExisting: false,
1288+
});
1289+
}).to.throw('"notExisting" is not a valid key for enableEslintLoader(). Valid keys: lintVue.');
1290+
});
1291+
});
12801292
});

0 commit comments

Comments
 (0)