Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[prefer-const] does not account for side effect in default argument #2954

Closed
Labels
bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@yoursunny

Description

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

Repro

package.json

{"private":true,"dependencies": {"@typescript-eslint/eslint-plugin":"^4.14.0","@typescript-eslint/parser":"^4.14.0","eslint":"^7.18.0","typescript":"^4.1.3"  },"eslintConfig": {"parser":"@typescript-eslint/parser","plugins": ["@typescript-eslint"    ],"extends": ["eslint:recommended","plugin:@typescript-eslint/recommended"    ]  }}

input.ts

letn=0;exportclassC{constructor(publicreadonlyx=++n){}}

tsconfig.json

{"compilerOptions": {"strict":true,"target":"ES2019"  },"files": ["input.ts"  ]}

Expected Result

./node_modules/.bin/eslint input.js should give no error.

Actual Result

$ ./node_modules/.bin/eslint input.tsC:\Users\sunny\Documents\code\eslint-bug-prefer-const\input.ts  1:5  error  'n' is never reassigned. Use 'const' instead  prefer-const✖ 1 problem (1 error, 0 warnings)  1 error and 0 warnings potentially fixable with the `--fix` option.

If I use--fix, thelet would be changed toconst, and TypeScript will report compilation error.

Additional Info

Compiledinput.js

letn=0;exportclassC{constructor(x=++n){this.x=x;}}

./node_modules/.bin/eslint input.js gives no error.

Versions

packageversion
@typescript-eslint/eslint-plugin4.14.0
@typescript-eslint/parser4.14.0
TypeScript4.1.3
ESLint7.18.0
node15.5.1

This issue did not occur 3 days ago (2021-01-17). All of typescript-eslint, TypeScript, and ESLint had upgrades during this period of time. Downgrading typescript-eslint to 4.13.0 (but not downgrading other packages) seem to solve this problem. Thus, this is a regression.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp