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.
Files changed (147) hide show
  1. package/README.md +29 -61
  2. package/configs/recommended-module.js +2 -3
  3. package/configs/recommended-script.js +2 -2
  4. package/lib/all-rules.js +90 -47
  5. package/lib/configs/_commons.js +2 -5
  6. package/lib/configs/all.js +3 -4
  7. package/lib/configs/recommended-module.js +6 -8
  8. package/lib/configs/recommended-script.js +6 -8
  9. package/lib/configs/recommended.js +5 -7
  10. package/lib/eslint-utils.d.ts +125 -60
  11. package/lib/index.js +8 -10
  12. package/lib/rules/callback-return.js +4 -7
  13. package/lib/rules/exports-style.js +21 -10
  14. package/lib/rules/file-extension-in-import.js +9 -10
  15. package/lib/rules/global-require.js +10 -11
  16. package/lib/rules/handle-callback-err.js +4 -8
  17. package/lib/rules/hashbang.js +16 -15
  18. package/lib/rules/no-callback-literal.js +3 -5
  19. package/lib/rules/no-deprecated-api.js +18 -17
  20. package/lib/rules/no-exports-assign.js +7 -7
  21. package/lib/rules/no-extraneous-import.js +14 -15
  22. package/lib/rules/no-extraneous-require.js +16 -17
  23. package/lib/rules/no-hide-core-modules.js +15 -12
  24. package/lib/rules/no-missing-import.js +24 -25
  25. package/lib/rules/no-missing-require.js +18 -19
  26. package/lib/rules/no-mixed-requires.js +4 -6
  27. package/lib/rules/no-new-require.js +3 -5
  28. package/lib/rules/no-path-concat.js +59 -20
  29. package/lib/rules/no-process-env.js +3 -5
  30. package/lib/rules/no-process-exit.js +3 -5
  31. package/lib/rules/no-restricted-import.js +5 -7
  32. package/lib/rules/no-restricted-require.js +5 -7
  33. package/lib/rules/no-sync.js +36 -22
  34. package/lib/rules/no-top-level-await.js +17 -19
  35. package/lib/rules/no-unpublished-bin.js +11 -12
  36. package/lib/rules/no-unpublished-import.js +21 -22
  37. package/lib/rules/no-unpublished-require.js +21 -22
  38. package/lib/rules/no-unsupported-features/es-builtins.js +9 -10
  39. package/lib/rules/no-unsupported-features/es-syntax.js +40 -20
  40. package/lib/rules/no-unsupported-features/node-builtins.js +12 -14
  41. package/lib/rules/prefer-global/buffer.js +5 -7
  42. package/lib/rules/prefer-global/console.js +5 -7
  43. package/lib/rules/prefer-global/crypto.js +45 -0
  44. package/lib/rules/prefer-global/process.js +5 -7
  45. package/lib/rules/prefer-global/text-decoder.js +5 -7
  46. package/lib/rules/prefer-global/text-encoder.js +5 -7
  47. package/lib/rules/prefer-global/timers.js +52 -0
  48. package/lib/rules/prefer-global/url-search-params.js +5 -7
  49. package/lib/rules/prefer-global/url.js +5 -7
  50. package/lib/rules/prefer-node-protocol.js +10 -15
  51. package/lib/rules/prefer-promises/dns.js +9 -12
  52. package/lib/rules/prefer-promises/fs.js +14 -11
  53. package/lib/rules/process-exit-as-throw.js +22 -14
  54. package/lib/rules/rule-module.d.ts +17 -15
  55. package/lib/rules/shebang.js +22 -6
  56. package/lib/types-code-path-analysis/code-path-analyzer.d.ts +15 -15
  57. package/lib/types-code-path-analysis/code-path-segment.d.ts +32 -16
  58. package/lib/types-code-path-analysis/code-path-state.d.ts +166 -121
  59. package/lib/types-code-path-analysis/code-path.d.ts +32 -22
  60. package/lib/types-code-path-analysis/debug-helpers.d.ts +7 -7
  61. package/lib/types-code-path-analysis/fork-context.d.ts +33 -20
  62. package/lib/types-code-path-analysis/id-generator.d.ts +5 -5
  63. package/lib/unsupported-features/node-builtins-modules/assert.js +4 -5
  64. package/lib/unsupported-features/node-builtins-modules/async_hooks.js +2 -4
  65. package/lib/unsupported-features/node-builtins-modules/buffer.js +8 -5
  66. package/lib/unsupported-features/node-builtins-modules/child_process.js +2 -4
  67. package/lib/unsupported-features/node-builtins-modules/cluster.js +2 -4
  68. package/lib/unsupported-features/node-builtins-modules/console.js +2 -4
  69. package/lib/unsupported-features/node-builtins-modules/crypto.js +11 -4
  70. package/lib/unsupported-features/node-builtins-modules/dgram.js +2 -4
  71. package/lib/unsupported-features/node-builtins-modules/diagnostics_channel.js +2 -4
  72. package/lib/unsupported-features/node-builtins-modules/dns.js +2 -5
  73. package/lib/unsupported-features/node-builtins-modules/domain.js +2 -4
  74. package/lib/unsupported-features/node-builtins-modules/events.js +6 -5
  75. package/lib/unsupported-features/node-builtins-modules/fs.js +15 -9
  76. package/lib/unsupported-features/node-builtins-modules/http.js +36 -17
  77. package/lib/unsupported-features/node-builtins-modules/http2.js +2 -4
  78. package/lib/unsupported-features/node-builtins-modules/https.js +2 -4
  79. package/lib/unsupported-features/node-builtins-modules/inspector.js +20 -8
  80. package/lib/unsupported-features/node-builtins-modules/module.js +2 -4
  81. package/lib/unsupported-features/node-builtins-modules/net.js +2 -4
  82. package/lib/unsupported-features/node-builtins-modules/os.js +2 -4
  83. package/lib/unsupported-features/node-builtins-modules/path.js +8 -7
  84. package/lib/unsupported-features/node-builtins-modules/perf_hooks.js +4 -4
  85. package/lib/unsupported-features/node-builtins-modules/process.js +26 -9
  86. package/lib/unsupported-features/node-builtins-modules/punycode.js +2 -4
  87. package/lib/unsupported-features/node-builtins-modules/querystring.js +2 -4
  88. package/lib/unsupported-features/node-builtins-modules/readline.js +5 -8
  89. package/lib/unsupported-features/node-builtins-modules/repl.js +2 -4
  90. package/lib/unsupported-features/node-builtins-modules/sea.js +3 -4
  91. package/lib/unsupported-features/node-builtins-modules/sqlite.js +3 -4
  92. package/lib/unsupported-features/node-builtins-modules/stream.js +35 -16
  93. package/lib/unsupported-features/node-builtins-modules/string_decoder.js +2 -4
  94. package/lib/unsupported-features/node-builtins-modules/test.js +3 -4
  95. package/lib/unsupported-features/node-builtins-modules/timers.js +2 -5
  96. package/lib/unsupported-features/node-builtins-modules/tls.js +5 -5
  97. package/lib/unsupported-features/node-builtins-modules/trace_events.js +2 -4
  98. package/lib/unsupported-features/node-builtins-modules/tty.js +2 -4
  99. package/lib/unsupported-features/node-builtins-modules/url.js +11 -7
  100. package/lib/unsupported-features/node-builtins-modules/util.js +20 -9
  101. package/lib/unsupported-features/node-builtins-modules/v8.js +4 -5
  102. package/lib/unsupported-features/node-builtins-modules/vm.js +2 -4
  103. package/lib/unsupported-features/node-builtins-modules/wasi.js +2 -4
  104. package/lib/unsupported-features/node-builtins-modules/worker_threads.js +15 -4
  105. package/lib/unsupported-features/node-builtins-modules/zlib.js +2 -4
  106. package/lib/unsupported-features/node-builtins.js +89 -51
  107. package/lib/unsupported-features/node-globals.js +21 -16
  108. package/lib/unsupported-features/node-import-meta.js +7 -7
  109. package/lib/unsupported-features/types.js +1 -3
  110. package/lib/util/cache.js +1 -2
  111. package/lib/util/check-existence.js +5 -6
  112. package/lib/util/check-extraneous.js +5 -6
  113. package/lib/util/check-prefer-global.js +5 -9
  114. package/lib/util/check-publish.js +8 -14
  115. package/lib/util/check-restricted.js +8 -9
  116. package/lib/util/check-unsupported-builtins.js +14 -19
  117. package/lib/util/enumerate-property-names.js +3 -4
  118. package/lib/util/exists.js +4 -5
  119. package/lib/util/extend-trackmap-with-node-prefix.js +3 -4
  120. package/lib/util/get-allow-modules.js +2 -3
  121. package/lib/util/get-configured-node-version.js +6 -7
  122. package/lib/util/get-convert-path.js +3 -4
  123. package/lib/util/get-full-type-name.js +9 -3
  124. package/lib/util/get-npmignore.js +10 -8
  125. package/lib/util/get-package-json.js +4 -7
  126. package/lib/util/get-parser-services.js +7 -4
  127. package/lib/util/get-resolve-paths.js +2 -3
  128. package/lib/util/get-resolver-config.js +2 -3
  129. package/lib/util/get-semver-range.js +2 -3
  130. package/lib/util/get-try-extensions.js +4 -5
  131. package/lib/util/get-tsconfig.js +4 -11
  132. package/lib/util/get-type-of-node.js +1 -3
  133. package/lib/util/get-typescript-extension-map.js +9 -5
  134. package/lib/util/has-parent-node.js +1 -5
  135. package/lib/util/import-target.js +8 -11
  136. package/lib/util/is-bin-file.js +2 -4
  137. package/lib/util/is-typescript.js +3 -6
  138. package/lib/util/iterate-process-get-builtin-module-references.js +2 -7
  139. package/lib/util/map-typescript-extension.js +4 -9
  140. package/lib/util/merge-visitors-in-place.js +1 -2
  141. package/lib/util/strip-import-path-params.js +1 -2
  142. package/lib/util/unprefix-node-colon.js +1 -3
  143. package/lib/util/visit-import.js +12 -13
  144. package/lib/util/visit-require.js +16 -20
  145. package/package.json +21 -9
  146. package/types/index.d.ts +3 -6
  147. package/lib/util/eslint-compat.js +0 -45
@@ -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 'estree';
7
- import * as eslint from 'eslint';
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(globalScope: eslint.Scope.Scope, { mode, globalObjectNames, }?: {
17
- mode?: "legacy" | "strict" | undefined;
18
- globalObjectNames?: string[] | undefined;
19
- } | undefined);
20
- variableStack: eslint.Scope.Variable[];
21
- globalScope: eslint.Scope.Scope;
22
- mode: "legacy" | "strict";
23
- globalObjectNames: string[];
24
- iterateGlobalReferences<Info extends unknown>(traceMap: TraceMap<Info>): IterableIterator<Reference<Info>>;
25
- iterateCjsReferences<Info extends unknown>(traceMap: TraceMap<Info>): IterableIterator<Reference<Info>>;
26
- iterateEsmReferences<Info extends unknown>(traceMap: TraceMap<Info>): IterableIterator<Reference<Info>>;
27
- iteratePropertyReferences<Info extends unknown>(node: estree.Expression, traceMap: TraceMap<Info>): IterableIterator<Reference<Info>>;
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(initialScope: eslint.Scope.Scope, nameOrNode: string | Node): eslint.Scope.Variable | null;
65
+ export function findVariable(
66
+ initialScope: eslint.Scope.Scope,
67
+ nameOrNode: string | Node
68
+ ): eslint.Scope.Variable | null
51
69
 
52
- export function getFunctionHeadLocation(node: Extract<eslint.Rule.Node, {
53
- type: 'FunctionDeclaration' | 'FunctionExpression' | 'ArrowFunctionExpression';
54
- }>, sourceCode: eslint.SourceCode): eslint.AST.SourceLocation | null;
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(node: Extract<eslint.Rule.Node, {
57
- type: 'FunctionDeclaration' | 'FunctionExpression' | 'ArrowFunctionExpression';
58
- }>, sourceCode?: eslint.SourceCode | undefined): string;
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(initialScope: eslint.Scope.Scope, node: Node): eslint.Scope.Scope;
96
+ export function getInnermostScope(
97
+ initialScope: eslint.Scope.Scope,
98
+ node: Node
99
+ ): eslint.Scope.Scope
61
100
 
62
- export function getPropertyName(node: Extract<Node, {
63
- type: 'MemberExpression' | 'Property' | 'MethodDefinition' | 'PropertyDefinition';
64
- }>, initialScope?: eslint.Scope.Scope | undefined): string | null;
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(node: Node, initialScope?: eslint.Scope.Scope | null | undefined): {
67
- value: unknown;
68
- optional?: never;
69
- } | {
70
- value: undefined;
71
- optional?: true;
72
- } | null;
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(node: Node, initialScope?: eslint.Scope.Scope | null | undefined): string | null;
129
+ export function getStringIfConstant(
130
+ node: Node,
131
+ initialScope?: eslint.Scope.Scope | null | undefined
132
+ ): string | null
75
133
 
76
- export function hasSideEffect(node: eslint.Rule.Node, sourceCode: eslint.SourceCode, { considerGetters, considerImplicitTypeConversion }?: VisitOptions | undefined): boolean;
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
- "use strict"
2
-
3
- const pkg = require("../package.json")
4
- const esmConfig = require("./configs/recommended-module")
5
- const cjsConfig = require("./configs/recommended-script")
6
- const recommendedConfig = require("./configs/recommended")
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 }, ...allRulesConfig.flat },
44
+ "flat/all": { plugins: { n: base }, ...allRulesFlatConfig },
47
45
  }
48
46
 
49
47
  /** @type {ESLint.Plugin & { configs: Configs }} */
50
- module.exports = Object.assign(base, { configs })
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
- module.exports = {
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: null,
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 = getSourceCode(context)
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
- const { hasParentNode } = require("../util/has-parent-node.js")
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 (hasParentNode(reference.identifier) === false) {
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
- return variable.references.map(reference => reference.identifier)
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
- module.exports = {
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 = getSourceCode(context)
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(context)
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
- const path = require("path")
8
- const fs = require("fs")
9
- const { convertTsExtensionToJs } = require("../util/map-typescript-extension")
10
- const getTryExtensions = require("../util/get-try-extensions")
11
- const visitImport = require("../util/visit-import")
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
- module.exports = {
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 ((context.filename ?? context.getFilename()).startsWith("<")) {
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
- module.exports = {
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: null,
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(context, node)
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 = getAncestors(context, node).every(
74
- parent => ACCEPTABLE_PARENTS.indexOf(parent.type) > -1
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
- module.exports = {
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: null,
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(context, node)
74
+ const scope = context.sourceCode.getScope(node)
79
75
  const parameters = getParameters(scope)
80
76
  const firstParameter = parameters[0]
81
77
 
@@ -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
- const path = require("path")
8
- const matcher = require("ignore").default
6
+ import path from "node:path"
7
+ import matcherModule from "ignore"
9
8
 
10
- const getConvertPath = require("../util/get-convert-path")
11
- const { getPackageJson } = require("../util/get-package-json")
12
- const getNpmignore = require("../util/get-npmignore")
13
- const { isBinFile } = require("../util/is-bin-file")
14
- const { getSourceCode } = require("../util/eslint-compat")
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 ?? context.getFilename())
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
- module.exports = {
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: getConvertPath.schema,
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 = getSourceCode(context)
135
- const filePath = context.filename ?? context.getFilename()
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
- module.exports = {
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: null,
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) {