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

[no-shadow] False positive when declaring any TypeScript enum #2466

Closed
3 tasks done
Kenadia opened this issue Sep 1, 2020 · 11 comments
Closed
3 tasks done

[no-shadow] False positive when declaring any TypeScript enum #2466

Kenadia opened this issue Sep 1, 2020 · 11 comments
Labels
fix: user error issue was fixed by correcting the configuration / correcting the code package: parser Issues related to @typescript-eslint/parser

Comments

@Kenadia
Copy link

Kenadia commented Sep 1, 2020

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

export enum SimpleEnum {
  SIMPLE_ENUM_VALUE,
}

Full minimal repro here: https://github.com/Kenadia/no-shadow-eslint-enum-test.

Expected Result

No error.

Actual Result

  1:13  error  'SimpleEnum' is already declared in the upper scope  no-shadow

Additional Info

  eslint:cli CLI args: [ 'src/index.ts', '--debug' ] +0ms
  eslint:cli Running on files +3ms
  eslint:config-array-factory Loading JSON config file: /dir/no-shadow-eslint-enum-test/package.json +0ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '/dir/no-shadow-eslint-enum-test', loose: false } ] +0ms
  eslint:ignore-pattern   processed: { basePath: '/dir/no-shadow-eslint-enum-test', patterns: [ '/**/node_modules/*' ] } +1ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '/dir/no-shadow-eslint-enum-test', loose: false } ] +1ms
  eslint:ignore-pattern   processed: { basePath: '/dir/no-shadow-eslint-enum-test', patterns: [ '/**/node_modules/*' ] } +0ms
  eslint:file-enumerator Start to iterate files: [ 'src/index.ts' ] +0ms
  eslint:file-enumerator File: /dir/no-shadow-eslint-enum-test/src/index.ts +1ms
  eslint:cascading-config-array-factory Load config files for /dir/no-shadow-eslint-enum-test/src. +0ms
  eslint:cascading-config-array-factory No cache found: /dir/no-shadow-eslint-enum-test/src. +0ms
  eslint:config-array-factory Config file not found on /dir/no-shadow-eslint-enum-test/src +3ms
  eslint:cascading-config-array-factory No cache found: /dir/no-shadow-eslint-enum-test. +0ms
  eslint:config-array-factory Loading JS config file: /dir/no-shadow-eslint-enum-test/.eslintrc.js +1ms
  eslint:config-array-factory Config file found: /dir/no-shadow-eslint-enum-test/.eslintrc.js +0ms
  eslint:config-array-factory Loading parser "@typescript-eslint/parser" from /dir/no-shadow-eslint-enum-test/.eslintrc.js +0ms
  eslint:config-array-factory Loaded: @typescript-eslint/parser@4.0.1 (/dir/no-shadow-eslint-enum-test/node_modules/@typescript-eslint/parser/dist/index.js) +1ms
  eslint:config-array-factory Loading plugin "@typescript-eslint" from /dir/no-shadow-eslint-enum-test/.eslintrc.js +215ms
  eslint:config-array-factory Loaded: @typescript-eslint/eslint-plugin@4.0.1 (/dir/no-shadow-eslint-enum-test/node_modules/@typescript-eslint/eslint-plugin/dist/index.js) +1ms
  eslint:config-array-factory Plugin /dir/no-shadow-eslint-enum-test/node_modules/@typescript-eslint/eslint-plugin/dist/index.js loaded in: 122ms +122ms
  eslint:cascading-config-array-factory No cache found: /dir. +340ms
  eslint:config-array-factory Config file not found on /dir +0ms
  eslint:cascading-config-array-factory Stop traversing because of considered root. +0ms
  eslint:rules Loading rule 'no-shadow' (remaining=281) +0ms
  eslint:cascading-config-array-factory Configuration was determined: ConfigArray(2) [ { type: 'config', name: 'DefaultIgnorePattern', filePath: '', criteria: null, env: undefined, globals: undefined, ignorePattern: IgnorePattern { patterns: [Array], basePath: '/dir/no-shadow-eslint-enum-test', loose: false }, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: undefined, settings: undefined }, { type: 'config', name: '.eslintrc.js', filePath: '/dir/no-shadow-eslint-enum-test/.eslintrc.js', criteria: null, env: { node: true }, globals: undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: { error: null, filePath: '/dir/no-shadow-eslint-enum-test/node_modules/@typescript-eslint/parser/dist/index.js', id: '@typescript-eslint/parser', importerName: '.eslintrc.js', importerPath: '/dir/no-shadow-eslint-enum-test/.eslintrc.js' }, parserOptions: { ecmaVersion: 2018, sourceType: 'module' }, plugins: { '@typescript-eslint': [Object] }, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: { 'no-shadow': 'error' }, settings: undefined } ] on /dir/no-shadow-eslint-enum-test/src +3ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/**/node_modules/*' ], basePath: '/dir/no-shadow-eslint-enum-test', loose: false } ] +346ms
  eslint:ignore-pattern   processed: { basePath: '/dir/no-shadow-eslint-enum-test', patterns: [ '/**/node_modules/*' ] } +0ms
  eslint:ignore-pattern Check {
  filePath: '/dir/no-shadow-eslint-enum-test/src/index.ts',
  dot: false,
  relativePath: 'src/index.ts',
  result: false
} +0ms
  eslint:cli-engine Lint /dir/no-shadow-eslint-enum-test/src/index.ts +0ms
  eslint:linter Linting code for /dir/no-shadow-eslint-enum-test/src/index.ts (pass 1) +0ms
  eslint:linter Verify +0ms
  eslint:linter With ConfigArray: /dir/no-shadow-eslint-enum-test/src/index.ts +0ms
  eslint:linter Generating fixed text for /dir/no-shadow-eslint-enum-test/src/index.ts (pass 1) +22ms
  eslint:source-code-fixer Applying fixes +0ms
  eslint:source-code-fixer shouldFix parameter was false, not attempting fixes +0ms
  eslint:file-enumerator Complete iterating files: ["src/index.ts"] +368ms
  eslint:cli-engine Linting complete in: 369ms +22ms

Versions

package version
@typescript-eslint/parser 4.0.1
TypeScript 4.0.2
ESLint 7.8.0
node 12.18.3
@Kenadia Kenadia added package: parser Issues related to @typescript-eslint/parser triage Waiting for maintainers to take a look labels Sep 1, 2020
@bradzacher bradzacher added bug Something isn't working enhancement: plugin rule option New rule option for an existing eslint-plugin rule and removed triage Waiting for maintainers to take a look bug Something isn't working labels Sep 1, 2020
@bradzacher

This comment has been minimized.

@Kenadia

This comment has been minimized.

@bradzacher bradzacher added bug Something isn't working and removed enhancement: plugin rule option New rule option for an existing eslint-plugin rule labels Sep 1, 2020
@bradzacher
Copy link
Member

bradzacher commented Sep 1, 2020

Oh wait I'm so sorry. I completely misunderstood and misread this.
I thought that I fixed this in #2374

Hmm...

There's a passing test for this in master (

`
enum Direction {
left = 'left',
right = 'right',
}
`,
) so this should be working fine.

@jsaguet
Copy link

jsaguet commented Sep 1, 2020

I had the same issue as @Kenadia.

I realized that I was actually using no-shadow rule from eslint package.
After I switched to the configuration as shown in the documentation, I didn't have any issue anymore:

'no-shadow': 'off',
'@typescript-eslint/no-shadow': ['error'],

@Kenadia
Copy link
Author

Kenadia commented Sep 1, 2020

Got it, this is my mistake then, I'm sorry. I was reading through #325 (led there by Google) and didn't realize that a @typescript-eslint/no-shadow rule had been introduced since. Looks like a few people had the same confusion #2374 (comment)

@Kenadia Kenadia closed this as completed Sep 1, 2020
@jsaguet
Copy link

jsaguet commented Sep 1, 2020

I got confused as well.
It was not very clear to me in the release note that I needed to switch to the new rule @typescript-eslint/no-shadow although now that I know it, it does seem clear:

Release note 4.0.0

there are some new extension rules that have been added to better support TS that users will need to switch to:

  • no-redeclare
  • no-shadow

-> I think it would have been more obvious to mention the full name (@typescript-eslint/no-shadow)

@bradzacher
Copy link
Member

Thanks for the heads up! I'll update the release note.

@bradzacher bradzacher added fix: user error issue was fixed by correcting the configuration / correcting the code and removed bug Something isn't working labels Sep 1, 2020
@AArnott
Copy link

AArnott commented Sep 2, 2020

When I add:

'@typescript-eslint/no-shadow': ['error'],

I get one of these errors for each of my .ts source files:

1:1  error  Definition for rule '@typescript-eslint/no-shadow' was not found  @typescript-eslint/no-shadow

Why isn't the fix working for me? I believe I'm using the latest versions of all relevant packages:

		"@typescript-eslint/parser": "^4.0.1",
		"eslint": "^7.8.1",
		"eslint-plugin-github": "^4.1.1",
		"eslint-plugin-jest": "^23.20.0",

@bradzacher
Copy link
Member

You need to install @typescript-eslint/eslint-plugin

@AArnott
Copy link

AArnott commented Sep 2, 2020

Thanks. Should that be added to the release notes, @bradzacher?

@bradzacher
Copy link
Member

bradzacher commented Sep 2, 2020

We generally make the assumption that you're using both the parser and plugin together.
Installing them both is step 0 of our getting started guide.

We also state in the plugin readme that you should be using the same version of the parser and plugin.

Your project does have our plugin installed, but it's installed as a transient dependency via eslint-plugin-github - you should always take care to ensure you're only using installed dependencies, and not transient ones.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fix: user error issue was fixed by correcting the configuration / correcting the code package: parser Issues related to @typescript-eslint/parser
Projects
None yet
Development

No branches or pull requests

4 participants