summaryrefslogtreecommitdiff
path: root/tools/eslint/lib/rules/no-unexpected-multiline.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/lib/rules/no-unexpected-multiline.js')
-rw-r--r--tools/eslint/lib/rules/no-unexpected-multiline.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/eslint/lib/rules/no-unexpected-multiline.js b/tools/eslint/lib/rules/no-unexpected-multiline.js
index 6c15f5dd59..9398b8a603 100644
--- a/tools/eslint/lib/rules/no-unexpected-multiline.js
+++ b/tools/eslint/lib/rules/no-unexpected-multiline.js
@@ -30,6 +30,9 @@ module.exports = {
const FUNCTION_MESSAGE = "Unexpected newline between function and ( of function call.";
const PROPERTY_MESSAGE = "Unexpected newline between object and [ of property access.";
const TAGGED_TEMPLATE_MESSAGE = "Unexpected newline between template tag and template literal.";
+ const DIVISION_MESSAGE = "Unexpected newline between numerator and division operator.";
+
+ const REGEX_FLAG_MATCHER = /^[gimuy]+$/;
const sourceCode = context.getSourceCode();
@@ -75,6 +78,19 @@ module.exports = {
return;
}
checkForBreakAfter(node.callee, FUNCTION_MESSAGE);
+ },
+
+ "BinaryExpression[operator='/'] > BinaryExpression[operator='/'].left"(node) {
+ const secondSlash = sourceCode.getTokenAfter(node, token => token.value === "/");
+ const tokenAfterOperator = sourceCode.getTokenAfter(secondSlash);
+
+ if (
+ tokenAfterOperator.type === "Identifier" &&
+ REGEX_FLAG_MATCHER.test(tokenAfterOperator.value) &&
+ secondSlash.range[1] === tokenAfterOperator.range[0]
+ ) {
+ checkForBreakAfter(node.left, DIVISION_MESSAGE);
+ }
}
};