Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 4 additions & 5 deletions packages/eslint-plugin/src/rules/no-extra-parens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default util.createRule<Options, MessageIds>({
},
defaultOptions: ['all'],
create(context) {
const sourceCode = context.getSourceCode();
const rules = baseRule.create(context);

function binaryExp(
Expand Down Expand Up @@ -79,11 +80,9 @@ export default util.createRule<Options, MessageIds>({

if (
node.arguments.length === 1 &&
node.typeArguments?.params.some(
param =>
param.type === AST_NODE_TYPES.TSImportType ||
param.type === AST_NODE_TYPES.TSArrayType,
)
// is there any opening parenthesis in type arguments
sourceCode.getTokenAfter(node.callee, util.isOpeningParenToken) !==
sourceCode.getTokenBefore(node.arguments[0], util.isOpeningParenToken)
) {
return rule({
...node,
Expand Down
30 changes: 30 additions & 0 deletions packages/eslint-plugin/tests/rules/no-extra-parens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,26 @@ f<(number | string)[]>(['a', 1])
},
},
},
{
code: `
f<(number)>(1)
`,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
{
code: `
f<(number) | string>(1)
`,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
],

invalid: [
Expand Down Expand Up @@ -608,6 +628,16 @@ f<(number | string)[]>(['a', 1])
},
],
},
{
code: 'a<(A) | number>((1));',
output: 'a<(A) | number>(1);',
errors: [
{
messageId: 'unexpected',
column: 17,
},
],
},
{
code: 'async function f(arg: Promise<any>) { await (arg); }',
output: 'async function f(arg: Promise<any>) { await arg; }',
Expand Down