Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

🐛 ts/useShorthandArrayType is not taking into consideration the need for parenthesis #3111

Closed
1 task done
xunilrj opened this issue Aug 25, 2022 · 0 comments · Fixed by #3119
Closed
1 task done
Labels
A-Linter Area: linter S-Bug: confirmed Status: report has been confirmed as a valid bug
Milestone

Comments

@xunilrj
Copy link
Contributor

xunilrj commented Aug 25, 2022

Environment information

Running the analyzer from the main branch.

What happened?

The lint rule ts/useShorthandArrayType is not taking into consideration the need for parenthesis when creating the suggested fix.

Example:

let v = [] as Array<(...args: E) => void>;
console.log(v);

https://play.rome.tools/?code=let+v+%3D+%5B%5D+as+Array%3C%28...args%3A+E%29+%3D%3E+void%3E%3B%0Aconsole.log%28v%29%3B&lineWidth=80&indentStyle=tab&quoteStyle=double&indentWidth=2&sourceType=module&typescript=true&jsx=false#bABlAHQAIAB2ACAAPQAgAFsAXQAgAGEAcwAgAEEAcgByAGEAeQA8ACgALgAuAC4AYQByAGcAcwA6ACAARQApACAAPQA+ACAAdgBvAGkAZAA+ADsACgBjAG8AbgBzAG8AbABlAC4AbABvAGcAKAB2ACkAOwA=

Suggested fix here is:

error[[ts/useShorthandArrayType](https://rome.tools/docs/lint/rules/useShorthandArrayType/)]: Use shorthand T[] syntax instead of Array<T> syntax.
  ┌─ main.ts:1:15
  │
1 │ let v = [] as Array<(...args: E) => void>;
  │               ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Suggested fix: Use shorthand T[] syntax to replace
    | @@ -1,2 +1,2 @@
0   | - let v = [] as Array<(...args: E) => void>;
  0 | + let v = [] as (...args: E) => void[];
1 1 |   console.log(v);

Expected result

I was expecting the suggested fix to be

let v = [] as ((...args: E) => void)[]; // <- see wrapping parenthesis

Code of Conduct

  • I agree to follow Rome's Code of Conduct
@xunilrj xunilrj added the S-To triage Status: user report of a possible bug that needs to be triaged label Aug 25, 2022
@ematipico ematipico added S-Bug: confirmed Status: report has been confirmed as a valid bug A-Linter Area: linter and removed S-To triage Status: user report of a possible bug that needs to be triaged labels Aug 29, 2022
@ematipico ematipico added this to the 0.9.0 milestone Aug 29, 2022
@leops leops moved this to Done in Rome 2022 Sep 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Linter Area: linter S-Bug: confirmed Status: report has been confirmed as a valid bug
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants