@typescript-eslint/eslint-plugin 8.21.1-alpha.10 → 8.21.1-alpha.11

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.
@@ -107,8 +107,8 @@ The rule will **_not_** report any errors in files _that contain decorators_ whe
107
107
 
108
108
  > See [Blog > Changes to consistent-type-imports when used with legacy decorators and decorator metadata](/blog/changes-to-consistent-type-imports-with-decorators) for more details.
109
109
 
110
- If you are using [type-aware linting](https://typescript-eslint.io/linting/typed-linting) then we will automatically infer your setup from your tsconfig and you should not need to configure anything.
111
- Otherwise you can explicitly tell our tooling to analyze your code as if the compiler option was turned on by setting both [`parserOptions.emitDecoratorMetadata = true`](https://typescript-eslint.io/packages/parser/#emitdecoratormetadata) and [`parserOptions.experimentalDecorators = true`](https://typescript-eslint.io/packages/parser/#experimentaldecorators).
110
+ If you are using [type-aware linting](/getting-started/typed-linting) then we will automatically infer your setup from your tsconfig and you should not need to configure anything.
111
+ Otherwise you can explicitly tell our tooling to analyze your code as if the compiler option was turned on by setting both [`parserOptions.emitDecoratorMetadata = true`](/packages/parser/#emitdecoratormetadata) and [`parserOptions.experimentalDecorators = true`](/packages/parser/#experimentaldecorators).
112
112
 
113
113
  ## Comparison with `importsNotUsedAsValues` / `verbatimModuleSyntax`
114
114
 
@@ -135,8 +135,15 @@ declare module 'foo' {}
135
135
 
136
136
  ## When Not To Use It
137
137
 
138
- If your project was architected before modern modules and namespaces, it may be difficult to migrate off of namespaces.
138
+ If your project uses TypeScript's CommonJS export syntax (`export = ...`), you may need to use namespaces in order to export types from your module.
139
+ You can learn more about this at:
140
+
141
+ - [TypeScript#52203](https://github.com/microsoft/TypeScript/pull/52203), the pull request introducing [`verbatimModuleSyntax`](https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax)
142
+ - [TypeScript#60852](https://github.com/microsoft/TypeScript/issues/60852), an issue requesting syntax to export types from a CommonJS module.
143
+
144
+ If your project uses this syntax, either because it was architected before modern modules and namespaces, or because a module option such as `verbatimModuleSyntax` requires it, it may be difficult to migrate off of namespaces.
139
145
  In that case you may not be able to use this rule for parts of your project.
146
+
140
147
  You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
141
148
 
142
149
  ## Further Reading
@@ -144,6 +151,7 @@ You might consider using [ESLint disable comments](https://eslint.org/docs/lates
144
151
  {/* cspell:disable-next-line */}
145
152
 
146
153
  - [FAQ: I get errors from the `@typescript-eslint/no-namespace` and/or `no-var` rules about declaring global variables](/troubleshooting/faqs/eslint#i-get-errors-from-the-typescript-eslintno-namespace-andor-no-var-rules-about-declaring-global-variables)
147
- - [Modules](https://www.typescriptlang.org/docs/handbook/modules.html)
148
- - [Namespaces](https://www.typescriptlang.org/docs/handbook/namespaces.html)
149
- - [Namespaces and Modules](https://www.typescriptlang.org/docs/handbook/namespaces-and-modules.html)
154
+ - [FAQ: How should I handle reports that conflict with verbatimModuleSyntax?](/troubleshooting/faqs/typescript#how-should-i-handle-reports-that-conflict-with-verbatimmodulesyntax)
155
+ - [TypeScript handbook entry on Modules](https://www.typescriptlang.org/docs/handbook/modules.html)
156
+ - [TypeScript handbook entry on Namespaces](https://www.typescriptlang.org/docs/handbook/namespaces.html)
157
+ - [TypeScript handbook entry on Namespaces and Modules](https://www.typescriptlang.org/docs/handbook/namespaces-and-modules.html)
@@ -9,7 +9,9 @@ import TabItem from '@theme/TabItem';
9
9
  >
10
10
  > See **https://typescript-eslint.io/rules/no-require-imports** for documentation.
11
11
 
12
- Prefer the newer ES6-style imports over `require()`.
12
+ Depending on your TSConfig settings and whether you're authoring ES Modules or CommonJS, TS may allow both `import` and `require()` to be used, even within a single file.
13
+
14
+ This rule enforces that you use the newer ES Module `import` syntax over CommonJS `require()`.
13
15
 
14
16
  ## Examples
15
17
 
@@ -42,7 +44,7 @@ import * as lib3 from 'lib3';
42
44
 
43
45
  These strings will be compiled into regular expressions with the `u` flag and be used to test against the imported path. A common use case is to allow importing `package.json`. This is because `package.json` commonly lives outside of the TS root directory, so statically importing it would lead to root directory conflicts, especially with `resolveJsonModule` enabled. You can also use it to allow importing any JSON if your environment doesn't support JSON modules, or use it for other cases where `import` statements cannot work.
44
46
 
45
- With `{allow: ['/package\\.json$']}`:
47
+ With `{ allow: ['/package\\.json$'] }`:
46
48
 
47
49
  <Tabs>
48
50
  <TabItem value="❌ Incorrect">
@@ -66,9 +68,9 @@ console.log(require('../package.json').version);
66
68
  {/* insert option description */}
67
69
 
68
70
  When set to `true`, `import ... = require(...)` declarations won't be reported.
69
- This is useful if you use certain module options that require strict CommonJS interop semantics.
71
+ This is beneficial if you use certain module options that require strict CommonJS interop semantics, such as [verbatimModuleSyntax](https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax).
70
72
 
71
- With `{allowAsImport: true}`:
73
+ With `{ allowAsImport: true }`:
72
74
 
73
75
  <Tabs>
74
76
  <TabItem value="❌ Incorrect">
@@ -90,10 +92,22 @@ import foo from 'foo';
90
92
  </TabItem>
91
93
  </Tabs>
92
94
 
95
+ ## Usage with CommonJS
96
+
97
+ While this rule is primarily intended to promote ES Module syntax, it still makes sense to enable this rule when authoring CommonJS modules.
98
+
99
+ If you prefer to use TypeScript's built-in `import ... from ...` ES Module syntax, which is transformed to `require()` calls during transpilation when outputting CommonJS, you can use the rule's default behavior.
100
+
101
+ If, instead, you prefer to use `require()` syntax, we recommend you use this rule with [`allowAsImport`](#allowAsImport) enabled.
102
+ That way, you still enforce usage of `import ... = require(...)` rather than bare `require()` calls, which are not statically analyzed by TypeScript.
103
+ We don't directly a way to _prohibit_ ES Module syntax from being used; consider instead using TypeScript's [`verbatimModuleSyntax`](https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax) option if you find yourself in a situation where you would want this.
104
+
93
105
  ## When Not To Use It
94
106
 
95
- If your project frequently uses older CommonJS `require`s, then this rule might not be applicable to you.
96
- If only a subset of your project uses `require`s then you might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
107
+ If you are authoring CommonJS modules _and_ your project frequently uses dynamic `require`s, then this rule might not be applicable to you.
108
+ Otherwise the `allowAsImport` option probably suits your needs.
109
+
110
+ If only a subset of your project uses dynamic `require`s then you might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
97
111
 
98
112
  ## Related To
99
113
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/eslint-plugin",
3
- "version": "8.21.1-alpha.10",
3
+ "version": "8.21.1-alpha.11",
4
4
  "description": "TypeScript plugin for ESLint",
5
5
  "files": [
6
6
  "dist",
@@ -61,10 +61,10 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "@eslint-community/regexpp": "^4.10.0",
64
- "@typescript-eslint/scope-manager": "8.21.1-alpha.10",
65
- "@typescript-eslint/type-utils": "8.21.1-alpha.10",
66
- "@typescript-eslint/utils": "8.21.1-alpha.10",
67
- "@typescript-eslint/visitor-keys": "8.21.1-alpha.10",
64
+ "@typescript-eslint/scope-manager": "8.21.1-alpha.11",
65
+ "@typescript-eslint/type-utils": "8.21.1-alpha.11",
66
+ "@typescript-eslint/utils": "8.21.1-alpha.11",
67
+ "@typescript-eslint/visitor-keys": "8.21.1-alpha.11",
68
68
  "graphemer": "^1.4.0",
69
69
  "ignore": "^5.3.1",
70
70
  "natural-compare": "^1.4.0",
@@ -75,8 +75,8 @@
75
75
  "@types/marked": "^5.0.2",
76
76
  "@types/mdast": "^4.0.3",
77
77
  "@types/natural-compare": "*",
78
- "@typescript-eslint/rule-schema-to-typescript-types": "8.21.1-alpha.10",
79
- "@typescript-eslint/rule-tester": "8.21.1-alpha.10",
78
+ "@typescript-eslint/rule-schema-to-typescript-types": "8.21.1-alpha.11",
79
+ "@typescript-eslint/rule-tester": "8.21.1-alpha.11",
80
80
  "ajv": "^6.12.6",
81
81
  "cross-env": "^7.0.3",
82
82
  "cross-fetch": "*",