Skip to content

Commit

Permalink
Fix: indent does not check FunctionDeclaration nodes properly (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BYK authored and Ian VanSchooten committed Aug 24, 2015
1 parent d4702de commit 2a7aaea
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rules/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ module.exports = function(context) {
// If function content is not empty
if (node.body.length > 0) {
// Calculate left shift position don't require strict indent
// allow function body allign to (indentSize * X)
// allow function body align to (indentSize * X)
while (getNodeIndent(node.body[0]) > indent) {
indent += indentSize;
}
Expand Down Expand Up @@ -408,7 +408,7 @@ module.exports = function(context) {
return;
}

if (node.parent && (node.parent.type === "FunctionExpression")) {
if (node.parent && (node.parent.type === "FunctionExpression" || node.parent.type === "FunctionDeclaration")) {
checkIndentInFunctionBlock(node);
return;
}
Expand Down
23 changes: 23 additions & 0 deletions tests/lib/rules/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,29 @@ ruleTester.run("indent", rule, {
"var a = 1\n" +
" ,b = 2\n" +
" ;"
},
{
code:
"export function create (some,\n" +
" argument) {\n" +
" return Object.create({\n" +
" a: some,\n" +
" b: argument\n" +
" });\n" +
"};",
ecmaFeatures: { modules: true },
options: [2]
},
{
code:
"export function create (id, xfilter, rawType,\n" +
" width=defaultWidth, height=defaultHeight,\n" +
" footerHeight=defaultFooterHeight,\n" +
" padding=defaultPadding) {\n" +
" // ... function body, indented two spaces\n" +
"}\n",
ecmaFeatures: { modules: true, defaultParams: true },
options: [2]
}
],
invalid: [
Expand Down

0 comments on commit 2a7aaea

Please sign in to comment.