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
Fix to add parentheses for TSTypeQuery in some case #14042
Changes from 3 commits
4357463
8bd1d57
6075690
13d63c2
20e5a29
2fa910b
338124e
15096f1
57d3a18
59a7a56
f3f7503
7035317
7ea60a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -456,7 +456,14 @@ function needsParens(path, options) { | |
(parent.type === "TSTypeAnnotation" && | ||
path.getParentNode(1).type.startsWith("TSJSDoc")) | ||
); | ||
|
||
case "TSTypeQuery": | ||
if ( | ||
parent.type === "TSIndexedAccessType" || | ||
parent.type === "TSArrayType" | ||
) { | ||
return true; | ||
} | ||
// fallthrough | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think |
||
case "ArrayTypeAnnotation": | ||
return parent.type === "NullableTypeAnnotation"; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`typeof.ts format 1`] = ` | ||
====================================options===================================== | ||
parsers: ["typescript"] | ||
printWidth: 80 | ||
| printWidth | ||
=====================================input====================================== | ||
// https://github.com/typescript-eslint/typescript-eslint/pull/4382 | ||
a as (typeof node.children)[number] | ||
a as (typeof node.children)[] | ||
a as ((typeof node.children)[number])[] | ||
=====================================output===================================== | ||
// https://github.com/typescript-eslint/typescript-eslint/pull/4382 | ||
a as (typeof node.children)[number]; | ||
a as (typeof node.children)[]; | ||
a as (typeof node.children)[number][]; | ||
|
||
================================================================================ | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
run_spec(__dirname, ["typescript"]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// https://github.com/typescript-eslint/typescript-eslint/pull/4382 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this comment |
||
a as (typeof node.children)[number] | ||
a as (typeof node.children)[] | ||
a as ((typeof node.children)[number])[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need check the property name here, in this case
name === "objectType"
.Prettier pr-14042
Playground link
Input:
Output:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this property name was
elementType
May I add a case like the code below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, should be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in this commit. 7035317