Skip to content

[prefer-readonly] False positive on fields within mixin classes #2590

@WGroenestein

Description

@WGroenestein

Repro
Using the repo code from https://github.com/WGroenestein/typescript-eslint-prefer-readonly-class-mixin

  1. run "npm install"
  2. run "npm run build"
  3. see that the build compiles without errors
  4. run "npm run lint"
  5. see that it fails with error
file.ts
  7:3  error  Member '_name' is never reassigned; mark it as `readonly`  @typescript-eslint/prefer-readonly

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

  1. run "npm run fix-lint"
  2. see that it prefixed "_name" in "file.ts" with readonly
  3. run "npm run build"
  4. see that the build fails with error
file.ts(10,9): error TS2540: Cannot assign to '_name' because it is a read-only property.

Expected Result

Fields which are assigned outside the constructor (e.g. setters) in mixin classes are not marked as not assigned / readonly

Actual Result

They are reported as errors, and when running --fix it breaks the build

Additional Info

The debug log can be found in the repo (https://github.com/WGroenestein/typescript-eslint-prefer-readonly-class-mixin/blob/master/debug.log)

Versions

package version
@typescript-eslint/eslint-plugin 4.2.0
@typescript-eslint/parser 4.2.0
TypeScript 4.0.3
ESLint 7.9.0
node 12.18.3

Metadata

Metadata

Assignees

Labels

accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinghas prthere is a PR raised to close thispackage: 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