Skip to content
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

Fix: support for MemberExpression with function body. #7400

Merged
merged 1 commit into from Oct 23, 2016

Conversation

sstern6
Copy link
Contributor

@sstern6 sstern6 commented Oct 19, 2016

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

This PR fixes: #7366 and possibly #7320.

What changes did you make? (Give an overview)
Updated indent.js and tests to ensure support for function bodies inside of MemberExpressions.

Is there anything you'd like reviewers to focus on?

@eslintbot
Copy link

LGTM

@mention-bot
Copy link

@sstern6, thanks for your PR! By analyzing the history of the files in this pull request, we identified @nzakas, @gyandeeps and @vitorbal to be potential reviewers.

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a few artifacts from earlier attempts at solving this problem left over- see if you can remove one or both of the blocks I've flagged and have tests continue to pass. If not, no worries, but I want to make sure the blocks are necessary first 😄

return;
}

if (getParentNodeByType(node, "VariableDeclaration", "FunctionExpression")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check for VariableDeclaration as well as VariableDeclarator? Please try removing this block and see if tests still pass.

let parent = node.parent;

while (parent.type !== type && parent.type !== "Program") {
if (!stopAt) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block might not be necessary since we changed line 392 to check explicitly against Program, see if you can remove this?

@eslintbot
Copy link

LGTM

@sstern6
Copy link
Contributor Author

sstern6 commented Oct 19, 2016

@platinumazure Back up with your comments resolved

@nzakas nzakas added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels Oct 21, 2016
@nzakas
Copy link
Member

nzakas commented Oct 21, 2016

@platinumazure want to take another look?

@platinumazure
Copy link
Member

Irritating, I could swear I reviewed this already. Sorry folks. LGTM, thanks @sstern6!

@gyandeeps
Copy link
Member

I will merge.. just want feedback from our other indent experts like @not-an-aardvark @BYK

@@ -888,11 +880,11 @@ module.exports = {
// alter the expectation of correct indentation. Skip them.
// TODO: Add appropriate configuration options for variable
// declarations and assignments.
if (getVariableDeclaratorNode(node)) {
if (getParentNodeByType(node, "VariableDeclarator", "FunctionExpression")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should check for ArrowFunctionExpression as well.

var foo = () => {
  foo
                .bar // <-- this needs to be checked
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed- the function could be adapted to take an array of stop node types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will have this back up today!

Thanks for the feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @platinumazure @not-an-aardvark used Array.includes in my solution but forgot it wasnt supported, reverted my changes and re pushed. Will have a solution up tonight. Just wanted to give you a heads up.

Thanks

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@eslintbot
Copy link

LGTM

@sstern6
Copy link
Contributor Author

sstern6 commented Oct 23, 2016

@platinumazure @not-an-aardvark back up with your feedback to check for ArrowFunctionExpressions, while also supporting a list for stopAt. Because of this, I needed to create a helper function that allowed me to check if the parent.type === stop At NodeType.

Looking forward to your feedback

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a slight nitpick. Thanks!

* @param {array} nodeList list of node types passed in
* @returns {boolean} if parentType matches item in nodeList, otherwise false
*/
function checkIfParentTypeIsInStopNodeList(parentType, nodeList) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a minor nit and shouldn't block this PR from being merged, but I think this function can be replaced with just nodeList.indexOf(parentType) !== -1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

youre right, over engineered this. Be up in 1 min!

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@not-an-aardvark implemented what you recommended, with a small tweak. With the current logic in the whole loop we would need to change it to nodeList.indexOf(parentType) === -1 because in the loop we are looping until parent === type, stopAtList.indexOf(parent.type) === 1, and parent.type === 'Program'. The semantics get a little tricky with the booleans and my implementation in the loop. Let me know if I need to explain further or I missed something.

Thank you

@eslintbot
Copy link

LGTM

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@gyandeeps gyandeeps merged commit c710584 into eslint:master Oct 23, 2016
@sstern6 sstern6 mentioned this pull request Oct 24, 2016
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

indent does not report MemberExpression indents in function body of variable declarations
8 participants