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

feat(linter): implement no-negated-condition rule #8149

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

baseballyama
Copy link
Contributor

@baseballyama baseballyama commented Dec 27, 2024

Copy link

graphite-app bot commented Dec 27, 2024

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Dec 27, 2024
Copy link

codspeed-hq bot commented Dec 27, 2024

CodSpeed Performance Report

Merging #8149 will not alter performance

Comparing baseballyama:feat/lint/no-negated-condition (0cdc22e) with main (5234d96)

Summary

✅ 29 untouched benchmarks

Copy link
Contributor

@Sysix Sysix left a comment

Choose a reason for hiding this comment

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

thanks for the work. I commented some possible improvements.
They are all probably only nitpicking :')

Copy link
Contributor

@Sysix Sysix left a comment

Choose a reason for hiding this comment

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

👍 you can resolve the discussions (I do not have the rights for that ^^)

Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

i think we've already got this rule covered by the unicorn variant?

do you mind porting the test cases to there and seeing if the all pass correctly?

https://github.com/oxc-project/oxc/blob/bd0693bcd01cc826a4717779558e06ce99262732/crates/oxc_linter/src/rules/unicorn/no_negated_condition.rs#L0-L1

@baseballyama
Copy link
Contributor Author

@camc314

I added tests to the unicorn's rule, and they all passed.
I think it would be better to have a rule on the ESLint side as well, so I rewrote it to forward the processing.
What do you think?

@Sysix
Copy link
Contributor

Sysix commented Dec 27, 2024

@camc314 personally I like this remapping. Can we do this the same for other rules and maybe fix #8009 ?

@camc314
Copy link
Contributor

camc314 commented Dec 27, 2024

i haven't looked into #8009.

but we shouldn't have the same code doing the same thing/

That said, it would be OK to map unicorn/no-negated-condition to eslint/no-negated-condition as we do for some of the TS rules.

To clarify, we would change the following

if plugin_name == "typescript" && is_eslint_rule_adapted_to_typescript(rule_name) {
return (rule_name, "eslint");
}

to be something like:

diff --git a/crates/oxc_linter/src/config/rules.rs b/crates/oxc_linter/src/config/rules.rs
index e661f876f..251026b5f 100644
--- a/crates/oxc_linter/src/config/rules.rs
+++ b/crates/oxc_linter/src/config/rules.rs
@@ -160,6 +160,10 @@ fn transform_rule_and_plugin_name<'a>(
         return (rule_name, "eslint");
     }
 
+    if plugin_name == "unicorn" && rule_name == "no-negated-condition" {
+        return ("no-negated-condition", "eslint");
+    }
+
     (rule_name, plugin_name)
 }

that way, regardsless of whether you have eslint/no-negated-condition OR no-negated-condition OR unicorn/no-negated-condition, it should turn on the rule correctly.

@camc314
Copy link
Contributor

camc314 commented Dec 27, 2024

i looked into #8009 briefly and i'm pretty sure it's unrelated to this. it's (possibly - although i couldn't reproduce it) a bug somewhere in our config code

@baseballyama baseballyama force-pushed the feat/lint/no-negated-condition branch from cd2d32e to 24388b5 Compare December 28, 2024 01:07
@baseballyama
Copy link
Contributor Author

@camc314

Thank you for your review! (And other PRs also!)

I updated the PR according to your comment.
24388b5

@baseballyama baseballyama requested a review from camc314 December 28, 2024 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants