Skip to content

Commit

Permalink
eslint/vue: tweak WebpackConfig#enableEslintLoader()
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocal committed Mar 20, 2020
1 parent bdf8ba4 commit bc444ff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
27 changes: 16 additions & 11 deletions lib/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class WebpackConfig {
this.vueOptions = {
useJsx: false,
};
this.eslintOptions = {
lintVue: false,
};

// Features/Loaders options callbacks
this.postCssLoaderOptionsCallback = () => {};
Expand Down Expand Up @@ -686,31 +689,33 @@ class WebpackConfig {
this.vueOptions = vueOptions;
}

enableEslintLoader(eslintLoaderOptionsOrCallback = () => {}) {
enableEslintLoader(eslintLoaderOptionsOrCallback = () => {}, eslintOptions = {}) {
this.useEslintLoader = true;

if (typeof eslintLoaderOptionsOrCallback === 'function') {
this.eslintLoaderOptionsCallback = eslintLoaderOptionsOrCallback;
return;
}

if (typeof eslintLoaderOptionsOrCallback === 'string') {
} else if (typeof eslintLoaderOptionsOrCallback === 'string') {
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.');

this.eslintLoaderOptionsCallback = (options) => {
options.extends = eslintLoaderOptionsOrCallback;
};
return;
}

if (typeof eslintLoaderOptionsOrCallback === 'object') {
} else if (typeof eslintLoaderOptionsOrCallback === 'object') {
this.eslintLoaderOptionsCallback = (options) => {
Object.assign(options, eslintLoaderOptionsOrCallback);
};
return;
} else {
throw new Error('Argument 1 to enableEslintLoader() must be either a string, object or callback function.');
}

// Check allowed keys
for (const key of Object.keys(eslintOptions)) {
if (!(key in this.eslintOptions)) {
throw new Error(`"${key}" is not a valid key for enableEslintLoader(). Valid keys: ${Object.keys(this.eslintOptions).join(', ')}.`);
}
}

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

enableBuildNotifications(enabled = true, notifierPluginOptionsCallback = () => {}) {
Expand Down
12 changes: 12 additions & 0 deletions test/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -1277,4 +1277,16 @@ describe('WebpackConfig object', () => {
expect(() => config.enableIntegrityHashes(true, ['sha1', 'foo', 'sha256'])).to.throw('Invalid hash algorithm "foo"');
});
});

describe('enableEslintLoader', () => {
it('Should validate Encore-specific options', () => {
const config = createConfig();

expect(() => {
config.enableEslintLoader(() => {}, {
notExisting: false,
});
}).to.throw('"notExisting" is not a valid key for enableEslintLoader(). Valid keys: lintVue.');
});
});
});

0 comments on commit bc444ff

Please sign in to comment.