Skip to content

Commit

Permalink
Fix: no reportin for comments inside (fixes eslint#12995)
Browse files Browse the repository at this point in the history
  • Loading branch information
anikethsaha committed May 16, 2020
1 parent 1f17533 commit 39e4753
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/rules/arrow-parens.js
Expand Up @@ -105,6 +105,14 @@ module.exports = {
], `${shouldAddSpaceForAsync ? " " : ""}${paramToken.value}`);
}

if (
node.params.length === 1 &&
(sourceCode.getCommentsBefore(node.params[0]).length > 0 ||
sourceCode.getCommentsAfter(node.params[0]).length > 0)
) {
return;
}

// "as-needed", { "requireForBlockBody": true }: x => x
if (
requireForBlockBody &&
Expand Down
58 changes: 57 additions & 1 deletion tests/lib/rules/arrow-parens.js
Expand Up @@ -29,6 +29,12 @@ const valid = [
"(a) => {\n}",
"a.then((foo) => {});",
"a.then((foo) => { if (true) {}; });",
"const f = (/* */a) => a + a;",
"const f = (a/** */) => a + a;",
"const f = (a//\n) => a + a;",
"const f = (//\na) => a + a;",
"const f = (/*\n */a//\n) => a + a;",
"const f = (/** @type {number} */a/**hello*/) => a + a;",
{ code: "a.then(async (foo) => { if (true) {}; });", parserOptions: { ecmaVersion: 8 } },

// "always" (explicit)
Expand Down Expand Up @@ -68,7 +74,31 @@ const valid = [
{ code: "async a => ({})", options: ["as-needed", { requireForBlockBody: true }], parserOptions: { ecmaVersion: 8 } },
{ code: "async a => a", options: ["as-needed", { requireForBlockBody: true }], parserOptions: { ecmaVersion: 8 } },
{ code: "(a: T) => a", options: ["as-needed", { requireForBlockBody: true }], parser: parser("identifer-type") },
{ code: "(a): T => a", options: ["as-needed", { requireForBlockBody: true }], parser: parser("return-type") }
{ code: "(a): T => a", options: ["as-needed", { requireForBlockBody: true }], parser: parser("return-type") },
{
code: "const f = (/** @type {number} */a/**hello*/) => a + a;",
options: ["as-needed"]
},
{
code: "const f = (/* */a) => a + a;",
options: ["as-needed"]
},
{
code: "const f = (a/** */) => a + a;",
options: ["as-needed"]
},
{
code: "const f = (a//\n) => a + a;",
options: ["as-needed"]
},
{
code: "const f = (//\na) => a + a;",
options: ["as-needed"]
},
{
code: "const f = (/*\n */a//\n) => a + a;",
options: ["as-needed"]
}
];

const type = "ArrowFunctionExpression";
Expand Down Expand Up @@ -271,6 +301,32 @@ const invalid = [
messageId: "unexpectedParensInline",
type
}]
},
{
code: "const f = /** @type {number} */(a)/**hello*/ => a + a;",
options: ["as-needed"],
output: "const f = /** @type {number} */a/**hello*/ => a + a;",
errors: [{
line: 1,
column: 33,
type,
messageId: "unexpectedParens",
endLine: 1,
endColumn: 34
}]
},
{
code: "const f = //\n(a) => a + a;",
output: "const f = //\na => a + a;",
options: ["as-needed"],
errors: [{
line: 2,
column: 2,
type,
messageId: "unexpectedParens",
endLine: 2,
endColumn: 3
}]
}
];

Expand Down

0 comments on commit 39e4753

Please sign in to comment.