Skip to content

Commit 9948c78

Browse files
authored
feat: add no-rename-default (#132)
1 parent cd52e86 commit 9948c78

37 files changed

+1359
-7
lines changed

.changeset/tasty-colts-cover.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": minor
3+
---
4+
5+
Added `no-rename-default` that forbid importing a default export by a different name. Originally created by @whitneytit, ported by @SukkaW

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
4343
| [no-mutable-exports](docs/rules/no-mutable-exports.md) | Forbid the use of mutable exports with `var` or `let`. | | | | | | |
4444
| [no-named-as-default](docs/rules/no-named-as-default.md) | Forbid use of exported name as identifier of default export. | | ☑️ 🚸 | | | | |
4545
| [no-named-as-default-member](docs/rules/no-named-as-default-member.md) | Forbid use of exported name as property of default export. | | ☑️ 🚸 | | | | |
46+
| [no-rename-default](docs/rules/no-rename-default.md) | Forbid importing a default export by a different name. | | 🚸 | | | | |
4647
| [no-unused-modules](docs/rules/no-unused-modules.md) | Forbid modules without exports, or exports without matching import in another module. | | | | | | |
4748

4849
### Module systems

docs/rules/no-rename-default.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# import-x/no-rename-default
2+
3+
⚠️ This rule _warns_ in the 🚸 `warnings` config.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
Prohibit importing a default export by another name.
8+
9+
## Rule Details
10+
11+
Given:
12+
13+
```js
14+
// api/get-users.js
15+
export default async function getUsers() {}
16+
```
17+
18+
...this would be valid:
19+
20+
```js
21+
import getUsers from './api/get-users.js'
22+
```
23+
24+
...and the following would be reported:
25+
26+
```js
27+
// Caution: `get-users.js` has a default export `getUsers`.
28+
// This imports `getUsers` as `findUsers`.
29+
// Check if you meant to write `import getUsers from './api/get-users'` instead.
30+
import findUsers from './get-users'
31+
```

src/config/flat/warnings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default {
77
rules: {
88
'import-x/no-named-as-default': 1,
99
'import-x/no-named-as-default-member': 1,
10+
'import-x/no-rename-default': 1,
1011
'import-x/no-duplicates': 1,
1112
},
1213
} satisfies PluginFlatBaseConfig

src/config/warnings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export = {
88
rules: {
99
'import-x/no-named-as-default': 1,
1010
'import-x/no-named-as-default-member': 1,
11+
'import-x/no-rename-default': 1,
1112
'import-x/no-duplicates': 1,
1213
},
1314
} satisfies PluginConfig

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import recommended from './config/recommended'
1818
import stage0 from './config/stage-0'
1919
import typescript from './config/typescript'
2020
import warnings from './config/warnings'
21-
2221
// rules
2322
import consistentTypeSpecifierStyle from './rules/consistent-type-specifier-style'
2423
import default_ from './rules/default'
@@ -55,6 +54,7 @@ import noNamespace from './rules/no-namespace'
5554
import noNodejsModules from './rules/no-nodejs-modules'
5655
import noRelativePackages from './rules/no-relative-packages'
5756
import noRelativeParentImports from './rules/no-relative-parent-imports'
57+
import noRenameDefault from './rules/no-rename-default'
5858
import noRestrictedPaths from './rules/no-restricted-paths'
5959
import noSelfImport from './rules/no-self-import'
6060
import noUnassignedImport from './rules/no-unassigned-import'
@@ -94,6 +94,7 @@ const rules = {
9494
'no-named-as-default': noNamedAsDefault,
9595
'no-named-as-default-member': noNamedAsDefaultMember,
9696
'no-anonymous-default-export': noAnonymousDefaultExport,
97+
'no-rename-default': noRenameDefault,
9798
'no-unused-modules': noUnusedModules,
9899

99100
'no-commonjs': noCommonjs,

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