Skip to content

Commit

Permalink
feat: allow require for configs (#72)
Browse files Browse the repository at this point in the history
With this PR linting skips prefer import rules for .config.js files, root or nested.

This removes the need to manually ignore these rules on common configuration files.
  • Loading branch information
threequartersjohn authored and satazor committed Oct 10, 2019
1 parent b9d6b19 commit a56e79a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Then enhance it with one or more **addons**:

- `browser` - If you are going to develop code for the browser (assumes you use CommonJS or AMD)
- `node` - If you are going to develop code for [NodeJS](nodejs.org)
- `es-modules`: If you are going to use ES6 import & export instead of CommonJS or AMD
- `es-modules`: If you are going to use ES6 import & export instead of CommonJS or AMD (this rule skips root `[...].config.js` files to avoid ignoring this rule in common configuration files)
- `babel-parser`: Use [babel-eslint](https://github.com/babel/babel-eslint) parser so that you may use language features that are not yet implemented in eslint (e.g.: dynamic imports)
- `react` - If you are going to use [React](https://reactjs.org/) (requires `es6` base configuration or higher)
- `jest` - If you are going to use [Jest](https://facebook.github.io/jest/) to develop tests
Expand Down
6 changes: 6 additions & 0 deletions addons/es-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ module.exports = {
// comment: This should be a warning instead of an error because there are still cases when we must use require.
'prefer-import/prefer-import-over-require': 1,
},
'overrides': [{
'files': '*.config.js',
'rules': {
'prefer-import/prefer-import-over-require': 0,
},
}],
};
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions test/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,19 @@ Array [

exports[`should pass on fixtures/samples/es6-modules/contrived.good.js 1`] = `Array []`;

exports[`should pass on fixtures/samples/es6-modules/require.config.js 1`] = `Array []`;

exports[`should pass on fixtures/samples/es6-modules/require.js 1`] = `
Array [
Object {
"column": 14,
"line": 5,
"rule": "prefer-import/prefer-import-over-require",
"severity": 1,
},
]
`;

exports[`should pass on fixtures/samples/es6-node/fileSize.good.js 1`] = `Array []`;

exports[`should pass on fixtures/samples/es6-node/loudException.good.js 1`] = `Array []`;
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/samples/es6-modules/require.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Made up sample.. not genuine

// [...].config.js file, should not warn against require

const test = require('good');

console.log(test);
7 changes: 7 additions & 0 deletions test/fixtures/samples/es6-modules/require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Made up sample.. not genuine

// Common file, should warn against require

const test = require('bad');

console.log(test);

0 comments on commit a56e79a

Please sign in to comment.