eslint-plugin-n 17.23.2 → 18.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 +29 -61
- package/configs/recommended-module.js +2 -3
- package/configs/recommended-script.js +2 -2
- package/lib/all-rules.js +90 -47
- package/lib/configs/_commons.js +2 -5
- package/lib/configs/all.js +3 -4
- package/lib/configs/recommended-module.js +6 -8
- package/lib/configs/recommended-script.js +6 -8
- package/lib/configs/recommended.js +5 -7
- package/lib/eslint-utils.d.ts +125 -60
- package/lib/index.js +8 -10
- package/lib/rules/callback-return.js +4 -7
- package/lib/rules/exports-style.js +21 -10
- package/lib/rules/file-extension-in-import.js +9 -10
- package/lib/rules/global-require.js +10 -11
- package/lib/rules/handle-callback-err.js +4 -8
- package/lib/rules/hashbang.js +16 -15
- package/lib/rules/no-callback-literal.js +3 -5
- package/lib/rules/no-deprecated-api.js +18 -17
- package/lib/rules/no-exports-assign.js +7 -7
- package/lib/rules/no-extraneous-import.js +14 -15
- package/lib/rules/no-extraneous-require.js +16 -17
- package/lib/rules/no-hide-core-modules.js +15 -12
- package/lib/rules/no-missing-import.js +24 -25
- package/lib/rules/no-missing-require.js +18 -19
- package/lib/rules/no-mixed-requires.js +4 -6
- package/lib/rules/no-new-require.js +3 -5
- package/lib/rules/no-path-concat.js +59 -20
- package/lib/rules/no-process-env.js +3 -5
- package/lib/rules/no-process-exit.js +3 -5
- package/lib/rules/no-restricted-import.js +5 -7
- package/lib/rules/no-restricted-require.js +5 -7
- package/lib/rules/no-sync.js +36 -22
- package/lib/rules/no-top-level-await.js +17 -19
- package/lib/rules/no-unpublished-bin.js +11 -12
- package/lib/rules/no-unpublished-import.js +21 -22
- package/lib/rules/no-unpublished-require.js +21 -22
- package/lib/rules/no-unsupported-features/es-builtins.js +9 -10
- package/lib/rules/no-unsupported-features/es-syntax.js +40 -20
- package/lib/rules/no-unsupported-features/node-builtins.js +12 -14
- package/lib/rules/prefer-global/buffer.js +5 -7
- package/lib/rules/prefer-global/console.js +5 -7
- package/lib/rules/prefer-global/crypto.js +45 -0
- package/lib/rules/prefer-global/process.js +5 -7
- package/lib/rules/prefer-global/text-decoder.js +5 -7
- package/lib/rules/prefer-global/text-encoder.js +5 -7
- package/lib/rules/prefer-global/timers.js +52 -0
- package/lib/rules/prefer-global/url-search-params.js +5 -7
- package/lib/rules/prefer-global/url.js +5 -7
- package/lib/rules/prefer-node-protocol.js +10 -15
- package/lib/rules/prefer-promises/dns.js +9 -12
- package/lib/rules/prefer-promises/fs.js +14 -11
- package/lib/rules/process-exit-as-throw.js +22 -14
- package/lib/rules/rule-module.d.ts +17 -15
- package/lib/rules/shebang.js +22 -6
- package/lib/types-code-path-analysis/code-path-analyzer.d.ts +15 -15
- package/lib/types-code-path-analysis/code-path-segment.d.ts +32 -16
- package/lib/types-code-path-analysis/code-path-state.d.ts +166 -121
- package/lib/types-code-path-analysis/code-path.d.ts +32 -22
- package/lib/types-code-path-analysis/debug-helpers.d.ts +7 -7
- package/lib/types-code-path-analysis/fork-context.d.ts +33 -20
- package/lib/types-code-path-analysis/id-generator.d.ts +5 -5
- package/lib/unsupported-features/node-builtins-modules/assert.js +4 -5
- package/lib/unsupported-features/node-builtins-modules/async_hooks.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/buffer.js +8 -5
- package/lib/unsupported-features/node-builtins-modules/child_process.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/cluster.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/console.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/crypto.js +11 -4
- package/lib/unsupported-features/node-builtins-modules/dgram.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/diagnostics_channel.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/dns.js +2 -5
- package/lib/unsupported-features/node-builtins-modules/domain.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/events.js +6 -5
- package/lib/unsupported-features/node-builtins-modules/fs.js +15 -9
- package/lib/unsupported-features/node-builtins-modules/http.js +36 -17
- package/lib/unsupported-features/node-builtins-modules/http2.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/https.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/inspector.js +20 -8
- package/lib/unsupported-features/node-builtins-modules/module.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/net.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/os.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/path.js +8 -7
- package/lib/unsupported-features/node-builtins-modules/perf_hooks.js +4 -4
- package/lib/unsupported-features/node-builtins-modules/process.js +26 -9
- package/lib/unsupported-features/node-builtins-modules/punycode.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/querystring.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/readline.js +5 -8
- package/lib/unsupported-features/node-builtins-modules/repl.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/sea.js +3 -4
- package/lib/unsupported-features/node-builtins-modules/sqlite.js +3 -4
- package/lib/unsupported-features/node-builtins-modules/stream.js +35 -16
- package/lib/unsupported-features/node-builtins-modules/string_decoder.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/test.js +3 -4
- package/lib/unsupported-features/node-builtins-modules/timers.js +2 -5
- package/lib/unsupported-features/node-builtins-modules/tls.js +5 -5
- package/lib/unsupported-features/node-builtins-modules/trace_events.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/tty.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/url.js +11 -7
- package/lib/unsupported-features/node-builtins-modules/util.js +20 -9
- package/lib/unsupported-features/node-builtins-modules/v8.js +4 -5
- package/lib/unsupported-features/node-builtins-modules/vm.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/wasi.js +2 -4
- package/lib/unsupported-features/node-builtins-modules/worker_threads.js +15 -4
- package/lib/unsupported-features/node-builtins-modules/zlib.js +2 -4
- package/lib/unsupported-features/node-builtins.js +89 -51
- package/lib/unsupported-features/node-globals.js +21 -16
- package/lib/unsupported-features/node-import-meta.js +7 -7
- package/lib/unsupported-features/types.js +1 -3
- package/lib/util/cache.js +1 -2
- package/lib/util/check-existence.js +5 -6
- package/lib/util/check-extraneous.js +5 -6
- package/lib/util/check-prefer-global.js +5 -9
- package/lib/util/check-publish.js +8 -14
- package/lib/util/check-restricted.js +8 -9
- package/lib/util/check-unsupported-builtins.js +14 -19
- package/lib/util/enumerate-property-names.js +3 -4
- package/lib/util/exists.js +4 -5
- package/lib/util/extend-trackmap-with-node-prefix.js +3 -4
- package/lib/util/get-allow-modules.js +2 -3
- package/lib/util/get-configured-node-version.js +6 -7
- package/lib/util/get-convert-path.js +3 -4
- package/lib/util/get-full-type-name.js +9 -3
- package/lib/util/get-npmignore.js +10 -8
- package/lib/util/get-package-json.js +4 -7
- package/lib/util/get-parser-services.js +7 -4
- package/lib/util/get-resolve-paths.js +2 -3
- package/lib/util/get-resolver-config.js +2 -3
- package/lib/util/get-semver-range.js +2 -3
- package/lib/util/get-try-extensions.js +4 -5
- package/lib/util/get-tsconfig.js +4 -11
- package/lib/util/get-type-of-node.js +1 -3
- package/lib/util/get-typescript-extension-map.js +9 -5
- package/lib/util/has-parent-node.js +1 -5
- package/lib/util/import-target.js +8 -11
- package/lib/util/is-bin-file.js +2 -4
- package/lib/util/is-typescript.js +3 -6
- package/lib/util/iterate-process-get-builtin-module-references.js +2 -7
- package/lib/util/map-typescript-extension.js +4 -9
- package/lib/util/merge-visitors-in-place.js +1 -2
- package/lib/util/strip-import-path-params.js +1 -2
- package/lib/util/unprefix-node-colon.js +1 -3
- package/lib/util/visit-import.js +12 -13
- package/lib/util/visit-require.js +16 -20
- package/package.json +21 -9
- package/types/index.d.ts +3 -6
- package/lib/util/eslint-compat.js +0 -45
package/lib/eslint-utils.d.ts
CHANGED
|
@@ -1,81 +1,146 @@
|
|
|
1
|
-
declare module "eslint-plugin-es-x" {
|
|
2
|
-
export const rules: NonNullable<import('eslint').ESLint.Plugin["rules"]>;
|
|
3
|
-
}
|
|
1
|
+
declare module "eslint-plugin-es-x" {}
|
|
4
2
|
|
|
5
3
|
declare module "@eslint-community/eslint-utils" {
|
|
6
|
-
import * as estree from
|
|
7
|
-
import * as eslint from
|
|
4
|
+
import * as estree from "estree"
|
|
5
|
+
import * as eslint from "eslint"
|
|
8
6
|
|
|
9
|
-
type Node = estree.Node | estree.Expression
|
|
7
|
+
type Node = estree.Node | estree.Expression
|
|
10
8
|
|
|
11
|
-
export const READ: unique symbol
|
|
12
|
-
export const CALL: unique symbol
|
|
13
|
-
export const CONSTRUCT: unique symbol
|
|
14
|
-
export const ESM: unique symbol
|
|
9
|
+
export const READ: unique symbol
|
|
10
|
+
export const CALL: unique symbol
|
|
11
|
+
export const CONSTRUCT: unique symbol
|
|
12
|
+
export const ESM: unique symbol
|
|
15
13
|
export class ReferenceTracker {
|
|
16
|
-
constructor(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
constructor(
|
|
15
|
+
globalScope: eslint.Scope.Scope,
|
|
16
|
+
{
|
|
17
|
+
mode,
|
|
18
|
+
globalObjectNames,
|
|
19
|
+
}?:
|
|
20
|
+
| {
|
|
21
|
+
mode?: "legacy" | "strict" | undefined
|
|
22
|
+
globalObjectNames?: string[] | undefined
|
|
23
|
+
}
|
|
24
|
+
| undefined
|
|
25
|
+
)
|
|
26
|
+
variableStack: eslint.Scope.Variable[]
|
|
27
|
+
globalScope: eslint.Scope.Scope
|
|
28
|
+
mode: "legacy" | "strict"
|
|
29
|
+
globalObjectNames: string[]
|
|
30
|
+
iterateGlobalReferences<Info extends unknown>(
|
|
31
|
+
traceMap: TraceMap<Info>
|
|
32
|
+
): IterableIterator<Reference<Info>>
|
|
33
|
+
iterateCjsReferences<Info extends unknown>(
|
|
34
|
+
traceMap: TraceMap<Info>
|
|
35
|
+
): IterableIterator<Reference<Info>>
|
|
36
|
+
iterateEsmReferences<Info extends unknown>(
|
|
37
|
+
traceMap: TraceMap<Info>
|
|
38
|
+
): IterableIterator<Reference<Info>>
|
|
39
|
+
iteratePropertyReferences<Info extends unknown>(
|
|
40
|
+
node: estree.Expression,
|
|
41
|
+
traceMap: TraceMap<Info>
|
|
42
|
+
): IterableIterator<Reference<Info>>
|
|
28
43
|
}
|
|
29
44
|
export namespace ReferenceTracker {
|
|
30
|
-
export { READ }
|
|
31
|
-
export { CALL }
|
|
32
|
-
export { CONSTRUCT }
|
|
33
|
-
export { ESM }
|
|
45
|
+
export { READ }
|
|
46
|
+
export { CALL }
|
|
47
|
+
export { CONSTRUCT }
|
|
48
|
+
export { ESM }
|
|
34
49
|
}
|
|
35
|
-
type ReferenceType = typeof READ | typeof CALL | typeof CONSTRUCT
|
|
50
|
+
type ReferenceType = typeof READ | typeof CALL | typeof CONSTRUCT
|
|
36
51
|
type TraceMap<Info extends unknown> = {
|
|
37
|
-
[READ]?: Info
|
|
38
|
-
[CALL]?: Info
|
|
39
|
-
[CONSTRUCT]?: Info
|
|
40
|
-
[key: string]: TraceMap<Info> | undefined
|
|
52
|
+
[READ]?: Info
|
|
53
|
+
[CALL]?: Info
|
|
54
|
+
[CONSTRUCT]?: Info
|
|
55
|
+
[key: string]: TraceMap<Info> | undefined
|
|
41
56
|
}
|
|
42
|
-
type RichNode = eslint.Rule.Node | Node
|
|
57
|
+
type RichNode = eslint.Rule.Node | Node
|
|
43
58
|
type Reference<Info extends unknown> = {
|
|
44
|
-
node: RichNode
|
|
45
|
-
path: string[]
|
|
46
|
-
type: ReferenceType
|
|
47
|
-
info: Info
|
|
48
|
-
}
|
|
59
|
+
node: RichNode
|
|
60
|
+
path: string[]
|
|
61
|
+
type: ReferenceType
|
|
62
|
+
info: Info
|
|
63
|
+
}
|
|
49
64
|
|
|
50
|
-
export function findVariable(
|
|
65
|
+
export function findVariable(
|
|
66
|
+
initialScope: eslint.Scope.Scope,
|
|
67
|
+
nameOrNode: string | Node
|
|
68
|
+
): eslint.Scope.Variable | null
|
|
51
69
|
|
|
52
|
-
export function getFunctionHeadLocation(
|
|
53
|
-
|
|
54
|
-
|
|
70
|
+
export function getFunctionHeadLocation(
|
|
71
|
+
node: Extract<
|
|
72
|
+
eslint.Rule.Node,
|
|
73
|
+
{
|
|
74
|
+
type:
|
|
75
|
+
| "FunctionDeclaration"
|
|
76
|
+
| "FunctionExpression"
|
|
77
|
+
| "ArrowFunctionExpression"
|
|
78
|
+
}
|
|
79
|
+
>,
|
|
80
|
+
sourceCode: eslint.SourceCode
|
|
81
|
+
): eslint.AST.SourceLocation | null
|
|
55
82
|
|
|
56
|
-
export function getFunctionNameWithKind(
|
|
57
|
-
|
|
58
|
-
|
|
83
|
+
export function getFunctionNameWithKind(
|
|
84
|
+
node: Extract<
|
|
85
|
+
eslint.Rule.Node,
|
|
86
|
+
{
|
|
87
|
+
type:
|
|
88
|
+
| "FunctionDeclaration"
|
|
89
|
+
| "FunctionExpression"
|
|
90
|
+
| "ArrowFunctionExpression"
|
|
91
|
+
}
|
|
92
|
+
>,
|
|
93
|
+
sourceCode?: eslint.SourceCode | undefined
|
|
94
|
+
): string
|
|
59
95
|
|
|
60
|
-
export function getInnermostScope(
|
|
96
|
+
export function getInnermostScope(
|
|
97
|
+
initialScope: eslint.Scope.Scope,
|
|
98
|
+
node: Node
|
|
99
|
+
): eslint.Scope.Scope
|
|
61
100
|
|
|
62
|
-
export function getPropertyName(
|
|
63
|
-
|
|
64
|
-
|
|
101
|
+
export function getPropertyName(
|
|
102
|
+
node: Extract<
|
|
103
|
+
Node,
|
|
104
|
+
{
|
|
105
|
+
type:
|
|
106
|
+
| "MemberExpression"
|
|
107
|
+
| "Property"
|
|
108
|
+
| "MethodDefinition"
|
|
109
|
+
| "PropertyDefinition"
|
|
110
|
+
}
|
|
111
|
+
>,
|
|
112
|
+
initialScope?: eslint.Scope.Scope | undefined
|
|
113
|
+
): string | null
|
|
65
114
|
|
|
66
|
-
export function getStaticValue(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
115
|
+
export function getStaticValue(
|
|
116
|
+
node: Node,
|
|
117
|
+
initialScope?: eslint.Scope.Scope | null | undefined
|
|
118
|
+
):
|
|
119
|
+
| {
|
|
120
|
+
value: unknown
|
|
121
|
+
optional?: never
|
|
122
|
+
}
|
|
123
|
+
| {
|
|
124
|
+
value: undefined
|
|
125
|
+
optional?: true
|
|
126
|
+
}
|
|
127
|
+
| null
|
|
73
128
|
|
|
74
|
-
export function getStringIfConstant(
|
|
129
|
+
export function getStringIfConstant(
|
|
130
|
+
node: Node,
|
|
131
|
+
initialScope?: eslint.Scope.Scope | null | undefined
|
|
132
|
+
): string | null
|
|
75
133
|
|
|
76
|
-
export function hasSideEffect(
|
|
134
|
+
export function hasSideEffect(
|
|
135
|
+
node: eslint.Rule.Node,
|
|
136
|
+
sourceCode: eslint.SourceCode,
|
|
137
|
+
{
|
|
138
|
+
considerGetters,
|
|
139
|
+
considerImplicitTypeConversion,
|
|
140
|
+
}?: VisitOptions | undefined
|
|
141
|
+
): boolean
|
|
77
142
|
type VisitOptions = {
|
|
78
|
-
considerGetters?: boolean | undefined
|
|
79
|
-
considerImplicitTypeConversion?: boolean | undefined
|
|
80
|
-
}
|
|
143
|
+
considerGetters?: boolean | undefined
|
|
144
|
+
considerImplicitTypeConversion?: boolean | undefined
|
|
145
|
+
}
|
|
81
146
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const allRulesConfig = require("./configs/all")
|
|
8
|
-
const allRules = require("./all-rules")
|
|
1
|
+
import pkg from "../package.json" with { type: "json" }
|
|
2
|
+
import * as esmConfig from "./configs/recommended-module.js"
|
|
3
|
+
import * as cjsConfig from "./configs/recommended-script.js"
|
|
4
|
+
import * as recommendedConfig from "./configs/recommended.js"
|
|
5
|
+
import { flat as allRulesFlatConfig } from "./configs/all.js"
|
|
6
|
+
import allRules from "./all-rules.js"
|
|
9
7
|
|
|
10
8
|
/** @import { ESLint, Linter } from 'eslint' */
|
|
11
9
|
|
|
@@ -43,8 +41,8 @@ const configs = {
|
|
|
43
41
|
{ files: ["**/*.mjs"], plugins: { n: base }, ...esmConfig.flat },
|
|
44
42
|
{ files: ["**/*.cjs"], plugins: { n: base }, ...cjsConfig.flat },
|
|
45
43
|
],
|
|
46
|
-
"flat/all": { plugins: { n: base }, ...
|
|
44
|
+
"flat/all": { plugins: { n: base }, ...allRulesFlatConfig },
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
/** @type {ESLint.Plugin & { configs: Configs }} */
|
|
50
|
-
|
|
48
|
+
export default Object.assign(base, { configs })
|
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
* @author Jamund Ferguson
|
|
3
3
|
* See LICENSE file in root directory for full license.
|
|
4
4
|
*/
|
|
5
|
-
"use strict"
|
|
6
|
-
const { getSourceCode } = require("../util/eslint-compat")
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* @typedef {[string[]?]} RuleOptions
|
|
10
8
|
*/
|
|
11
|
-
/** @type {import('./rule-module').RuleModule<{RuleOptions: RuleOptions}>} */
|
|
12
|
-
|
|
9
|
+
/** @type {import('./rule-module.js').RuleModule<{RuleOptions: RuleOptions}>} */
|
|
10
|
+
export default {
|
|
13
11
|
meta: {
|
|
14
12
|
type: "suggestion",
|
|
15
13
|
docs: {
|
|
@@ -23,15 +21,14 @@ module.exports = {
|
|
|
23
21
|
items: { type: "string" },
|
|
24
22
|
},
|
|
25
23
|
],
|
|
26
|
-
fixable:
|
|
24
|
+
fixable: void 0,
|
|
27
25
|
messages: {
|
|
28
26
|
missingReturn: "Expected return with your callback function.",
|
|
29
27
|
},
|
|
30
28
|
},
|
|
31
|
-
|
|
32
29
|
create(context) {
|
|
33
30
|
const callbacks = context.options[0] || ["callback", "cb", "next"]
|
|
34
|
-
const sourceCode =
|
|
31
|
+
const sourceCode = context.sourceCode
|
|
35
32
|
|
|
36
33
|
/**
|
|
37
34
|
* Find the closest parent matching a list of types.
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
* @author Toru Nagashima
|
|
3
3
|
* See LICENSE file in root directory for full license.
|
|
4
4
|
*/
|
|
5
|
-
"use strict"
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
const { getSourceCode, getScope } = require("../util/eslint-compat")
|
|
6
|
+
import { hasParentNode } from "../util/has-parent-node.js"
|
|
9
7
|
|
|
10
8
|
/*istanbul ignore next */
|
|
11
9
|
/**
|
|
@@ -128,7 +126,10 @@ function getModuleExportsNodes(scope) {
|
|
|
128
126
|
const nodes = []
|
|
129
127
|
|
|
130
128
|
for (const reference of variable.references) {
|
|
131
|
-
if (
|
|
129
|
+
if (
|
|
130
|
+
reference.identifier.type !== "Identifier" ||
|
|
131
|
+
hasParentNode(reference.identifier) === false
|
|
132
|
+
) {
|
|
132
133
|
continue
|
|
133
134
|
}
|
|
134
135
|
const node = reference.identifier.parent
|
|
@@ -154,7 +155,16 @@ function getExportsNodes(scope) {
|
|
|
154
155
|
return []
|
|
155
156
|
}
|
|
156
157
|
|
|
157
|
-
|
|
158
|
+
/** @type {import('estree').Identifier[]} */
|
|
159
|
+
const nodes = []
|
|
160
|
+
|
|
161
|
+
for (const reference of variable.references) {
|
|
162
|
+
if (reference.identifier.type === "Identifier") {
|
|
163
|
+
nodes.push(reference.identifier)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return nodes
|
|
158
168
|
}
|
|
159
169
|
|
|
160
170
|
/**
|
|
@@ -273,8 +283,8 @@ function fixModuleExports(node, sourceCode, fixer) {
|
|
|
273
283
|
* {allowBatchAssign?: boolean}?
|
|
274
284
|
* ]} RuleOptions
|
|
275
285
|
*/
|
|
276
|
-
/** @type {import('./rule-module').RuleModule<{RuleOptions: RuleOptions}>} */
|
|
277
|
-
|
|
286
|
+
/** @type {import('./rule-module.js').RuleModule<{RuleOptions: RuleOptions}>} */
|
|
287
|
+
export default {
|
|
278
288
|
meta: {
|
|
279
289
|
docs: {
|
|
280
290
|
description: "enforce either `module.exports` or `exports`",
|
|
@@ -303,13 +313,12 @@ module.exports = {
|
|
|
303
313
|
"Unexpected assignment to 'exports'. Don't modify 'exports' itself.",
|
|
304
314
|
},
|
|
305
315
|
},
|
|
306
|
-
|
|
307
316
|
create(context) {
|
|
308
317
|
const mode = context.options[0] || "module.exports"
|
|
309
318
|
const batchAssignAllowed = Boolean(
|
|
310
319
|
context.options[1] != null && context.options[1].allowBatchAssign
|
|
311
320
|
)
|
|
312
|
-
const sourceCode =
|
|
321
|
+
const sourceCode = context.sourceCode
|
|
313
322
|
|
|
314
323
|
/**
|
|
315
324
|
* Gets the location info of reports.
|
|
@@ -434,7 +443,9 @@ module.exports = {
|
|
|
434
443
|
|
|
435
444
|
return {
|
|
436
445
|
"Program:exit"() {
|
|
437
|
-
const scope = getScope(
|
|
446
|
+
const scope = context.sourceCode.getScope(
|
|
447
|
+
context.sourceCode.ast
|
|
448
|
+
)
|
|
438
449
|
|
|
439
450
|
switch (mode) {
|
|
440
451
|
case "module.exports":
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
* @author Toru Nagashima
|
|
3
3
|
* See LICENSE file in root directory for full license.
|
|
4
4
|
*/
|
|
5
|
-
"use strict"
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
import path from "node:path"
|
|
7
|
+
import fs from "node:fs"
|
|
8
|
+
import { convertTsExtensionToJs } from "../util/map-typescript-extension.js"
|
|
9
|
+
import { getTryExtensions } from "../util/get-try-extensions.js"
|
|
10
|
+
import { visitImport } from "../util/visit-import.js"
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* Get all file extensions of the files which have the same basename.
|
|
@@ -67,8 +66,8 @@ function getIndexExtension(directoryPath, tryExtensions) {
|
|
|
67
66
|
* {[ext in string]?: "always" | "never"}?
|
|
68
67
|
* ]} RuleOptions
|
|
69
68
|
*/
|
|
70
|
-
/** @type {import('./rule-module').RuleModule<{RuleOptions: RuleOptions}>} */
|
|
71
|
-
|
|
69
|
+
/** @type {import('./rule-module.js').RuleModule<{RuleOptions: RuleOptions}>} */
|
|
70
|
+
export default {
|
|
72
71
|
meta: {
|
|
73
72
|
docs: {
|
|
74
73
|
description:
|
|
@@ -96,7 +95,7 @@ module.exports = {
|
|
|
96
95
|
type: "suggestion",
|
|
97
96
|
},
|
|
98
97
|
create(context) {
|
|
99
|
-
if (
|
|
98
|
+
if (context.filename.startsWith("<")) {
|
|
100
99
|
return {}
|
|
101
100
|
}
|
|
102
101
|
const defaultStyle = context.options[0] || "always"
|
|
@@ -104,7 +103,7 @@ module.exports = {
|
|
|
104
103
|
const tryExtensions = getTryExtensions(context, 1)
|
|
105
104
|
|
|
106
105
|
/**
|
|
107
|
-
* @param {import("../util/import-target.js")} target
|
|
106
|
+
* @param {import("../util/import-target.js").ImportTarget} target
|
|
108
107
|
* @returns {void}
|
|
109
108
|
*/
|
|
110
109
|
function verify({ filePath, name, node, moduleType }) {
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
* @author Jamund Ferguson
|
|
3
3
|
* See LICENSE file in root directory for full license.
|
|
4
4
|
*/
|
|
5
|
-
"use strict"
|
|
6
|
-
|
|
7
|
-
const { getScope, getAncestors } = require("../util/eslint-compat")
|
|
8
5
|
|
|
9
6
|
const ACCEPTABLE_PARENTS = [
|
|
10
7
|
"AssignmentExpression",
|
|
@@ -43,8 +40,8 @@ function isShadowed(scope, node) {
|
|
|
43
40
|
return Boolean(reference?.resolved?.defs?.length)
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
/** @type {import('./rule-module').RuleModule} */
|
|
47
|
-
|
|
43
|
+
/** @type {import('./rule-module.js').RuleModule} */
|
|
44
|
+
export default {
|
|
48
45
|
meta: {
|
|
49
46
|
type: "suggestion",
|
|
50
47
|
docs: {
|
|
@@ -53,26 +50,28 @@ module.exports = {
|
|
|
53
50
|
recommended: false,
|
|
54
51
|
url: "https://github.com/eslint-community/eslint-plugin-n/blob/HEAD/docs/rules/global-require.md",
|
|
55
52
|
},
|
|
56
|
-
fixable:
|
|
53
|
+
fixable: void 0,
|
|
57
54
|
schema: [],
|
|
58
55
|
messages: {
|
|
59
56
|
unexpected: "Unexpected require().",
|
|
60
57
|
},
|
|
61
58
|
},
|
|
62
|
-
|
|
63
59
|
create(context) {
|
|
64
60
|
return {
|
|
65
61
|
CallExpression(node) {
|
|
66
|
-
const currentScope = getScope(
|
|
62
|
+
const currentScope = context.sourceCode.getScope(node)
|
|
67
63
|
|
|
68
64
|
if (
|
|
69
65
|
node.callee.type === "Identifier" &&
|
|
70
66
|
node.callee.name === "require" &&
|
|
71
67
|
!isShadowed(currentScope, node.callee)
|
|
72
68
|
) {
|
|
73
|
-
const isGoodRequire =
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
const isGoodRequire = context.sourceCode
|
|
70
|
+
.getAncestors(node)
|
|
71
|
+
.every(
|
|
72
|
+
parent =>
|
|
73
|
+
ACCEPTABLE_PARENTS.indexOf(parent.type) > -1
|
|
74
|
+
)
|
|
76
75
|
|
|
77
76
|
if (!isGoodRequire) {
|
|
78
77
|
context.report({ node, messageId: "unexpected" })
|
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
* @author Jamund Ferguson
|
|
3
3
|
* See LICENSE file in root directory for full license.
|
|
4
4
|
*/
|
|
5
|
-
"use strict"
|
|
6
|
-
|
|
7
|
-
const { getScope } = require("../util/eslint-compat")
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* @typedef {[string?]} RuleOptions
|
|
11
8
|
*/
|
|
12
|
-
/** @type {import('./rule-module').RuleModule<{RuleOptions: RuleOptions}>} */
|
|
13
|
-
|
|
9
|
+
/** @type {import('./rule-module.js').RuleModule<{RuleOptions: RuleOptions}>} */
|
|
10
|
+
export default {
|
|
14
11
|
meta: {
|
|
15
12
|
type: "suggestion",
|
|
16
13
|
docs: {
|
|
@@ -18,7 +15,7 @@ module.exports = {
|
|
|
18
15
|
recommended: false,
|
|
19
16
|
url: "https://github.com/eslint-community/eslint-plugin-n/blob/HEAD/docs/rules/handle-callback-err.md",
|
|
20
17
|
},
|
|
21
|
-
fixable:
|
|
18
|
+
fixable: void 0,
|
|
22
19
|
schema: [
|
|
23
20
|
{
|
|
24
21
|
type: "string",
|
|
@@ -28,7 +25,6 @@ module.exports = {
|
|
|
28
25
|
expected: "Expected error to be handled.",
|
|
29
26
|
},
|
|
30
27
|
},
|
|
31
|
-
|
|
32
28
|
create(context) {
|
|
33
29
|
const errorArgument = context.options[0] || "err"
|
|
34
30
|
|
|
@@ -75,7 +71,7 @@ module.exports = {
|
|
|
75
71
|
* @returns {void}
|
|
76
72
|
*/
|
|
77
73
|
function checkForError(node) {
|
|
78
|
-
const scope = getScope(
|
|
74
|
+
const scope = context.sourceCode.getScope(node)
|
|
79
75
|
const parameters = getParameters(scope)
|
|
80
76
|
const firstParameter = parameters[0]
|
|
81
77
|
|
package/lib/rules/hashbang.js
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
* @author Toru Nagashima
|
|
3
3
|
* See LICENSE file in root directory for full license.
|
|
4
4
|
*/
|
|
5
|
-
"use strict"
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import path from "node:path"
|
|
7
|
+
import matcherModule from "ignore"
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
import { getConvertPath, schema } from "../util/get-convert-path.js"
|
|
10
|
+
import { getPackageJson } from "../util/get-package-json.js"
|
|
11
|
+
import { getNpmignore } from "../util/get-npmignore.js"
|
|
12
|
+
import { isBinFile } from "../util/is-bin-file.js"
|
|
13
|
+
|
|
14
|
+
/** @type {typeof import('ignore').default} */
|
|
15
|
+
const matcher = /** @type {any} */ (matcherModule)
|
|
15
16
|
|
|
16
17
|
const ENV_SHEBANG = "#!/usr/bin/env"
|
|
17
18
|
const NODE_SHEBANG = `${ENV_SHEBANG} {{executableName}}\n`
|
|
@@ -51,7 +52,7 @@ function isNodeShebang(shebang, executableName) {
|
|
|
51
52
|
* @returns {string}
|
|
52
53
|
*/
|
|
53
54
|
function getExpectedExecutableName(context) {
|
|
54
|
-
const extension = path.extname(context.filename
|
|
55
|
+
const extension = path.extname(context.filename)
|
|
55
56
|
const { executableMap = {} } =
|
|
56
57
|
/** @type {[{ executableMap: Record<string, string> }]} */
|
|
57
58
|
(context.options)?.[0] ?? {}
|
|
@@ -81,15 +82,15 @@ function getShebangInfo(sourceCode) {
|
|
|
81
82
|
/**
|
|
82
83
|
* @typedef {[
|
|
83
84
|
* {
|
|
84
|
-
* convertPath?: import('../util/get-convert-path').ConvertPath;
|
|
85
|
+
* convertPath?: import('../util/get-convert-path.js').ConvertPath;
|
|
85
86
|
* ignoreUnpublished?: boolean;
|
|
86
87
|
* additionalExecutables?: string[];
|
|
87
88
|
* executableMap?: Record<string, string>;
|
|
88
89
|
* }?
|
|
89
90
|
* ]} RuleOptions
|
|
90
91
|
*/
|
|
91
|
-
/** @type {import('./rule-module').RuleModule<{RuleOptions: RuleOptions}>} */
|
|
92
|
-
|
|
92
|
+
/** @type {import('./rule-module.js').RuleModule<{RuleOptions: RuleOptions}>} */
|
|
93
|
+
export default {
|
|
93
94
|
meta: {
|
|
94
95
|
docs: {
|
|
95
96
|
description: "require correct usage of hashbang",
|
|
@@ -102,7 +103,7 @@ module.exports = {
|
|
|
102
103
|
{
|
|
103
104
|
type: "object",
|
|
104
105
|
properties: {
|
|
105
|
-
convertPath:
|
|
106
|
+
convertPath: schema,
|
|
106
107
|
ignoreUnpublished: { type: "boolean" },
|
|
107
108
|
additionalExecutables: {
|
|
108
109
|
type: "array",
|
|
@@ -131,8 +132,8 @@ module.exports = {
|
|
|
131
132
|
},
|
|
132
133
|
},
|
|
133
134
|
create(context) {
|
|
134
|
-
const sourceCode =
|
|
135
|
-
const filePath = context.filename
|
|
135
|
+
const sourceCode = context.sourceCode
|
|
136
|
+
const filePath = context.filename
|
|
136
137
|
if (filePath === "<input>") {
|
|
137
138
|
return {}
|
|
138
139
|
}
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
* @author Jamund Ferguson
|
|
3
3
|
* See LICENSE file in root directory for full license.
|
|
4
4
|
*/
|
|
5
|
-
"use strict"
|
|
6
5
|
|
|
7
6
|
const callbackNames = ["callback", "cb"]
|
|
8
7
|
|
|
9
|
-
/** @type {import('./rule-module').RuleModule} */
|
|
10
|
-
|
|
8
|
+
/** @type {import('./rule-module.js').RuleModule} */
|
|
9
|
+
export default {
|
|
11
10
|
meta: {
|
|
12
11
|
docs: {
|
|
13
12
|
description:
|
|
@@ -16,14 +15,13 @@ module.exports = {
|
|
|
16
15
|
url: "https://github.com/eslint-community/eslint-plugin-n/blob/HEAD/docs/rules/no-callback-literal.md",
|
|
17
16
|
},
|
|
18
17
|
type: "problem",
|
|
19
|
-
fixable:
|
|
18
|
+
fixable: void 0,
|
|
20
19
|
schema: [],
|
|
21
20
|
messages: {
|
|
22
21
|
unexpectedLiteral:
|
|
23
22
|
"Unexpected literal in error position of callback.",
|
|
24
23
|
},
|
|
25
24
|
},
|
|
26
|
-
|
|
27
25
|
create(context) {
|
|
28
26
|
return {
|
|
29
27
|
CallExpression(node) {
|