eslint-plugin-n 14.0.0 → 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +90 -97
- package/lib/converted-esm/import-meta-resolve.js +3104 -0
- package/lib/rules/callback-return.js +1 -2
- package/lib/rules/exports-style.js +1 -2
- package/lib/rules/file-extension-in-import.js +5 -12
- package/lib/rules/global-require.js +1 -2
- package/lib/rules/handle-callback-err.js +1 -2
- package/lib/rules/no-callback-literal.js +1 -2
- package/lib/rules/no-deprecated-api.js +7 -11
- package/lib/rules/no-exports-assign.js +1 -2
- package/lib/rules/no-extraneous-import.js +1 -4
- package/lib/rules/no-extraneous-require.js +1 -2
- package/lib/rules/no-hide-core-modules.js +16 -4
- package/lib/rules/no-missing-import.js +1 -4
- package/lib/rules/no-missing-require.js +1 -2
- package/lib/rules/no-mixed-requires.js +1 -2
- package/lib/rules/no-new-require.js +1 -2
- package/lib/rules/no-path-concat.js +1 -2
- package/lib/rules/no-process-env.js +1 -2
- package/lib/rules/no-process-exit.js +1 -2
- package/lib/rules/no-restricted-import.js +1 -2
- package/lib/rules/no-restricted-require.js +1 -2
- package/lib/rules/no-sync.js +1 -2
- package/lib/rules/no-unpublished-bin.js +1 -2
- package/lib/rules/no-unpublished-import.js +1 -4
- package/lib/rules/no-unpublished-require.js +1 -2
- package/lib/rules/no-unsupported-features/es-builtins.js +1 -2
- package/lib/rules/no-unsupported-features/es-syntax.js +1 -2
- package/lib/rules/no-unsupported-features/node-builtins.js +1 -3
- package/lib/rules/no-unsupported-features.js +5 -5
- package/lib/rules/prefer-global/buffer.js +1 -2
- package/lib/rules/prefer-global/console.js +1 -2
- package/lib/rules/prefer-global/process.js +1 -2
- package/lib/rules/prefer-global/text-decoder.js +1 -2
- package/lib/rules/prefer-global/text-encoder.js +1 -2
- package/lib/rules/prefer-global/url-search-params.js +1 -2
- package/lib/rules/prefer-global/url.js +1 -2
- package/lib/rules/prefer-promises/dns.js +1 -2
- package/lib/rules/prefer-promises/fs.js +1 -2
- package/lib/rules/process-exit-as-throw.js +1 -2
- package/lib/rules/shebang.js +1 -2
- package/lib/util/check-publish.js +1 -1
- package/lib/util/get-allow-modules.js +4 -2
- package/lib/util/get-convert-path.js +5 -3
- package/lib/util/get-npmignore.js +2 -1
- package/lib/util/get-resolve-paths.js +4 -2
- package/lib/util/get-try-extensions.js +4 -2
- package/lib/util/import-target.js +54 -7
- package/lib/util/visit-import.js +3 -1
- package/lib/util/visit-require.js +3 -1
- package/package.json +99 -87
package/README.md
CHANGED
|
@@ -1,48 +1,41 @@
|
|
|
1
1
|
# eslint-plugin-n
|
|
2
2
|
|
|
3
|
-
> forked from [eslint-plugin-node](https://www.npmjs.com/package/eslint-plugin-node) v11.1.0. as the original repository seems [
|
|
3
|
+
> forked from [eslint-plugin-node](https://www.npmjs.com/package/eslint-plugin-node) v11.1.0. as the original repository seems [no longer maintained](https://github.com/mysticatea/eslint-plugin-node/issues/300).
|
|
4
4
|
|
|
5
|
-
[](http://www.npmtrends.com/eslint-plugin-node)
|
|
7
|
-
[](https://github.com/mysticatea/eslint-plugin-node/actions)
|
|
8
|
-
[](https://codecov.io/gh/mysticatea/eslint-plugin-node)
|
|
9
|
-
[](https://david-dm.org/mysticatea/eslint-plugin-node)
|
|
5
|
+
[](https://www.npmjs.com/package/eslint-plugin-n) [](http://www.npmtrends.com/eslint-plugin-n) [](https://github.com/weiran-zsd/eslint-plugin-node/actions) [](https://codecov.io/gh/weiran-zsd/eslint-plugin-node) [](https://david-dm.org/weiran-zsd/eslint-plugin-node)
|
|
10
6
|
|
|
11
7
|
Additional ESLint's rules for Node.js
|
|
12
8
|
|
|
13
9
|
## 💿 Install & Usage
|
|
14
10
|
|
|
15
11
|
```
|
|
16
|
-
$ npm install --save-dev eslint eslint-plugin-
|
|
12
|
+
$ npm install --save-dev eslint eslint-plugin-n
|
|
17
13
|
```
|
|
18
14
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
15
|
+
- Requires Node.js `>=12.22.0`
|
|
16
|
+
- Requires ESLint `>=7.0.0`
|
|
21
17
|
|
|
22
|
-
**Note:** It recommends a use of [the "engines" field of package.json](https://docs.npmjs.com/files/package.json#engines). The "engines" field is used by `
|
|
18
|
+
**Note:** It recommends a use of [the "engines" field of package.json](https://docs.npmjs.com/files/package.json#engines). The "engines" field is used by `n/no-unsupported-features/*` rules.
|
|
23
19
|
|
|
24
20
|
**.eslintrc.json** (An example)
|
|
25
21
|
|
|
26
22
|
```jsonc
|
|
27
23
|
{
|
|
28
|
-
"extends": [
|
|
29
|
-
"eslint:recommended",
|
|
30
|
-
"plugin:node/recommended"
|
|
31
|
-
],
|
|
24
|
+
"extends": ["eslint:recommended", "plugin:n/recommended"],
|
|
32
25
|
"parserOptions": {
|
|
33
26
|
// Only ESLint 6.2.0 and later support ES2020.
|
|
34
27
|
"ecmaVersion": 2020
|
|
35
28
|
},
|
|
36
29
|
"rules": {
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
30
|
+
"n/exports-style": ["error", "module.exports"],
|
|
31
|
+
"n/file-extension-in-import": ["error", "always"],
|
|
32
|
+
"n/prefer-global/buffer": ["error", "always"],
|
|
33
|
+
"n/prefer-global/console": ["error", "always"],
|
|
34
|
+
"n/prefer-global/process": ["error", "always"],
|
|
35
|
+
"n/prefer-global/url-search-params": ["error", "always"],
|
|
36
|
+
"n/prefer-global/url": ["error", "always"],
|
|
37
|
+
"n/prefer-promises/dns": "error",
|
|
38
|
+
"n/prefer-promises/fs": "error"
|
|
46
39
|
}
|
|
47
40
|
}
|
|
48
41
|
```
|
|
@@ -62,61 +55,61 @@ $ npm install --save-dev eslint eslint-plugin-node
|
|
|
62
55
|
|
|
63
56
|
## 📖 Rules
|
|
64
57
|
|
|
65
|
-
-
|
|
66
|
-
-
|
|
58
|
+
- ⭐️ - the mark of recommended rules.
|
|
59
|
+
- ✒️ - the mark of fixable rules.
|
|
67
60
|
|
|
68
61
|
<!--RULES_TABLE_START-->
|
|
69
62
|
### Possible Errors
|
|
70
63
|
|
|
71
64
|
| Rule ID | Description | |
|
|
72
65
|
|:--------|:------------|:--:|
|
|
73
|
-
| [
|
|
74
|
-
| [
|
|
75
|
-
| [
|
|
76
|
-
| [
|
|
77
|
-
| [
|
|
78
|
-
| [
|
|
79
|
-
| [
|
|
80
|
-
| [
|
|
81
|
-
| [
|
|
82
|
-
| [
|
|
83
|
-
| [
|
|
84
|
-
| [
|
|
85
|
-
| [
|
|
86
|
-
| [
|
|
87
|
-
| [
|
|
88
|
-
| [
|
|
89
|
-
| [
|
|
90
|
-
| [
|
|
66
|
+
| [n/handle-callback-err](./docs/rules/handle-callback-err.md) | require error handling in callbacks | |
|
|
67
|
+
| [n/no-callback-literal](./docs/rules/no-callback-literal.md) | ensure Node.js-style error-first callback pattern is followed | |
|
|
68
|
+
| [n/no-exports-assign](./docs/rules/no-exports-assign.md) | disallow the assignment to `exports` | ⭐️ |
|
|
69
|
+
| [n/no-extraneous-import](./docs/rules/no-extraneous-import.md) | disallow `import` declarations which import extraneous modules | ⭐️ |
|
|
70
|
+
| [n/no-extraneous-require](./docs/rules/no-extraneous-require.md) | disallow `require()` expressions which import extraneous modules | ⭐️ |
|
|
71
|
+
| [n/no-missing-import](./docs/rules/no-missing-import.md) | disallow `import` declarations which import non-existence modules | ⭐️ |
|
|
72
|
+
| [n/no-missing-require](./docs/rules/no-missing-require.md) | disallow `require()` expressions which import non-existence modules | ⭐️ |
|
|
73
|
+
| [n/no-new-require](./docs/rules/no-new-require.md) | disallow `new` operators with calls to `require` | |
|
|
74
|
+
| [n/no-path-concat](./docs/rules/no-path-concat.md) | disallow string concatenation with `__dirname` and `__filename` | |
|
|
75
|
+
| [n/no-process-exit](./docs/rules/no-process-exit.md) | disallow the use of `process.exit()` | |
|
|
76
|
+
| [n/no-unpublished-bin](./docs/rules/no-unpublished-bin.md) | disallow `bin` files that npm ignores | ⭐️ |
|
|
77
|
+
| [n/no-unpublished-import](./docs/rules/no-unpublished-import.md) | disallow `import` declarations which import private modules | ⭐️ |
|
|
78
|
+
| [n/no-unpublished-require](./docs/rules/no-unpublished-require.md) | disallow `require()` expressions which import private modules | ⭐️ |
|
|
79
|
+
| [n/no-unsupported-features/es-builtins](./docs/rules/no-unsupported-features/es-builtins.md) | disallow unsupported ECMAScript built-ins on the specified version | ⭐️ |
|
|
80
|
+
| [n/no-unsupported-features/es-syntax](./docs/rules/no-unsupported-features/es-syntax.md) | disallow unsupported ECMAScript syntax on the specified version | ⭐️ |
|
|
81
|
+
| [n/no-unsupported-features/node-builtins](./docs/rules/no-unsupported-features/node-builtins.md) | disallow unsupported Node.js built-in APIs on the specified version | ⭐️ |
|
|
82
|
+
| [n/process-exit-as-throw](./docs/rules/process-exit-as-throw.md) | make `process.exit()` expressions the same code path as `throw` | ⭐️ |
|
|
83
|
+
| [n/shebang](./docs/rules/shebang.md) | suggest correct usage of shebang | ⭐️✒️ |
|
|
91
84
|
|
|
92
85
|
### Best Practices
|
|
93
86
|
|
|
94
87
|
| Rule ID | Description | |
|
|
95
88
|
|:--------|:------------|:--:|
|
|
96
|
-
| [
|
|
89
|
+
| [n/no-deprecated-api](./docs/rules/no-deprecated-api.md) | disallow deprecated APIs | ⭐️ |
|
|
97
90
|
|
|
98
91
|
### Stylistic Issues
|
|
99
92
|
|
|
100
93
|
| Rule ID | Description | |
|
|
101
94
|
|:--------|:------------|:--:|
|
|
102
|
-
| [
|
|
103
|
-
| [
|
|
104
|
-
| [
|
|
105
|
-
| [
|
|
106
|
-
| [
|
|
107
|
-
| [
|
|
108
|
-
| [
|
|
109
|
-
| [
|
|
110
|
-
| [
|
|
111
|
-
| [
|
|
112
|
-
| [
|
|
113
|
-
| [
|
|
114
|
-
| [
|
|
115
|
-
| [
|
|
116
|
-
| [
|
|
117
|
-
| [
|
|
118
|
-
| [
|
|
119
|
-
| [
|
|
95
|
+
| [n/callback-return](./docs/rules/callback-return.md) | require `return` statements after callbacks | |
|
|
96
|
+
| [n/exports-style](./docs/rules/exports-style.md) | enforce either `module.exports` or `exports` | |
|
|
97
|
+
| [n/file-extension-in-import](./docs/rules/file-extension-in-import.md) | enforce the style of file extensions in `import` declarations | ✒️ |
|
|
98
|
+
| [n/global-require](./docs/rules/global-require.md) | require `require()` calls to be placed at top-level module scope | |
|
|
99
|
+
| [n/no-mixed-requires](./docs/rules/no-mixed-requires.md) | disallow `require` calls to be mixed with regular variable declarations | |
|
|
100
|
+
| [n/no-process-env](./docs/rules/no-process-env.md) | disallow the use of `process.env` | |
|
|
101
|
+
| [n/no-restricted-import](./docs/rules/no-restricted-import.md) | disallow specified modules when loaded by `import` declarations | |
|
|
102
|
+
| [n/no-restricted-require](./docs/rules/no-restricted-require.md) | disallow specified modules when loaded by `require` | |
|
|
103
|
+
| [n/no-sync](./docs/rules/no-sync.md) | disallow synchronous methods | |
|
|
104
|
+
| [n/prefer-global/buffer](./docs/rules/prefer-global/buffer.md) | enforce either `Buffer` or `require("buffer").Buffer` | |
|
|
105
|
+
| [n/prefer-global/console](./docs/rules/prefer-global/console.md) | enforce either `console` or `require("console")` | |
|
|
106
|
+
| [n/prefer-global/process](./docs/rules/prefer-global/process.md) | enforce either `process` or `require("process")` | |
|
|
107
|
+
| [n/prefer-global/text-decoder](./docs/rules/prefer-global/text-decoder.md) | enforce either `TextDecoder` or `require("util").TextDecoder` | |
|
|
108
|
+
| [n/prefer-global/text-encoder](./docs/rules/prefer-global/text-encoder.md) | enforce either `TextEncoder` or `require("util").TextEncoder` | |
|
|
109
|
+
| [n/prefer-global/url-search-params](./docs/rules/prefer-global/url-search-params.md) | enforce either `URLSearchParams` or `require("url").URLSearchParams` | |
|
|
110
|
+
| [n/prefer-global/url](./docs/rules/prefer-global/url.md) | enforce either `URL` or `require("url").URL` | |
|
|
111
|
+
| [n/prefer-promises/dns](./docs/rules/prefer-promises/dns.md) | enforce `require("dns").promises` | |
|
|
112
|
+
| [n/prefer-promises/fs](./docs/rules/prefer-promises/fs.md) | enforce `require("fs").promises` | |
|
|
120
113
|
|
|
121
114
|
### Deprecated rules
|
|
122
115
|
|
|
@@ -124,8 +117,8 @@ These rules have been deprecated in accordance with the [deprecation policy](htt
|
|
|
124
117
|
|
|
125
118
|
| Rule ID | Replaced by |
|
|
126
119
|
|:--------|:------------|
|
|
127
|
-
| [
|
|
128
|
-
| [
|
|
120
|
+
| [n/no-hide-core-modules](./docs/rules/no-hide-core-modules.md) | (nothing) |
|
|
121
|
+
| [n/no-unsupported-features](./docs/rules/no-unsupported-features.md) | [n/no-unsupported-features/es-syntax](./docs/rules/no-unsupported-features/es-syntax.md) and [n/no-unsupported-features/es-builtins](./docs/rules/no-unsupported-features/es-builtins.md) |
|
|
129
122
|
|
|
130
123
|
<!--RULES_TABLE_END-->
|
|
131
124
|
|
|
@@ -133,48 +126,48 @@ These rules have been deprecated in accordance with the [deprecation policy](htt
|
|
|
133
126
|
|
|
134
127
|
This plugin provides three configs:
|
|
135
128
|
|
|
136
|
-
-
|
|
137
|
-
-
|
|
138
|
-
-
|
|
129
|
+
- `plugin:n/recommended` considers both CommonJS and ES Modules. If [`"type":"module"` field](https://medium.com/@nodejs/announcing-a-new-experimental-modules-1be8d2d6c2ff#b023) existed in package.json then it considers files as ES Modules. Otherwise it considers files as CommonJS. In addition, it considers `*.mjs` files as ES Modules and `*.cjs` files as CommonJS.
|
|
130
|
+
- `plugin:n/recommended-module` considers all files as ES Modules.
|
|
131
|
+
- `plugin:n/recommended-script` considers all files as CommonJS.
|
|
139
132
|
|
|
140
133
|
Those preset config:
|
|
141
134
|
|
|
142
|
-
-
|
|
143
|
-
-
|
|
144
|
-
-
|
|
145
|
-
-
|
|
146
|
-
-
|
|
135
|
+
- enable [no-process-exit](http://eslint.org/docs/rules/no-process-exit) rule because [the official document](https://nodejs.org/api/process.html#process_process_exit_code) does not recommend a use of `process.exit()`.
|
|
136
|
+
- enable plugin rules which are given :star: in the above table.
|
|
137
|
+
- add `{ecmaVersion: 2019}` and etc into `parserOptions`.
|
|
138
|
+
- add proper globals into `globals`.
|
|
139
|
+
- add this plugin into `plugins`.
|
|
147
140
|
|
|
148
141
|
## 👫 FAQ
|
|
149
142
|
|
|
150
|
-
-
|
|
151
|
-
-
|
|
143
|
+
- Q: The `no-missing-import` / `no-missing-require` rules don't work with nested folders in SublimeLinter-eslint
|
|
144
|
+
- A: See [context.getFilename() in rule returns relative path](https://github.com/roadhump/SublimeLinter-eslint#contextgetfilename-in-rule-returns-relative-path) in the SublimeLinter-eslint FAQ.
|
|
152
145
|
|
|
153
146
|
## 🚥 Semantic Versioning Policy
|
|
154
147
|
|
|
155
|
-
`eslint-plugin-
|
|
156
|
-
|
|
157
|
-
-
|
|
158
|
-
-
|
|
159
|
-
-
|
|
160
|
-
-
|
|
161
|
-
-
|
|
162
|
-
-
|
|
163
|
-
-
|
|
164
|
-
-
|
|
165
|
-
-
|
|
166
|
-
-
|
|
167
|
-
-
|
|
168
|
-
-
|
|
169
|
-
-
|
|
170
|
-
-
|
|
171
|
-
-
|
|
172
|
-
-
|
|
173
|
-
-
|
|
148
|
+
`eslint-plugin-n` follows [semantic versioning](http://semver.org/) and [ESLint's Semantic Versioning Policy](https://github.com/eslint/eslint#semantic-versioning-policy).
|
|
149
|
+
|
|
150
|
+
- Patch release (intended to not break your lint build)
|
|
151
|
+
- A bug fix in a rule that results in it reporting fewer errors.
|
|
152
|
+
- Improvements to documentation.
|
|
153
|
+
- Non-user-facing changes such as refactoring code, adding, deleting, or modifying tests, and increasing test coverage.
|
|
154
|
+
- Re-releasing after a failed release (i.e., publishing a release that doesn't work for anyone).
|
|
155
|
+
- Minor release (might break your lint build)
|
|
156
|
+
- A bug fix in a rule that results in it reporting more errors.
|
|
157
|
+
- A new rule is created.
|
|
158
|
+
- A new option to an existing rule is created.
|
|
159
|
+
- An existing rule is deprecated.
|
|
160
|
+
- Major release (likely to break your lint build)
|
|
161
|
+
- A support for old Node version is dropped.
|
|
162
|
+
- A support for old ESLint version is dropped.
|
|
163
|
+
- An existing rule is changed in it reporting more errors.
|
|
164
|
+
- An existing rule is removed.
|
|
165
|
+
- An existing option of a rule is removed.
|
|
166
|
+
- An existing config is updated.
|
|
174
167
|
|
|
175
168
|
## 📰 Changelog
|
|
176
169
|
|
|
177
|
-
-
|
|
170
|
+
- [GitHub Releases](https://github.com/weiran-zsd/eslint-plugin-n/releases)
|
|
178
171
|
|
|
179
172
|
## ❤️ Contributing
|
|
180
173
|
|
|
@@ -184,6 +177,6 @@ Please use GitHub's Issues/PRs.
|
|
|
184
177
|
|
|
185
178
|
### Development Tools
|
|
186
179
|
|
|
187
|
-
-
|
|
188
|
-
-
|
|
189
|
-
-
|
|
180
|
+
- `npm test` runs tests and measures coverage.
|
|
181
|
+
- `npm run coverage` shows the coverage result of `npm test` command.
|
|
182
|
+
- `npm run clean` removes the coverage result of `npm test` command.
|