Skip to content

Commit

Permalink
docs(eslint-plugin): [no-redeclare] clearly document type/variable re…
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher authored and phaux committed Sep 28, 2020
1 parent 0a62323 commit 24a74bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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,
},
],
},
],
});

0 comments on commit 24a74bb

Please sign in to comment.