Skip to content

Conversation

@connorshea
Copy link
Contributor

@connorshea connorshea commented Dec 6, 2025

Uses DefaultRuleConfig now, this rule does. Updated to use a proper tuple config, it has been.

Continue to pass, the tests do.

Part of #14743 and dependent on #16555, this PR is.

Generated docs:

## Configuration

### The 1st option

type: `"never" | "always"`

#### `"never"`

The default `"never"` option can have exception options in an object literal, via `exceptRange` and `onlyEquality`.

#### `"always"`

The `"always"` option requires that literal values must always come first in comparisons.

### The 2nd option

This option is an object with the following properties:

#### exceptRange

type: `boolean`

default: `false`

If the `"exceptRange"` property is `true`, the rule _allows_ yoda conditions
in range comparisons which are wrapped directly in parentheses, including the
parentheses of an `if` or `while` condition.
A _range_ comparison tests whether a variable is inside or outside the range
between two literal values.

#### onlyEquality

type: `boolean`

default: `false`

If the `"onlyEquality"` property is `true`, the rule reports yoda
conditions _only_ for the equality operators `==` and `===`. The `onlyEquality`
option allows a superset of the exceptions which `exceptRange` allows, thus
both options are not useful together.

@connorshea connorshea requested a review from camc314 as a code owner December 6, 2025 21:39
@github-actions github-actions bot added A-linter Area - Linter C-docs Category - Documentation. Related to user-facing or internal documentation labels Dec 6, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 6, 2025

CodSpeed Performance Report

Merging #16562 will not alter performance

Comparing yoda-docs (082886a) with handle-tuple-rules-better (19b5d40)

Summary

✅ 4 untouched
⏩ 41 skipped1

Footnotes

  1. 41 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modernizes the eslint/yoda rule to use DefaultRuleConfig for configuration handling and enables automatic schema generation. The rule configuration now uses a tuple struct pattern Yoda(AllowYoda, YodaOptions) to match ESLint's configuration format where the first parameter is a string mode ("never" or "always") and the second is an optional options object with exceptRange and onlyEquality properties.

Key Changes:

  • Replaced manual configuration parsing with DefaultRuleConfig wrapper for cleaner deserialization
  • Restructured configuration types to support automatic schema generation and documentation
  • Removed the rule from the schema exclusion list in test configuration

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
crates/oxc_linter/src/rules/eslint/yoda.rs Refactored configuration handling: introduced AllowYoda enum and YodaOptions struct with proper serde/schema derives, updated from_configuration() to use DefaultRuleConfig, and adjusted run() method to destructure the tuple struct
crates/oxc_linter/tests/rule_configuration_documentation_test.rs Removed eslint/yoda from the exclusion list since it now has proper schema support for auto-generated documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

lol, great PR title and description

@camc314 camc314 self-assigned this Dec 6, 2025
@camc314 camc314 added 0-merge Merge with Graphite Merge Queue and removed 0-merge Merge with Graphite Merge Queue labels Dec 6, 2025
@connorshea connorshea force-pushed the handle-tuple-rules-better branch from ca59885 to 962bfe2 Compare December 6, 2025 22:52
…rule, I have.

Uses DefaultRuleConfig now, this rule does. Updated it to use a proper tuple config, I have.

Continue to pass, the tests do.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-docs Category - Documentation. Related to user-facing or internal documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants