-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
enhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginhas prthere is a PR raised to close thisthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
I would like to enforce function arguments to be read-only (immutable), to prevent me from accidentally mutate user input. I've encountered many modules that accidentally modify a user-supplied options-object.
I would also like to enforce function return values to not be read-only, as that's annoying for users without much benefit, since it's not actually enforced at runtime. This one might be slightly controversial, so could be an option.
Fail
function foo(input: number[]): void {}
function foo(input: string): Readonly<Point> {}
Pass
function foo(input: readonly number[]): void {}
function foo(input: string): Point {}
The rule should support enforcing read-only for:
readonly
(array and tuple)readonly
(object property)Readonly
(object properties)ReadonlyArray
readonly
for object keys:{readonly [user: string]: boolean}
BendingBender, j-f1, otofu-square, ldrick, ryasmi and 24 more
Metadata
Metadata
Assignees
Labels
enhancement: new plugin ruleNew rule request for eslint-pluginNew rule request for eslint-pluginhas prthere is a PR raised to close thisthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin