Skip to content

Commit aa782df

Browse files
committed
eslint/vue: implement getTest() on ESlint loader helper
1 parent bc444ff commit aa782df

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
@@ -69,5 +69,19 @@ Install ${chalk.yellow('babel-eslint')} to prevent potential parsing issues: ${p
6969
};
7070

7171
return applyOptionsCallback(webpackConfig.eslintLoaderOptionsCallback, eslintLoaderOptions);
72+
},
73+
74+
/**
75+
* @param {WebpackConfig} webpackConfig
76+
* @return {RegExp} to use for eslint-loader `test` rule
77+
*/
78+
getTest(webpackConfig) {
79+
const extensions = ['jsx?'];
80+
81+
if (webpackConfig.eslintOptions.lintVue) {
82+
extensions.push('vue');
83+
}
84+
85+
return new RegExp(`\\.(${extensions.join('|')})$`);
7286
}
7387
};

test/loaders/eslint.js

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

0 commit comments

Comments
 (0)