Skip to content

Commit 9f31d95

Browse files
committed
Add test for ESLint with external configuration (and babel-eslint usage)
1 parent 3ba6cf2 commit 9f31d95

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

fixtures/js/eslint-es2018.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const a = { x: 0, y: 1, z: 2 };
2+
const { x, ...b } = a;

test/functional.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,47 @@ module.exports = {
17221722
}, true);
17231723
});
17241724

1725+
it('When enabled, eslint checks for linting errors by using configuration from file', (done) => {
1726+
const cwd = process.cwd();
1727+
after(() => {
1728+
process.chdir(cwd);
1729+
});
1730+
1731+
const appDir = testSetup.createTestAppDir();
1732+
const config = testSetup.createWebpackConfig(appDir, 'www/build', 'dev');
1733+
config.setPublicPath('/build');
1734+
config.addEntry('main', './js/eslint-es2018');
1735+
config.enableEslintLoader({
1736+
// Force eslint-loader to output errors instead of sometimes
1737+
// using warnings (see: https://github.com/MoOx/eslint-loader#errors-and-warning)
1738+
emitError: true,
1739+
});
1740+
fs.writeFileSync(
1741+
path.join(appDir, '.eslintrc.js'),
1742+
`
1743+
module.exports = {
1744+
parser: 'babel-eslint',
1745+
rules: {
1746+
'indent': ['error', 2],
1747+
'no-unused-vars': ['error', { 'args': 'all' }]
1748+
}
1749+
} `
1750+
);
1751+
1752+
process.chdir(appDir);
1753+
1754+
testSetup.runWebpack(config, (webpackAssert, stats) => {
1755+
const eslintErrors = stats.toJson().errors[0];
1756+
1757+
expect(eslintErrors).not.to.contain('Parsing error: Unexpected token ..');
1758+
expect(eslintErrors).to.contain('Expected indentation of 0 spaces but found 2');
1759+
expect(eslintErrors).to.contain('\'x\' is assigned a value but never used');
1760+
expect(eslintErrors).to.contain('\'b\' is assigned a value but never used');
1761+
1762+
done();
1763+
}, true);
1764+
});
1765+
17251766
it('Code splitting with dynamic import', (done) => {
17261767
const config = createWebpackConfig('www/build', 'dev');
17271768
config.setPublicPath('/build');

0 commit comments

Comments
 (0)