-
Notifications
You must be signed in to change notification settings - Fork 887
Parenthesized simple types are not fixed correctly when using array-type array-simple #4844
Comments
Format twice as a workaround to palantir/tslint#4844
I'm actually wondering what the expected behavior should be. I suggested that There are no rules that fix the following (playground link): type A = (number);
type B = ((number)); Since TSLint doesn't consider this an error, and doesn't fix it, it would be inconsistent to consider the following an error: type A = (number)[];
type B = ((number))[] As a side note, some formatters (notably, Prettier) remove parentheses in the first example, but not in the second, which I suppose means that they consider the latter to be stylistically acceptable. Perhaps the solution to this issue is simply to consider a parenthesized type to be "simple" if its contents are simple. In other words, the fix would be to ignore parentheses when deciding whether something is a simple type. I'd therefore like to revise the expected behavior: Expected behaviorNo error is raised for |
Format twice as a workaround to palantir/tslint#4844
I am inclined to favor this behavior as well. It's also interesting to note how TSLint fixes parenthesized non-simple array types. type A = ((number&string))[]; // original
type A = Array<(number&string)>; // TSLint-fixed Is the desired behavior to remove only one layer of parentheses, or all of them (or maybe even none at all)? I'm not sure, but I think may decision made should be consistent. The parentheses in What I mean by this is
This goes a little beyond the scope of this PR, but it's one argument for accepting |
I agree with this: I think it's safe to remove parentheses that have a semantic role, but that it is best to let a formatter decide what to do with parentheses serving a stylistic role. So this bug is fixed by:
I submitted a PR doing just that :) |
🤖 Beep boop! 👉 TSLint is deprecated 👈 and you should switch to typescript-eslint! 🤖 🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋 |
Bug Report
Reproduction using TSLint Playground
Playground link
TypeScript code being linted
with
tslint.json
configuration:Actual behavior
tslint --fix
, "fixes"(number)[]
toArray<number>
. This raises an error because of the"array-simple"
rule.Array<T>
instead ofT[]
Expected behavior
tslint --fix
should fix(number)[]
tonumber[]
. No error should be raised.T[]
instead of(T)[]
.The text was updated successfully, but these errors were encountered: