Skip to content

Commit c1f6148

Browse files
committed
eslint/vue: implement getTest() on ESlint loader helper
1 parent 9391a4a commit c1f6148

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/loaders/eslint.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,19 @@ module.exports = {
2828
};
2929

3030
return applyOptionsCallback(webpackConfig.eslintLoaderOptionsCallback, eslintLoaderOptions);
31+
},
32+
33+
/**
34+
* @param {WebpackConfig} webpackConfig
35+
* @return {RegExp} to use for eslint-loader `test` rule
36+
*/
37+
getTest(webpackConfig) {
38+
const extensions = ['jsx?'];
39+
40+
if (webpackConfig.eslintOptions.lintVue) {
41+
extensions.push('vue');
42+
}
43+
44+
return new RegExp(`\\.(${extensions.join('|')})$`);
3145
}
3246
};

test/loaders/eslint.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,21 @@ describe('loaders/eslint', () => {
7777
const actualOptions = eslintLoader.getOptions(config);
7878
expect(actualOptions).to.deep.equals({ foo: true });
7979
});
80+
81+
it('getTest() base behavior', () => {
82+
const config = createConfig();
83+
84+
const actualTest = eslintLoader.getTest(config);
85+
expect(actualTest.toString()).to.equals(/\.(jsx?)$/.toString());
86+
});
87+
88+
it('getTest() with Vue', () => {
89+
const config = createConfig();
90+
config.enableEslintLoader(() => {}, {
91+
lintVue: true,
92+
});
93+
94+
const actualTest = eslintLoader.getTest(config);
95+
expect(actualTest.toString()).to.equals(/\.(jsx?|vue)$/.toString());
96+
});
8097
});

0 commit comments

Comments
 (0)