Skip to content

Commit 9715220

Browse files
authored
refactor: backport a few upstream changes (#171)
1 parent 0bac033 commit 9715220

19 files changed

+135
-39
lines changed

.changeset/fast-carpets-teach.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
Perf: avoid regexp during parser choosing

.changeset/hot-jokes-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
Add extra guard for rule `no-named-as-default`. A few guards are borrowed from https://github.com/import-js/eslint-plugin-import/pull/3032, but we don't sync the rest of changes from upstream since we have already implemented a way more performant check.

.changeset/old-years-rest.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
More test cases for `no-named-export` and `no-defualt-export` rule specifically with non-module `sourceType`

.changeset/orange-dryers-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
Fix `export` when there is only one `TSDeclareFunction` (https://github.com/import-js/eslint-plugin-import/pull/3065)

.changeset/shaggy-mayflies-applaud.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
Prevent `ExportMap`'s cache is being tainted by incompatible parser (e.g. old `babel-eslint`). The cache is now skipped w/ incompatible parsers, which might introduce performance impacts only for those who are using incompatible parsers. (https://github.com/import-js/eslint-plugin-import/pull/3062)

.changeset/spicy-mangos-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
Docs: fix a few typos here and there

.changeset/tough-elephants-divide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-import-x": patch
3+
---
4+
5+
Properly fix espree parser w/ ESLint Flat Config

docs/rules/no-relative-packages.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
Use this rule to prevent importing packages through relative paths.
88

9-
It's useful in Yarn/Lerna workspaces, were it's possible to import a sibling
10-
package using `../package` relative path, while direct `package` is the correct one.
9+
It's useful in a monorepo setup, where it's possible to import a sibling package using `../package` relative path, while direct `package` is the correct one.
1110

1211
## Examples
1312

docs/rules/no-restricted-paths.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Some projects contain files which are not always meant to be executed in the same environment.
66
For example consider a web application that contains specific code for the server and some specific code for the browser/client. In this case you don’t want to import server-only files in your client code.
77

8-
In order to prevent such scenarios this rule allows you to define restricted zones where you can forbid files from imported if they match a specific path.
8+
In order to prevent such scenarios this rule allows you to define restricted zones where you can forbid files from being imported if they match a specific path.
99

1010
## Rule Details
1111

src/rules/export.ts

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AST_NODE_TYPES } from '@typescript-eslint/utils'
12
import type { TSESTree } from '@typescript-eslint/utils'
23

34
import {
@@ -30,37 +31,24 @@ const rootProgram = 'root'
3031
const tsTypePrefix = 'type:'
3132

3233
/**
33-
* Detect function overloads like:
34+
* Remove function overloads like:
35+
*
3436
* ```ts
3537
* export function foo(a: number);
3638
* export function foo(a: string);
3739
* export function foo(a: number|string) { return a; }
3840
* ```
3941
*/
40-
function isTypescriptFunctionOverloads(nodes: Set<TSESTree.Node>) {
41-
const nodesArr = [...nodes]
42-
43-
const idents = nodesArr.flatMap(node =>
44-
'declaration' in node && node.declaration?.type === 'TSDeclareFunction'
45-
? node.declaration.id!.name
46-
: [],
47-
)
48-
49-
if (new Set(idents).size !== idents.length) {
50-
return true
51-
}
52-
53-
const types = new Set(nodesArr.map(node => `${node.parent!.type}` as const))
54-
if (!types.has('TSDeclareFunction')) {
55-
return false
56-
}
57-
if (types.size === 1) {
58-
return true
59-
}
60-
if (types.size === 2 && types.has('FunctionDeclaration')) {
61-
return true
42+
function removeTypescriptFunctionOverloads(nodes: Set<TSESTree.Node>) {
43+
for (const node of nodes) {
44+
const declType =
45+
node.type === AST_NODE_TYPES.ExportDefaultDeclaration
46+
? node.declaration.type
47+
: node.parent?.type
48+
if (declType === AST_NODE_TYPES.TSDeclareFunction) {
49+
nodes.delete(node)
50+
}
6251
}
63-
return false
6452
}
6553

6654
/**
@@ -277,14 +265,17 @@ export = createRule<[], MessageId>({
277265
'Program:exit'() {
278266
for (const [, named] of namespace) {
279267
for (const [name, nodes] of named) {
268+
if (nodes.size === 0) {
269+
continue
270+
}
271+
272+
removeTypescriptFunctionOverloads(nodes)
273+
280274
if (nodes.size <= 1) {
281275
continue
282276
}
283277

284-
if (
285-
isTypescriptFunctionOverloads(nodes) ||
286-
isTypescriptNamespaceMerging(nodes)
287-
) {
278+
if (isTypescriptNamespaceMerging(nodes)) {
288279
continue
289280
}
290281

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy