Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): [array-type] --fix flag removes parentheses from type#5997

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletionspackages/eslint-plugin/src/rules/array-type.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -252,8 +252,7 @@ export default util.createRule<Options, MessageIds>({
}

const type = typeParams[0];
const typeParens =
!util.isParenthesized(type, sourceCode) && typeNeedsParentheses(type);
const typeParens = typeNeedsParentheses(type);
const parentParens =
readonlyPrefix &&
node.parent?.type === AST_NODE_TYPES.TSArrayType &&
Expand Down
55 changes: 55 additions & 0 deletionspackages/eslint-plugin/tests/rules/array-type.test.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1982,6 +1982,61 @@ class Foo<T = Bar[][]> extends Bar<T, T[]> implements Baz<T[]> {
}
`,
);
testOutput(
'array',
`
interface WorkingArray {
outerProperty: Array<
{ innerPropertyOne: string } & { innerPropertyTwo: string }
>;
}

interface BrokenArray {
outerProperty: Array<
({ innerPropertyOne: string } & { innerPropertyTwo: string })
>;
}
`,
`
interface WorkingArray {
outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[];
}

interface BrokenArray {
outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[];
}
`,
);
testOutput(
'array',
`
type WorkingArray = {
outerProperty: Array<
{ innerPropertyOne: string } & { innerPropertyTwo: string }
>;
}

type BrokenArray = {
outerProperty: Array<
({ innerPropertyOne: string } & { innerPropertyTwo: string })
>;
}
`,
`
type WorkingArray = {
outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[];
}

type BrokenArray = {
outerProperty: ({ innerPropertyOne: string } & { innerPropertyTwo: string })[];
}
`,
);
Comment on lines +2010 to +2034
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This test case looks identical to the one above?

Copy link
ContributorAuthor

@mhnaeemmhnaeemNov 16, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@Josh-Cena One is with type and the other one is with interface, I wanted to be sure it doesn't affect the code different on either keyword. I can modify it a bit if you like@Josh-Cena

Maybe something like
type BrokenArray = Array<({ a: number } & { b: string })>

testOutput(
'array',
'const a: Array<(string|number)>;',
'const a: (string|number)[];',
);
testOutput(
'array-simple',
'let xx: Array<Array<number>> = [[1, 2], [3]];',
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp