Skip to content

refactor(linter): Update from_configuration to return a Result object so we can surface errors in the future.#17479

Merged
camc314 merged 26 commits intomainfrom
from-config-result
Dec 30, 2025
Merged

refactor(linter): Update from_configuration to return a Result object so we can surface errors in the future.#17479
camc314 merged 26 commits intomainfrom
from-config-result

Conversation

@connorshea
Copy link
Member

@connorshea connorshea commented Dec 30, 2025

Built on top of #17478.

Based on the changes I experimented with in #17199, and the suggestion given by camc in that PR.

AI Disclosure: This was done almost entirely via find+replace and manual updates to fix individual rules. I did use AI for the change in 0abc981 since I had trouble figuring out a solution for that.

It may be easier to review this by going through it commit-by-commit.

Ran ecosystem CI on this branch and it looks like it works fine, no new regressions https://github.com/oxc-project/oxc-ecosystem-ci/actions/runs/20590908980

@connorshea connorshea requested a review from camc314 as a code owner December 30, 2025 06:49
@github-actions github-actions bot added A-linter Area - Linter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Dec 30, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 30, 2025

CodSpeed Performance Report

Merging #17479 will not alter performance

Comparing from-config-result (aab3e91) with main (7c60a27)1

Summary

✅ 4 untouched
⏩ 41 skipped2

Footnotes

  1. No successful run was found on main (54b4342) during the generation of this report, so 7c60a27 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 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 from_configuration method across all lint rules to return a Result type instead of Self, enabling better error handling for configuration parsing failures in the future.

Key changes:

  • Updated the Rule trait's from_configuration signature to return Result<Self, serde_json::error::Error>
  • Modified all rule implementations to wrap their return values in Ok()
  • Updated all call sites to unwrap the Result

Reviewed changes

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

Show a summary per file
File Description
crates/oxc_linter/src/rule.rs Updated the Rule trait definition and documentation to use Result return type
tasks/rulegen/template.txt Updated template for new rules to use Result return type
crates/oxc_macros/src/declare_all_lint_rules.rs Modified macro to propagate errors with ? operator
crates/oxc_linter/src/config/rules.rs Added .unwrap() call when creating rules from configuration
crates/oxc_linter/src/tester.rs Added .unwrap() call in test rule configuration
crates/oxc_linter/src/rules/**/*.rs Updated 200+ individual rule implementations to return Ok(...)

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

@camc314 camc314 self-assigned this Dec 30, 2025
@graphite-app graphite-app bot force-pushed the pass-self-to-default-rule-config branch from 505e41e to 3c7ad0a Compare December 30, 2025 11:07
Base automatically changed from pass-self-to-default-rule-config to main December 30, 2025 11:12
@camc314 camc314 merged commit 901eef6 into main Dec 30, 2025
20 checks passed
@camc314 camc314 deleted the from-config-result branch December 30, 2025 18:29
graphite-app bot pushed a commit that referenced this pull request Jan 16, 2026
…t/no-hooks and eslint/no-return-assign rules. (#17600)

AI Disclosure: The changes to `config_builder.rs` and DefaultRuleConfig were heavily assisted with AI (Copilot + Raptor mini + Claude Opus 4.5), but generally seem reasonable to me. I went through a few iterations to get a simpler implementation of the changeset and I'm relatively happy with where we're at now. I am unsure about how performant it is for a large/complex configuration, though.

Closes #17506. Follow-up on #17479.

Basically, this updates two rules (`jest/no-hooks` and `eslint/no-return-assign`) to surface errors when the user provides invalid configuration options.

This will surface all config errors it finds and then bail without doing any linting.

This will hard-error and not continue linting when it hits an invalid config object. There are valid arguments for not doing this and instead just logging a warning and falling back to default values, but I think this is probably the correct option?

I have added direct tests to the rule files themselves for valid/invalid config options, it may be a good idea to update the Tester to accept array of invalid and valid config shapes, but that's something we can figure out later.

I've also added some snapshot tests to ensure that we have snapshots of what it looks like when an invalid config option is hit, and can ensure we don't regress on this behavior in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments