-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
enhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a lookWaiting for team members to take a look
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
My proposal is suitable for this project
- My proposal specifically checks TypeScript syntax, or it proposes a check that requires type information to be accurate.
- My proposal is not a "formatting rule"; meaning it does not just enforce how code is formatted (whitespace, brace placement, etc).
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Description
Since --enforceReadonly
was never released (microsoft/TypeScript#58296 is still open), it may be a good idea to think about implementing this.
Fail Cases
type MutableA = { a: string };
type ReadonlyA = { readonly a: string };
const mutate = (mut: MutableA): void => {
mut.a = "whoops";
};
const readonlyA: ReadonlyA = { a: "readonly?" };
mutate(readonlyA);
Pass Cases
type MutableA = { a: string };
type ReadonlyA = { readonly a: string };
const read = (mut: ReadonlyA): void => {
// No longer allowed:
// mut.a = "whoops";
};
const readonlyA: ReadonlyA = { a: "readonly?" };
read(readonlyA);
Additional Info
Other implementations:
- https://github.com/iliubinskii/eslint-plugin-misc/blob/master/src/typescript/base/no-unsafe-object-assignment.ts
- (eslint 8) https://github.com/danielnixon/eslint-plugin-total-functions/blob/master/src/rules/no-unsafe-mutable-readonly-assignment.ts
Previous issue: #5954
Metadata
Metadata
Assignees
Labels
enhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a lookWaiting for team members to take a look