Skip to content

[array-type] --fix doesn't parenthesize ReadonlyArray fixes correctly #2741

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
weswigham opened this issue Nov 5, 2020 · 1 comment · Fixed by #2747
Closed

[array-type] --fix doesn't parenthesize ReadonlyArray fixes correctly #2741

weswigham opened this issue Nov 5, 2020 · 1 comment · Fixed by #2747
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@weswigham
Copy link

Repro

type Q = ReadonlyArray<object>[]

Expected Result

type Q = (readonly object[])[];

Actual Result

type Q = readonly object[][];

Additional Info

The lack of parenthesis change which level of array is considered readonly (it goes from the inner array to the outer one), causing a meaningful semantic difference in the resulting code.

Versions

package version
@typescript-eslint/eslint-plugin 4.5.0
@typescript-eslint/parser 4.5.0
TypeScript nightly development version - 11/5/2020
ESLint 7.12.1
node 10.22.0
@weswigham weswigham added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Nov 5, 2020
@bradzacher bradzacher added bug Something isn't working good first issue Good for newcomers and removed triage Waiting for team members to take a look labels Nov 5, 2020
@bradzacher
Copy link
Member

should be pretty straightforward to check if the parent is a TSArrayType and wrap it with parens in that case.

https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/src/rules/array-type.ts#L255-L266

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants