Skip to content

Commit 9391a4a

Browse files
committed
eslint/vue: tweak WebpackConfig#enableEslintLoader()
1 parent 2f1c5f7 commit 9391a4a

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
@@ -132,6 +132,9 @@ class WebpackConfig {
132132
this.vueOptions = {
133133
useJsx: false,
134134
};
135+
this.eslintOptions = {
136+
lintVue: false,
137+
};
135138

136139
// Features/Loaders options callbacks
137140
this.postCssLoaderOptionsCallback = () => {};
@@ -663,29 +666,31 @@ class WebpackConfig {
663666
this.vueOptions = vueOptions;
664667
}
665668

666-
enableEslintLoader(eslintLoaderOptionsOrCallback = () => {}) {
669+
enableEslintLoader(eslintLoaderOptionsOrCallback = () => {}, eslintOptions = {}) {
667670
this.useEslintLoader = true;
668671

669672
if (typeof eslintLoaderOptionsOrCallback === 'function') {
670673
this.eslintLoaderOptionsCallback = eslintLoaderOptionsOrCallback;
671-
return;
672-
}
673-
674-
if (typeof eslintLoaderOptionsOrCallback === 'string') {
674+
} else if (typeof eslintLoaderOptionsOrCallback === 'string') {
675675
this.eslintLoaderOptionsCallback = (options) => {
676676
options.extends = eslintLoaderOptionsOrCallback;
677677
};
678-
return;
679-
}
680-
681-
if (typeof eslintLoaderOptionsOrCallback === 'object') {
678+
} else if (typeof eslintLoaderOptionsOrCallback === 'object') {
682679
this.eslintLoaderOptionsCallback = (options) => {
683680
Object.assign(options, eslintLoaderOptionsOrCallback);
684681
};
685-
return;
682+
} else {
683+
throw new Error('Argument 1 to enableEslintLoader() must be either a string, object or callback function.');
684+
}
685+
686+
// Check allowed keys
687+
for (const key of Object.keys(eslintOptions)) {
688+
if (!(key in this.eslintOptions)) {
689+
throw new Error(`"${key}" is not a valid key for enableEslintLoader(). Valid keys: ${Object.keys(this.eslintOptions).join(', ')}.`);
690+
}
686691
}
687692

688-
throw new Error('Argument 1 to enableEslintLoader() must be either a string, object or callback function.');
693+
this.eslintOptions = eslintOptions;
689694
}
690695

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

test/WebpackConfig.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,4 +1259,16 @@ describe('WebpackConfig object', () => {
12591259
expect(() => config.enableIntegrityHashes(true, ['sha1', 'foo', 'sha256'])).to.throw('Invalid hash algorithm "foo"');
12601260
});
12611261
});
1262+
1263+
describe('enableEslintLoader', () => {
1264+
it('Should validate Encore-specific options', () => {
1265+
const config = createConfig();
1266+
1267+
expect(() => {
1268+
config.enableEslintLoader(() => {}, {
1269+
notExisting: false,
1270+
});
1271+
}).to.throw('"notExisting" is not a valid key for enableEslintLoader(). Valid keys: lintVue.');
1272+
});
1273+
});
12621274
});

0 commit comments

Comments
 (0)