Skip to content

Commit 619bd74

Browse files
authored
fix: false positive of no-shadow rule for TypeScript (#666)
1 parent cbe9025 commit 619bd74

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

lib/typescript.js

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ module.exports = {
2929
"@typescript-eslint/prefer-interface": "off",
3030
"@typescript-eslint/prefer-namespace-keyword": "off",
3131

32+
"no-shadow": "off",
33+
"@typescript-eslint/no-shadow": "error",
34+
3235
// These rules are required type information,
3336
// which means these can be checked without parserOptions.project
3437
// "@typescript-eslint/no-for-in-array": "error",

test/fixtures/react-typescript/error.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@ interface Props {
77
const Foo = ({name}: Props) => <p>Foo{...name}</p>;
88

99
const Component = () => <Foo name={['bar', 'foo']} />;
10-
export default Component;
10+
export default Component;
11+
12+
const shadow: number = 1;
13+
const shadowingFunc: () => number = () => {
14+
const shadow: number = 2;
15+
return shadow;
16+
};

test/fixtures/typescript/error.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
const nums: Array<number> = [1, 2, 3];
2+
3+
const shadow: number = 1;
4+
const shadowingFunc: () => number = () => {
5+
const shadow: number = 2;
6+
return shadow;
7+
};

test/react-typescript-test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ describe("react-typescript", () => {
1111
assert.deepStrictEqual(result, {
1212
"ok.tsx": {},
1313
"error.tsx": {
14-
errors: ["@typescript-eslint/array-type"],
14+
errors: [
15+
"@typescript-eslint/array-type",
16+
"@typescript-eslint/no-shadow",
17+
],
1518
},
1619
"warning.tsx": {
1720
warnings: [

test/typescript-test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ describe("typescript", () => {
88
assert.deepStrictEqual(result, {
99
"ok.ts": {},
1010
"error.ts": {
11-
errors: ["@typescript-eslint/array-type"],
11+
errors: [
12+
"@typescript-eslint/array-type",
13+
"@typescript-eslint/no-shadow",
14+
],
1215
},
1316
"warning.ts": {
1417
warnings: [

0 commit comments

Comments
 (0)