Skip to content

Commit

Permalink
chore(cr): add shortcut function applyRuleConfigurationCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocal committed Mar 1, 2019
1 parent bc1d025 commit bc0e9bf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ class ConfigGenerator {
}

buildRulesConfig() {
const applyRuleConfigurationCallback = (name, defaultRules) => {
if (!(name in this.webpackConfig.loaderConfigurationCallbacks)) {
throw new Error(`Loader "${name}" is not configurable. Valid loaders are "${Object.keys(this.webpackConfig.loaderConfigurationCallbacks).join('", "')}".`);
}

return applyOptionsCallback(this.webpackConfig.loaderConfigurationCallbacks[name], defaultRules);
};

let rules = [
{
// match .js and .jsx
Expand Down Expand Up @@ -357,7 +365,7 @@ class ConfigGenerator {
}

if (this.webpackConfig.useEslintLoader) {
rules.push(applyOptionsCallback(this.webpackConfig.loaderConfigurationCallbacks['eslint'], {
rules.push(applyRuleConfigurationCallback('eslint', {
test: /\.jsx?$/,
loader: 'eslint-loader',
exclude: /node_modules/,
Expand Down

0 comments on commit bc0e9bf

Please sign in to comment.