eslint-plugin-total-functions icon indicating copy to clipboard operation
eslint-plugin-total-functions copied to clipboard

[no-unsafe-mutable-readonly-assignment] add fixer

Open danielnixon opened this issue 3 years ago • 1 comments

For examples where the RHS is an array or object literal we should be able to automatically fix by appending as const.

Example:

const foo: ReadonlyArray<string> = ["foo"];

Should be automatically fixable to this:

const foo: ReadonlyArray<string> = ["foo"] as const;

danielnixon avatar Sep 25 '20 05:09 danielnixon

This fixer would only work if all properties on LHS are readonly, recursively. Otherwise the as const RHS after fixing would fall afoul of the inverse rule: unsafe readonly -> mutable assignment.

We should be able to detect that and only enable the fixer when the LHS in entirely readonly.

danielnixon avatar Sep 25 '20 07:09 danielnixon