Skip to content

Commit

Permalink
feat(rules): Upgrade rules format for eslint 8.x, with full schemas
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `absolute-or-current-dir` configuration no longer takes
regular expressions, only strings
  • Loading branch information
scottnonnenberg committed Nov 26, 2021
1 parent d8da28e commit eb8e960
Show file tree
Hide file tree
Showing 16 changed files with 1,447 additions and 2,649 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
- ~/.npm
- run:
name: Run tests
command: npm run ci
command: npm run test
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
coverage
!.eslintrc.js
test/end-to-end
19 changes: 6 additions & 13 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
'use strict';

module.exports = {
extends: [
'@scottnonnenberg/thehelp/core',
],

settings: {
'import/resolver': {
node: {
paths: [__dirname],
},
},
env: {
commonjs: true,
node: true,
},

rules: {
'security/detect-object-injection': 'off',
},
extends: [
'eslint:recommended',
],
};
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,18 @@ In your [`eslint`](http://eslint.org/) configuration:
{
"plugins": ["@scottnonnenberg/thehelp"],
"rules": {
"thehelp/absolute-or-current-dir": "error",
"@scottnonnenberg/thehelp/absolute-or-current-dir": "error",
},
}
```

_Note: rules DO NOT include the @scottnonnenberg prefix, even though you might think they should._

And that's it! Details for each rule below.

## Rules:

- [`thehelp/absolute-or-current-dir`](doc/absolute_or_current_dir.md) - all `require()` or `import` calls must either refer to absolute paths or the current directory ('./peer'). Goodbye `../../../`!
- [`thehelp/no-mutation`](doc/no_mutation.md) - prevents mutation of object values, pushing you to a more functional style. `exceptions` configuration allows CommonJS compatibility.
- [`thehelp/no-array-mutation`](doc/no_array_mutation.md) - looks for object calls (`obj.call()`) with function names taken from the list of mutating array methods.
- [`absolute-or-current-dir`](doc/absolute_or_current_dir.md) - all `require()` or `import` calls must either refer to absolute paths or the current directory ('./peer'). Goodbye `../../../`!
- [`no-mutation`](doc/no_mutation.md) - prevents mutation of object values, pushing you to a more functional style. `exceptions` configuration allows CommonJS compatibility.
- [`no-array-mutation`](doc/no_array_mutation.md) - looks for object calls (`obj.call()`) with function names taken from the list of mutating array methods.

## Contributing

Expand Down
12 changes: 6 additions & 6 deletions doc/absolute_or_current_dir.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This rule is designed to prevent this confusing and error-prone pattern:

```javascript
var app = require('../../../lib/app'); # invalid
import app from '../../../lib/app'; # invalid
var app = require('../../../lib/app'); // invalid
import app from '../../../lib/app'; // invalid
```

Instead pushing you to just two options:
Expand All @@ -20,8 +20,8 @@ import peer from './peer';
Either dependencies come from the same directory or an absolute path is required. You can still require node modules like usual. But you can't require something from a child directory:

```javascript
var child = require('./sub/child'); # invalid
import child from './sub/child'; # invalid
var child = require('./sub/child'); // invalid
import child from './sub/child'; // invalid
```

For both of these situations you'd be required to use an absolute path.
Expand Down Expand Up @@ -66,9 +66,9 @@ Now, how to set this up for your application? If you just turn this rule on, you
```javascript
{
'thehelp/absolute-or-current-dir': ['error', {
exceptions: [/setup_module_path$/],
exceptions: [/setup_module_path/],
}]
}
```

`exceptions` is an array of strings (to be compared exactly) or regular expressions which will be compared against the target of the `require()` or `import`. If a match is found, no error is thrown.
`exceptions` is an array of strings which will be compared (exactly or with `endsWith()`) against the target of the `require()` or `import`. If a match is found, no error is thrown.
Loading

0 comments on commit eb8e960

Please sign in to comment.