Skip to content

Commit

Permalink
eslint/vue: implement getTest() on ESlint loader helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocal committed Mar 20, 2020
1 parent bc444ff commit aa782df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/loaders/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,19 @@ Install ${chalk.yellow('babel-eslint')} to prevent potential parsing issues: ${p
};

return applyOptionsCallback(webpackConfig.eslintLoaderOptionsCallback, eslintLoaderOptions);
},

/**
* @param {WebpackConfig} webpackConfig
* @return {RegExp} to use for eslint-loader `test` rule
*/
getTest(webpackConfig) {
const extensions = ['jsx?'];

if (webpackConfig.eslintOptions.lintVue) {
extensions.push('vue');
}

return new RegExp(`\\.(${extensions.join('|')})$`);
}
};
17 changes: 17 additions & 0 deletions test/loaders/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,21 @@ describe('loaders/eslint', () => {
const actualOptions = eslintLoader.getOptions(config);
expect(actualOptions).to.deep.equals({ foo: true });
});

it('getTest() base behavior', () => {
const config = createConfig();

const actualTest = eslintLoader.getTest(config);
expect(actualTest.toString()).to.equals(/\.(jsx?)$/.toString());
});

it('getTest() with Vue', () => {
const config = createConfig();
config.enableEslintLoader(() => {}, {
lintVue: true,
});

const actualTest = eslintLoader.getTest(config);
expect(actualTest.toString()).to.equals(/\.(jsx?|vue)$/.toString());
});
});

0 comments on commit aa782df

Please sign in to comment.