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

Chore: enable no-param-reassign on ESLint codebase #10065

Merged
merged 1 commit into from Mar 8, 2018

Conversation

not-an-aardvark
Copy link
Member

@not-an-aardvark not-an-aardvark commented Mar 6, 2018

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

[x] Other, please explain:

What changes did you make? (Give an overview)

This enables the no-param-reassign rule on the ESLint codebase.

I think reassigning parameters generally makes code harder to read, because it's not possible to skip over a part of a function and assume that the parameter names still refer to the same objects. This is especially true since we require JSDoc comments in our codebase -- after reassigning a parameter, the JSDoc comment is generally inaccurate for the new assigned value.

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

Nothing in particular

@not-an-aardvark not-an-aardvark added the chore label Mar 6, 2018
if (!errors[0].length) {
errors = [errors];
if (Array.isArray(providedIndentType)) {
errors = Array.isArray(providedIndentType[0]) ? providedIndentType : [providedIndentType];
Copy link
Member

@aladdin-add aladdin-add Mar 6, 2018

Choose a reason for hiding this comment

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

providedIndentType can be [[]]? it seems to be string in comment.

Copy link
Member Author

@not-an-aardvark not-an-aardvark Mar 6, 2018

Choose a reason for hiding this comment

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

The function allows omitting the indentType, in which case the first argument gets used used as the errors.

expectedErrors("space", [[]]);

// is the same as

expectedErrors([[]]);

Copy link
Member

@aladdin-add aladdin-add Mar 6, 2018

Choose a reason for hiding this comment

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

I see. Thanks for detailed explanation! 👍

@not-an-aardvark not-an-aardvark merged commit e33bb64 into master Mar 8, 2018
5 checks passed
@not-an-aardvark not-an-aardvark deleted the enable-no-param-reassign branch Mar 8, 2018
Copy link
Member

@ilyavolodin ilyavolodin left a comment

Code changes looks good, however, I'm not sure about enabling no-param-reassign, in general it's a good rule to enable (I always do that), but I also always find exceptions for this rule, and have a bunch of comments in my code-base to disable it.

while (node) {
if (anyFunctionPattern.test(node.type)) {
return node;
for (let currentNode = node; currentNode; currentNode = currentNode.parent) {
Copy link
Member

@ilyavolodin ilyavolodin Mar 8, 2018

Choose a reason for hiding this comment

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

This is completely personal preference, and can be ignored for this PR, but I don't like using for loops for something other then counters. It's unexpected, and makes it much harder to read the code.

@not-an-aardvark
Copy link
Member Author

@not-an-aardvark not-an-aardvark commented Mar 9, 2018

@ilyavolodin Sorry about that. I personally think it's worth enabling the rule since there is usually a better option than reassigning a parameter, and IMO the rule helps in a vast majority of cases. However, I'd be fine with reverting if you feel strongly about not enabling the rule.

It's also worth noting that we'll be able to use default parameters soon when we drop support for Node 4, which will make it easier to have default values without reassigning parameters.

@ilyavolodin
Copy link
Member

@ilyavolodin ilyavolodin commented Mar 9, 2018

No, don't feel strongly enough about it. Just know that every time I enabled it in my code bases, I ended up creating a bunch of exceptions, which is annoying.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Sep 5, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age label Sep 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age chore
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants