Skip to content

Commit

Permalink
Fix: indent crash on parenthesized global return values (fixes #7573)…
Browse files Browse the repository at this point in the history
… (#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 f56c1ef
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rules/indent.js
Expand Up @@ -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({
Expand Down
42 changes: 42 additions & 0 deletions tests/lib/rules/indent.js
Expand Up @@ -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: [
Expand Down Expand Up @@ -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.