Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(eslint-plugin): [no-redeclare] clearly document type/variable redeclare case #2500

Merged
merged 1 commit into from Sep 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/eslint-plugin/docs/rules/no-redeclare.md
Expand Up @@ -66,4 +66,14 @@ function Baz() {}
namespace Baz {}
```

**Note:** Even with this option set to true, this rule will report if you name a type and a variable the same name. **_This is intentional_**.
Declaring a variable and a type and a variable the same is usually an accident, and it can lead to hard-to-understand code.
If you have a rare case where you're intentionally naming a type the same name as a variable, use a disable comment. For example:

```ts
type something = string;
// eslint-disable-next-line @typescript-eslint/no-redeclare -- intentionally naming the variable the same as the type
const something = 2;
```

<sup>Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-redeclare.md)</sup>
15 changes: 15 additions & 0 deletions packages/eslint-plugin/tests/rules/no-redeclare.test.ts
Expand Up @@ -627,5 +627,20 @@ namespace A {}
},
],
},
{
code: `
type something = string;
const something = 2;
`,
errors: [
{
messageId: 'redeclared',
data: {
id: 'something',
},
line: 3,
},
],
},
],
});