New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update: add indent
options for array and object literals (fixes #7473)
#7681
Conversation
LGTM |
@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vitorbal, @alecharmon and @gyandeeps to be potential reviewers. |
} else if (parent.type === "ObjectExpression" || parent.type === "ArrayExpression") { | ||
nodeIndent += options[parent.type] * indentSize; | ||
} else if (parent.type === "CallExpression" || parent.type === "NewExpression") { | ||
nodeIndent += (typeof options.CallExpression.arguments === "number" ? options.CallExpression.arguments : 1) * indentSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incidentally, is typeof
checks unnecessary for ObjectExpression
differently to CallExpression
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because CallExpression
indentation is ignored by default, so the default value of options.CallExpression.arguments
is null
. However, ArrayExpression
and ObjectExpression
indentations are not ignored by default, so the default values of options.ArrayExpression
and options.ObjectExpression
are 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got it. Thank you for the explanation.
Actually, "first" * indentSize
was in mind and I had forgotten that options.CallExpression.arguments
can be null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR!
But, there are cases that it clashes.
} | ||
|
||
if (options[node.type] === "first") { | ||
elementsIndent = elements[0].loc.start.column; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to throw TypeError
if there are empty objects/arrays.
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
I tried to make it work with with indentation like this but had no success. Do you think this is even possible?
I have a rule set like this, and tried different values of ArrayExpression and MemberExpression, no luck.
|
@larionov The correct indentation for that case would be: export default angular.module('foo', [
module1,
module2,
module3
])
.directive('bar', barDirective); or alternatively you could put the .directive call on the same line: export default angular.module('foo', [
module1,
module2,
module3
]).directive('bar', barDirective); Since the array after |
@not-an-aardvark I use http://jsbeautifier.org/ plugin to format my code automatically and it formats this code like in my first example, so I thought that was somewhat generally accepted. But anyway I already formatted all the code like in your first example, not sure how will second one will go with huge lists of directives. |
Just linked to #4081 since it's similar topic. |
This PR seems to have broken Our configuration for indent is: "indent" : [2, 2, {"SwitchCase": 1}], |
@NicholasBoll Can you please open a new issue with what u r seeing. Thanks |
What is the purpose of this pull request? (put an "X" next to item)
[x] Changes an existing rule
See #7473
What changes did you make? (Give an overview)
This adds an
ArrayExpression
andObjectExpression
option to theindent
rule, as described in #7473.Is there anything you'd like reviewers to focus on?
Nothing in particular.