Skip to content

Conversation

@connorshea
Copy link
Contributor

These rules accept tuple options, so this updates the code accordingly to support that. Part of #16023.

init-declarations:

## Configuration

### The 1st option

type: `"always" | "never"`

#### `"always"`

Requires that variables be initialized on declaration. This is the default behavior.

#### `"never"`

Disallows initialization during declaration.

### The 2nd option

This option is an object with the following properties:

#### ignoreForLoopInit

type: `boolean`

default: `false`

When set to `true`, allows uninitialized variables in the init expression of `for`, `for-in`, and `for-of` loops.
Only applies when mode is set to `"never"`.

grouped-accessor-pairs:

## Configuration

### The 1st option

type: `"anyOrder" | "getBeforeSet" | "setBeforeGet"`

#### `"anyOrder"`

Accessors can be in any order. This is the default.

#### `"getBeforeSet"`

Getters must come before setters.

#### `"setBeforeGet"`

Setters must come before getters.

### The 2nd option

This option is an object with the following properties:

#### enforceForTSTypes

type: `boolean`

default: `false`

When `enforceForTSTypes` is enabled, this rule also applies to TypeScript interfaces
and type aliases.

Examples of **incorrect** TypeScript code:

\```ts
interface Foo {
  get a(): string;
  someProperty: string;
  set a(value: string);
}

type Bar = {
  get b(): string;
  someProperty: string;
  set b(value: string);
};
\```

Examples of **correct** TypeScript code:

\```ts
interface Foo {
  get a(): string;
  set a(value: string);
  someProperty: string;
}

type Bar = {
  get b(): string;
  set b(value: string);
  someProperty: string;
};
\```

@connorshea connorshea requested a review from camc314 as a code owner December 6, 2025 20:20
@github-actions github-actions bot added A-linter Area - Linter C-bug Category - Bug labels Dec 6, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 6, 2025

CodSpeed Performance Report

Merging #16561 will not alter performance

Comparing more-more-docs (ac17e8b) 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 refactors the configuration structure for eslint/init-declarations and eslint/grouped-accessor-pairs rules to use tuple-based configs with DefaultRuleConfig, improving documentation generation for these rules. The changes align with the repository's configuration pattern where the first tuple element represents the primary option and the second element contains additional configuration properties.

Key Changes:

  • Migrated both rules from struct-based to tuple-based configuration structure
  • Simplified from_configuration implementation using DefaultRuleConfig wrapper
  • Enhanced documentation with detailed descriptions on enum variants
  • Standardized code formatting (comment style, import organization)

Reviewed changes

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

File Description
crates/oxc_linter/src/rules/eslint/init_declarations.rs Refactored to use tuple-based config InitDeclarations(Mode, InitDeclarationsConfig), replaced manual parsing with serde deserialization, and added enum variant documentation. Missing Serialize derives on config types.
crates/oxc_linter/src/rules/eslint/grouped_accessor_pairs.rs Refactored to use tuple-based config GroupedAccessorPairs(PairOrder, GroupedAccessorPairsConfig), aliased Box to OBox to avoid std library conflicts, updated destructuring patterns throughout, and enhanced documentation.

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

@camc314 camc314 self-assigned this Dec 6, 2025
@connorshea connorshea force-pushed the handle-tuple-rules-better branch from ca59885 to 962bfe2 Compare December 6, 2025 22:52
…ule, as it takes a tuple value.

Also refactor the rule to use DefaultRuleConfig to parse its configuration object.
This should be documented as accepting a tuple of values, not an object. This change corrects that problem and updates the configuration parsing to use DefaultRuleConfig.

I also needed to alias Box as OBox to avoid JsonSchema derive issues. Not entirely clear on why, but it works fine.
This ensures that the match is the primary part of the `run` function, so the codegen can detect it properly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants