Skip to content

Commit

Permalink
update no-unexpected-multiline
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jun 17, 2020
1 parent a31e04c commit 6c6bd95
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/rules/no-unexpected-multiline.js
Expand Up @@ -4,12 +4,6 @@
*/
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const astUtils = require("./utils/ast-utils");

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -49,7 +43,10 @@ module.exports = {
* @private
*/
function checkForBreakAfter(node, messageId) {
const openParen = sourceCode.getTokenAfter(node, astUtils.isNotClosingParenToken);
const openParen = sourceCode.getTokenAfter(
node,
t => !(t.type === "Punctuator" && (t.value === ")" || t.value === "?."))
);
const nodeExpressionEnd = sourceCode.getTokenBefore(openParen);

if (openParen.loc.start.line !== nodeExpressionEnd.loc.end.line) {
Expand Down
34 changes: 34 additions & 0 deletions tests/lib/rules/no-unexpected-multiline.js
Expand Up @@ -122,6 +122,16 @@ ruleTester.run("no-unexpected-multiline", rule, {
>\`multiline\`;
`,
parser: require.resolve("../../fixtures/parsers/typescript-parsers/tagged-template-with-generic/tagged-template-with-generic-3")
},

// Optional chaining
{
code: "var a = b\n ?.(x || y).doSomething()",
parserOptions: { ecmaVersion: 2020 }
},
{
code: "var a = b\n ?.[a, b, c].forEach(doSomething)",
parserOptions: { ecmaVersion: 2020 }
}
],
invalid: [
Expand Down Expand Up @@ -303,6 +313,30 @@ ruleTester.run("no-unexpected-multiline", rule, {
messageId: "taggedTemplate"
}
]
},

// Optional chaining
{
code: "var a = b?.\n(x || y).doSomething()",
parserOptions: { ecmaVersion: 2020 },
errors: [{
messageId: "function",
line: 2,
column: 1,
endLine: 2,
endColumn: 2
}]
},
{
code: "var a = b?.\n [a, b, c].forEach(doSomething)",
parserOptions: { ecmaVersion: 2020 },
errors: [{
line: 2,
column: 3,
endLine: 2,
endColumn: 4,
messageId: "property"
}]
}
]
});

0 comments on commit 6c6bd95

Please sign in to comment.