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

Update: check logical assignment operators in the complexity rule #13979

Merged
merged 1 commit into from Jan 15, 2021

Conversation

mdjermanovic
Copy link
Member

Prerequisites checklist

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

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

What rule do you want to change?

complexity

Does this change cause the rule to produce more or fewer warnings?

more

How will the change be implemented? (New option, new default behavior, etc.)?

new default behavior

Please provide some example code that this change will affect:

/*eslint complexity: ["error", 3]*/

function foo() {
  a &&= bar;
  b ||= bar;
  c ??= bar;
}

What does the rule currently do for this code?

no errors

What will the rule do after it's changed?

report an error that function foo has a complexity of 4.

What changes did you make? (Give an overview)

Changed the complexity rule to increment complexity on each &&=, ||=, or ??=.

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

This was originally planned for the next major release, but given the recent semver policy update we can release this change in a minor version.

I marked this as accepted since the rule already reports equivalent and nearly equivalent code:

/*eslint complexity: ["error", 3]*/

// error
function foo() {
  a = a && bar;
  b = b || bar;
  c = c ?? bar;
}

// error
function foo() {
  a && (a = bar);
  b || (b = bar);
  c ?? (c = bar);
}

// error
function foo() {
  if (a) a = bar;  
  if (!b) b = bar;
  if (c == null) c = bar;
}

// currently no error
function foo() {
  a &&= bar;
  b ||= bar;
  c ??= bar;
}

online demo

@mdjermanovic mdjermanovic added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion new syntax This issue is related to new syntax that has reached stage 4 labels Jan 4, 2021
@mdjermanovic mdjermanovic mentioned this pull request Jan 4, 2021
12 tasks
Copy link
Member

@yeonjuan yeonjuan left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@mdjermanovic mdjermanovic merged commit f17c3c3 into master Jan 15, 2021
@mdjermanovic mdjermanovic deleted the logicalassignment-complexity branch January 15, 2021 20:13
This was referenced Mar 5, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jul 15, 2021
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jul 15, 2021
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 enhancement This change enhances an existing feature of ESLint new syntax This issue is related to new syntax that has reached stage 4 rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants