feat(linter): implement unicorn/prefer-ternary#19605
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. This stack of pull requests is managed by Graphite. Learn more about stacking. |
1d74766 to
8bad22c
Compare
f7a4c6d to
a0cbd0d
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
57788eb to
de4ac82
Compare
8e140bf to
96a2135
Compare
6578ec8 to
0b09ea3
Compare
96a2135 to
efd8c0f
Compare
0b09ea3 to
090832c
Compare
efd8c0f to
79fe3b4
Compare
090832c to
cf7c921
Compare
cf7c921 to
4eb6ee4
Compare
There was a problem hiding this comment.
Pull request overview
This pull request implements the unicorn/prefer-ternary linter rule, which suggests using ternary expressions instead of simple if-else statements for improved code conciseness and readability. The rule supports two configuration modes: "always" (default) and "only-single-line".
Changes:
- Added new rule implementation in
prefer_ternary.rswith comprehensive logic for detecting mergeable if-else patterns - Added extensive test coverage with 50+ passing cases and 50+ failing cases
- Updated all generated/integration files to register the new rule
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_linter/src/rules/unicorn/prefer_ternary.rs | Core rule implementation with mergeability checking logic, configuration handling, and comprehensive tests |
| crates/oxc_linter/src/snapshots/unicorn_prefer_ternary.snap | Test snapshot file containing expected diagnostic outputs for 50+ test cases |
| crates/oxc_linter/src/rules.rs | Added module declaration for the new rule |
| crates/oxc_linter/src/generated/rules_enum.rs | Auto-generated enum registration and trait implementations for the rule |
| crates/oxc_linter/src/generated/rule_runner_impls.rs | Auto-generated runner implementation specifying the rule runs on IfStatement nodes |
4eb6ee4 to
ba3a708
Compare
Merge activity
|
ba3a708 to
42f78bb
Compare
# Oxlint ### 🚀 Features - 46177dd linter: Implement unicorn/prefer-module (#19603) (camc314) - 42f78bb linter: Implement unicorn/prefer-ternary (#19605) (camc314) ### 🐛 Bug Fixes - 43df857 react/exhaustive-deps: Normalize .current callback deps (#19610) (camc314) - 574f48f linter/no-throw-literal: Close warning block (#19612) (camc314) - 79fe3b4 linter/prefer-mock-return-shorthand: Avoid unsafe autofixes for call-like returns (#19581) (camc314) - 85045e8 linter: Check protected members in explicit-module-boundary-types (#19594) (camc314) - e38115e linter: Catch missing return type on exported arrow/function expressions (#19587) (Peter Wagenet) - 419d3fd linter: Fix false negatives in typescript/no-require-imports (#19589) (Peter Wagenet) - 7958b56 linter: Fix syntax error reporting in some output formatters. (#19590) (connorshea) - 024f51c linter: Add help text to more eslint diagnostics (#19591) (Anthony Amaro) - a8489a1 linter: Warning `eslint/no-throw-literal` rule to be deprecated, better use `typescript/only-throw-error` (#19593) (Said Atrahouch) - 50fc70d linter/type-aware: Use correct span for disable directives (#19576) (camc314) - 421a99c linter: Add help guidance to eslint diagnostic messages (#19562) (Anthony Amaro) - e81364a linter: Add help text to eslint rule diagnostics (#19560) (Anthony Amaro) - 89b58d0 linter: Add help text to more eslint rule diagnostics (#19561) (Anthony Amaro) - 74f7833 linter/jest/prefer-mock-return-shorthand: Preserve typed arrow returns (#19556) (camc314) - bdd6f34 linter: Restrict prefer-import-in-mock to mock calls (#19555) (camc314) ### 📚 Documentation - a331993 linter: Improve docs for `eslint/radix` rule. (#19611) (connorshea) ### 🛡️ Security - c67f9dc linter: Update ajv version. (#19613) (connorshea) # Oxfmt ### 🚀 Features - 984dc07 oxfmt: Strip `"experimental"SortXxx` prefix (#19567) (leaysgur) ### 🐛 Bug Fixes - d7b63a4 oxfmt: Update API types for `sortPackageJsonOptions` (#19569) (leaysgur) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>

No description provided.