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 1 commit into from Jan 15, 2021


Copy link

@mdjermanovic mdjermanovic commented Jan 4, 2021

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?


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


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 rule accepted new syntax labels Jan 4, 2021
@mdjermanovic mdjermanovic mentioned this pull request Jan 4, 2021
12 tasks
Copy link

@yeonjuan yeonjuan left a comment


@mdjermanovic mdjermanovic merged commit f17c3c3 into master Jan 15, 2021
13 checks passed
@mdjermanovic mdjermanovic deleted the logicalassignment-complexity branch Jan 15, 2021
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 label Jul 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
accepted archived due to age enhancement new syntax rule
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants