Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(eslint-plugin): [prefer-readonly] report if a member's property is reassigned#6043
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Changes fromall commits
3d88d1094c6b988a147ec913d9349c1de04be983e9File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -339,6 +339,34 @@ class Foo { | ||
| } | ||
| `, | ||
| }, | ||
| { | ||
| code: ` | ||
| class Test { | ||
| private testObj = { | ||
| prop: '', | ||
| }; | ||
| public test(): void { | ||
| this.testObj = ''; | ||
| } | ||
| } | ||
| `, | ||
| }, | ||
| { | ||
| code: ` | ||
| class TestObject { | ||
| public prop: number; | ||
| } | ||
| class Test { | ||
| private testObj = new TestObject(); | ||
| public test(): void { | ||
| this.testObj = new TestObject(); | ||
| } | ||
| } | ||
| `, | ||
| }, | ||
| ], | ||
| invalid: [ | ||
| { | ||
| @@ -742,5 +770,322 @@ function ClassWithName<TBase extends new (...args: any[]) => {}>(Base: TBase) { | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: ` | ||
| class Test { | ||
| private testObj = { | ||
| prop: '', | ||
| }; | ||
| public test(): void { | ||
| this.testObj.prop = ''; | ||
| } | ||
| } | ||
| `, | ||
| output: ` | ||
| class Test { | ||
| private readonly testObj = { | ||
| prop: '', | ||
| }; | ||
| public test(): void { | ||
| this.testObj.prop = ''; | ||
| } | ||
| } | ||
| `, | ||
| errors: [ | ||
| { | ||
| data: { | ||
| name: 'testObj', | ||
| }, | ||
| line: 3, | ||
| messageId: 'preferReadonly', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: ` | ||
| class TestObject { | ||
| public prop: number; | ||
| } | ||
| class Test { | ||
| private testObj = new TestObject(); | ||
| public test(): void { | ||
| this.testObj.prop = 10; | ||
| } | ||
| } | ||
| `, | ||
| output: ` | ||
| class TestObject { | ||
| public prop: number; | ||
| } | ||
| class Test { | ||
| private readonly testObj = new TestObject(); | ||
| public test(): void { | ||
| this.testObj.prop = 10; | ||
| } | ||
| } | ||
| `, | ||
| errors: [ | ||
| { | ||
| data: { | ||
| name: 'testObj', | ||
| }, | ||
| line: 7, | ||
| messageId: 'preferReadonly', | ||
| }, | ||
| ], | ||
| }, | ||
Member
| ||
| { | ||
| code: ` | ||
| class Test { | ||
| private testObj = { | ||
| prop: '', | ||
| }; | ||
| public test(): void { | ||
| this.testObj.prop; | ||
| } | ||
| } | ||
| `, | ||
| output: ` | ||
| class Test { | ||
| private readonly testObj = { | ||
| prop: '', | ||
| }; | ||
| public test(): void { | ||
| this.testObj.prop; | ||
| } | ||
| } | ||
| `, | ||
| errors: [ | ||
| { | ||
| data: { | ||
| name: 'testObj', | ||
| }, | ||
| line: 3, | ||
| messageId: 'preferReadonly', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: ` | ||
| class Test { | ||
| private testObj = {}; | ||
| public test(): void { | ||
| this.testObj?.prop; | ||
| } | ||
| } | ||
| `, | ||
| output: ` | ||
| class Test { | ||
| private readonly testObj = {}; | ||
| public test(): void { | ||
| this.testObj?.prop; | ||
| } | ||
| } | ||
| `, | ||
| errors: [ | ||
| { | ||
| data: { | ||
| name: 'testObj', | ||
| }, | ||
| line: 3, | ||
| messageId: 'preferReadonly', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: ` | ||
| class Test { | ||
| private testObj = {}; | ||
| public test(): void { | ||
| this.testObj!.prop; | ||
| } | ||
| } | ||
| `, | ||
| output: ` | ||
| class Test { | ||
| private readonly testObj = {}; | ||
| public test(): void { | ||
| this.testObj!.prop; | ||
| } | ||
| } | ||
| `, | ||
| errors: [ | ||
| { | ||
| data: { | ||
| name: 'testObj', | ||
| }, | ||
| line: 3, | ||
| messageId: 'preferReadonly', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: ` | ||
| class Test { | ||
| private testObj = {}; | ||
| public test(): void { | ||
| this.testObj.prop.prop = ''; | ||
| } | ||
| } | ||
| `, | ||
| output: ` | ||
| class Test { | ||
| private readonly testObj = {}; | ||
| public test(): void { | ||
| this.testObj.prop.prop = ''; | ||
| } | ||
| } | ||
| `, | ||
| errors: [ | ||
| { | ||
| data: { | ||
| name: 'testObj', | ||
| }, | ||
| line: 3, | ||
| messageId: 'preferReadonly', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: ` | ||
| class Test { | ||
| private testObj = {}; | ||
| public test(): void { | ||
| this.testObj.prop.doesSomething(); | ||
| } | ||
| } | ||
| `, | ||
| output: ` | ||
| class Test { | ||
| private readonly testObj = {}; | ||
| public test(): void { | ||
| this.testObj.prop.doesSomething(); | ||
| } | ||
| } | ||
| `, | ||
| errors: [ | ||
| { | ||
| data: { | ||
| name: 'testObj', | ||
| }, | ||
| line: 3, | ||
| messageId: 'preferReadonly', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: ` | ||
| class Test { | ||
| private testObj = {}; | ||
| public test(): void { | ||
| this.testObj?.prop.prop; | ||
| } | ||
| } | ||
| `, | ||
| output: ` | ||
| class Test { | ||
| private readonly testObj = {}; | ||
| public test(): void { | ||
| this.testObj?.prop.prop; | ||
| } | ||
| } | ||
| `, | ||
| errors: [ | ||
| { | ||
| data: { | ||
| name: 'testObj', | ||
| }, | ||
| line: 3, | ||
| messageId: 'preferReadonly', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: ` | ||
| class Test { | ||
| private testObj = {}; | ||
| public test(): void { | ||
| this.testObj?.prop?.prop; | ||
| } | ||
| } | ||
| `, | ||
| output: ` | ||
| class Test { | ||
| private readonly testObj = {}; | ||
| public test(): void { | ||
| this.testObj?.prop?.prop; | ||
| } | ||
| } | ||
| `, | ||
| errors: [ | ||
| { | ||
| data: { | ||
| name: 'testObj', | ||
| }, | ||
| line: 3, | ||
| messageId: 'preferReadonly', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: ` | ||
| class Test { | ||
| private testObj = {}; | ||
| public test(): void { | ||
| this.testObj.prop?.prop; | ||
| } | ||
| } | ||
| `, | ||
| output: ` | ||
| class Test { | ||
| private readonly testObj = {}; | ||
| public test(): void { | ||
| this.testObj.prop?.prop; | ||
| } | ||
| } | ||
| `, | ||
| errors: [ | ||
| { | ||
| data: { | ||
| name: 'testObj', | ||
| }, | ||
| line: 3, | ||
| messageId: 'preferReadonly', | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: ` | ||
| class Test { | ||
| private testObj = {}; | ||
| public test(): void { | ||
| this.testObj!.prop?.prop; | ||
| } | ||
| } | ||
| `, | ||
| output: ` | ||
| class Test { | ||
| private readonly testObj = {}; | ||
| public test(): void { | ||
| this.testObj!.prop?.prop; | ||
| } | ||
| } | ||
| `, | ||
| errors: [ | ||
| { | ||
| data: { | ||
| name: 'testObj', | ||
| }, | ||
| line: 3, | ||
| messageId: 'preferReadonly', | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }); | ||