Skip to content
Permalink
Browse files

Fix: `indent` crash on parenthesized global return values (fixes #7573)…

… (#7596)

* Fix: `indent` crash on parenthesized global return values (fixes #7573)

* Add tests without trailing semicolons
  • Loading branch information...
not-an-aardvark authored and ilyavolodin committed Nov 15, 2016
1 parent 100c6e1 commit f56c1ef0eecfb87c490310a9e77f48f5f4828145
Showing with 44 additions and 2 deletions.
  1. +2 −2 lib/rules/indent.js
  2. +42 −0 tests/lib/rules/indent.js
@@ -264,10 +264,10 @@ module.exports = {

lastNodeCheckEndOffset = lastNodeCheckEndOffset || 0;

const desiredIndent = (indentType === "space" ? " " : "\t").repeat(needed - lastNodeCheckEndOffset);
const desiredIndent = (indentType === "space" ? " " : "\t").repeat(needed);

const textRange = isLastNodeCheck
? [node.range[1] - gottenSpaces - gottenTabs - 1, node.range[1] - 1 - lastNodeCheckEndOffset]
? [node.range[1] - gottenSpaces - gottenTabs - 1 - lastNodeCheckEndOffset, node.range[1] - 1 - lastNodeCheckEndOffset]
: [node.range[0] - gottenSpaces - gottenTabs, node.range[0]];

context.report({
@@ -1710,6 +1710,22 @@ ruleTester.run("indent", rule, {
" );\n" +
"};",
options: [2]
},

// https://github.com/eslint/eslint/issues/7573
{
code:
"return (\n" +
" foo\n" +
");",
parserOptions: {ecmaFeatures: {globalReturn: true}}
},
{
code:
"return (\n" +
" foo\n" +
")",
parserOptions: {ecmaFeatures: {globalReturn: true}}
}
],
invalid: [
@@ -3462,6 +3478,32 @@ ruleTester.run("indent", rule, {
");",
options: [2, {CallExpression: {arguments: 3}}],
errors: expectedErrors([[2, 6, 2, "BinaryExpression"], [3, 6, 14, "UnaryExpression"], [4, 6, 8, "NewExpression"]])
},

// https://github.com/eslint/eslint/issues/7573
{
code:
"return (\n" +
" foo\n" +
" );",
output:
"return (\n" +
" foo\n" +
");",
parserOptions: {ecmaFeatures: {globalReturn: true}},
errors: expectedErrors([3, 0, 4, "ReturnStatement"])
},
{
code:
"return (\n" +
" foo\n" +
" )",
output:
"return (\n" +
" foo\n" +
")",
parserOptions: {ecmaFeatures: {globalReturn: true}},
errors: expectedErrors([3, 0, 4, "ReturnStatement"])
}
]
});

0 comments on commit f56c1ef

Please sign in to comment.
You can’t perform that action at this time.