Skip to content

Commit

Permalink
feat: add no-rename-default (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Aug 26, 2024
1 parent cd52e86 commit 9948c78
Show file tree
Hide file tree
Showing 37 changed files with 1,359 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-colts-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-import-x": minor
---

Added `no-rename-default` that forbid importing a default export by a different name. Originally created by @whitneytit, ported by @SukkaW
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a
| [no-mutable-exports](docs/rules/no-mutable-exports.md) | Forbid the use of mutable exports with `var` or `let`. | | | | | | |
| [no-named-as-default](docs/rules/no-named-as-default.md) | Forbid use of exported name as identifier of default export. | | ☑️ 🚸 | | | | |
| [no-named-as-default-member](docs/rules/no-named-as-default-member.md) | Forbid use of exported name as property of default export. | | ☑️ 🚸 | | | | |
| [no-rename-default](docs/rules/no-rename-default.md) | Forbid importing a default export by a different name. | | 🚸 | | | | |
| [no-unused-modules](docs/rules/no-unused-modules.md) | Forbid modules without exports, or exports without matching import in another module. | | | | | | |

### Module systems
Expand Down
31 changes: 31 additions & 0 deletions docs/rules/no-rename-default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# import-x/no-rename-default

⚠️ This rule _warns_ in the 🚸 `warnings` config.

<!-- end auto-generated rule header -->

Prohibit importing a default export by another name.

## Rule Details

Given:

```js
// api/get-users.js
export default async function getUsers() {}
```

...this would be valid:

```js
import getUsers from './api/get-users.js'
```

...and the following would be reported:

```js
// Caution: `get-users.js` has a default export `getUsers`.
// This imports `getUsers` as `findUsers`.
// Check if you meant to write `import getUsers from './api/get-users'` instead.
import findUsers from './get-users'
```
1 change: 1 addition & 0 deletions src/config/flat/warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
rules: {
'import-x/no-named-as-default': 1,
'import-x/no-named-as-default-member': 1,
'import-x/no-rename-default': 1,
'import-x/no-duplicates': 1,
},
} satisfies PluginFlatBaseConfig
1 change: 1 addition & 0 deletions src/config/warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export = {
rules: {
'import-x/no-named-as-default': 1,
'import-x/no-named-as-default-member': 1,
'import-x/no-rename-default': 1,
'import-x/no-duplicates': 1,
},
} satisfies PluginConfig
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import recommended from './config/recommended'
import stage0 from './config/stage-0'
import typescript from './config/typescript'
import warnings from './config/warnings'

// rules
import consistentTypeSpecifierStyle from './rules/consistent-type-specifier-style'
import default_ from './rules/default'
Expand Down Expand Up @@ -55,6 +54,7 @@ import noNamespace from './rules/no-namespace'
import noNodejsModules from './rules/no-nodejs-modules'
import noRelativePackages from './rules/no-relative-packages'
import noRelativeParentImports from './rules/no-relative-parent-imports'
import noRenameDefault from './rules/no-rename-default'
import noRestrictedPaths from './rules/no-restricted-paths'
import noSelfImport from './rules/no-self-import'
import noUnassignedImport from './rules/no-unassigned-import'
Expand Down Expand Up @@ -94,6 +94,7 @@ const rules = {
'no-named-as-default': noNamedAsDefault,
'no-named-as-default-member': noNamedAsDefaultMember,
'no-anonymous-default-export': noAnonymousDefaultExport,
'no-rename-default': noRenameDefault,
'no-unused-modules': noUnusedModules,

'no-commonjs': noCommonjs,
Expand Down
Loading

0 comments on commit 9948c78

Please sign in to comment.