Skip to content

refactor(linter): add diagnostics_with_multiple_fixes to LintContext #11357

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

Conversation

Sysix
Copy link
Member

@Sysix Sysix commented May 28, 2025

With something like that win forward_ref_uses_ref:

fn check_forward_ref_inner<'a>(
    exp: &Expression,
    call_expr: &CallExpression,
    ctx: &LintContext<'a>,
) {
    let (params, span) = match exp {
        Expression::ArrowFunctionExpression(f) => (&f.params, f.span),
        Expression::FunctionExpression(f) => (&f.params, f.span),
        _ => return,
    };
    if params.parameters_count() != 1 || params.rest.is_some() {
        return;
    }

    ctx.diagnostics_with_multiple_fixes(
        forward_ref_uses_ref_diagnostic(span),
        (
            FixKind::Suggestion,
            |fixer: RuleFixer<'_, 'a>| {
                fixer.replace_with(call_expr, exp).with_message("remove `forwardRef` wrapper")
            }
        ),
        (
            FixKind::Suggestion,
            |fixer: RuleFixer<'_, 'a>| {
                fixer.replace_with(call_expr, exp).with_message("add `ref` parameter")
            }
        ),
    );
}

I get in VSCode the setting 🥳
grafik

Copy link
Member Author

Sysix commented May 28, 2025


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.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added A-linter Area - Linter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels May 28, 2025
@Sysix Sysix force-pushed the 05-28-refactor_linter_add_diagnostics_with_multiple_fixes_to_lintcontext_ branch 2 times, most recently from dacffb9 to 59fa982 Compare May 29, 2025 13:08
Copy link

codspeed-hq bot commented May 29, 2025

CodSpeed Instrumentation Performance Report

Merging #11357 will create unknown performance changes

Comparing 05-28-refactor_linter_add_diagnostics_with_multiple_fixes_to_lintcontext_ (50ef691) with main (606bb34)

Summary

🆕 38 new benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
🆕 codegen[RadixUIAdoptionSection.jsx] N/A 132.1 µs N/A
🆕 codegen[binder.ts] N/A 4.8 ms N/A
🆕 codegen[cal.com.tsx] N/A 38.9 ms N/A
🆕 codegen[react.development.js] N/A 2.2 ms N/A
🆕 formatter[RadixUIAdoptionSection.jsx] N/A 299 µs N/A
🆕 formatter[binder.ts] N/A 18.9 ms N/A
🆕 formatter[cal.com.tsx] N/A 142.8 ms N/A
🆕 formatter[react.development.js] N/A 9.2 ms N/A
🆕 lexer[RadixUIAdoptionSection.jsx] N/A 21 µs N/A
🆕 lexer[binder.ts] N/A 929.2 µs N/A
🆕 lexer[cal.com.tsx] N/A 5.8 ms N/A
🆕 lexer[react.development.js] N/A 383.7 µs N/A
🆕 linter[RadixUIAdoptionSection.jsx] N/A 2.8 ms N/A
🆕 linter[binder.ts] N/A 148.5 ms N/A
🆕 linter[cal.com.tsx] N/A 1.3 s N/A
🆕 linter[react.development.js] N/A 54.4 ms N/A
🆕 mangler[RadixUIAdoptionSection.jsx] N/A 14.6 µs N/A
🆕 mangler[binder.ts] N/A 797.2 µs N/A
🆕 mangler[cal.com.tsx] N/A 2.7 ms N/A
🆕 mangler[react.development.js] N/A 282.9 µs N/A
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

@Sysix Sysix marked this pull request as ready for review May 29, 2025 13:28
@Sysix Sysix requested a review from camc314 as a code owner May 29, 2025 13:28
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label May 29, 2025
Copy link
Contributor

camc314 commented May 29, 2025

Merge activity

@Sysix Sysix force-pushed the 05-28-refactor_linter_add_diagnostics_with_multiple_fixes_to_lintcontext_ branch from 59fa982 to 6f6cba6 Compare May 29, 2025 14:10
@Sysix Sysix force-pushed the 05-25-refactor_linter_accept_possiblefixes_instead_of_fix_for_messages_ branch from 0229524 to e832cbc Compare May 29, 2025 14:10
…xt` (#11357)

With something like that win `forward_ref_uses_ref`:

```
fn check_forward_ref_inner<'a>(
    exp: &Expression,
    call_expr: &CallExpression,
    ctx: &LintContext<'a>,
) {
    let (params, span) = match exp {
        Expression::ArrowFunctionExpression(f) => (&f.params, f.span),
        Expression::FunctionExpression(f) => (&f.params, f.span),
        _ => return,
    };
    if params.parameters_count() != 1 || params.rest.is_some() {
        return;
    }

    ctx.diagnostics_with_multiple_fixes(
        forward_ref_uses_ref_diagnostic(span),
        (
            FixKind::Suggestion,
            |fixer: RuleFixer<'_, 'a>| {
                fixer.replace_with(call_expr, exp).with_message("remove `forwardRef` wrapper")
            }
        ),
        (
            FixKind::Suggestion,
            |fixer: RuleFixer<'_, 'a>| {
                fixer.replace_with(call_expr, exp).with_message("add `ref` parameter")
            }
        ),
    );
}
```

I get in VSCode the setting 🥳
![grafik](https://github.com/user-attachments/assets/acf7783f-99d9-441a-8813-b968ac8d9027)
@graphite-app graphite-app bot force-pushed the 05-25-refactor_linter_accept_possiblefixes_instead_of_fix_for_messages_ branch from e832cbc to 606bb34 Compare May 29, 2025 14:14
@graphite-app graphite-app bot force-pushed the 05-28-refactor_linter_add_diagnostics_with_multiple_fixes_to_lintcontext_ branch from 6f6cba6 to 50ef691 Compare May 29, 2025 14:14
Base automatically changed from 05-25-refactor_linter_accept_possiblefixes_instead_of_fix_for_messages_ to main May 29, 2025 14:17
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 29, 2025
@graphite-app graphite-app bot merged commit 50ef691 into main May 29, 2025
24 checks passed
@graphite-app graphite-app bot deleted the 05-28-refactor_linter_add_diagnostics_with_multiple_fixes_to_lintcontext_ branch May 29, 2025 14:18
camc314 added a commit that referenced this pull request May 30, 2025
## [0.17.0] - 2025-05-30

- ead5309 linter: [**BREAKING**] Remove react from default plugin set
(#11382) (camc314)

### Features

- 2d25bd8 linter: Remove `unicorn/no-for-loop` over
`typescript/prefer-for-of` (#11354) (camc314)
- bbb7eb1 linter: Add auto-fix to react/forward-ref-uses-ref (#11342)
(yefan)
- 590c27b linter: Add auto-fix to unicorn/no-await-expression-member
(#11306) (yefan)
- 7824f01 linter: Implement suggestion for `jsx/no-useless-fragment`
(#10800) (Cam McHenry)
- 2083d33 linter/language_server: Add second editor suggestion for
`react/forward-ref-uses-ref` (#11375) (Sysix)

### Bug Fixes

- f6424dd linter: Reflect react plugin is disabled by default in cli
(#11397) (camc314)
- 25ecbfe linter: Remove use of `FrameworkFlags::React` to decide
whether rules should run (#11383) (camc314)
- 0d240e4 linter: False positive in react/exhaustive-deps with default
formal parameter (#11395) (camc314)
- c91697e linter: Fix panic in multi byte char in `TryFrom` aria
(#11350) (camc314)
- 9798ef1 linter: Stack overflow in no-async-endpoint-handlers (#11317)
(camc314)
- 348ad97 linter: Skip no-unused-vars on astro files (#11303) (camc314)
- 183d7f0 linter: Make `jest/no-large-snapshots` error easier to
comprehend (#11294) (Ulrich Stark)
- 4e606a5 linter: Improve `jest/no-large-snapshots` (#11291) (Ulrich
Stark)
- 14f790f linter: Improve `jest/no-restricted-matchers` (#11292) (Ulrich
Stark)
- a2c82be linter/block-scoped-var: Better diagnostic messages (#11290)
(DonIsaac)
- 19772e5 linter/no-unused-vars: Panic when variable is redeclared as
function in same scope (#11280) (Dunqing)
- 7af5bb1 oxc_language_server: Include save option for text document
sync capability (#11297) (Nicholas Rayburn)

### Performance

- 0ed6c1a language_server: Use `Arc<RwLock>` instead of `Mutex` for
workspace workers (#11328) (Sysix)
- a0ee946 linter: Reduce code size in `globals` (#11333) (shulaoda)
- c90c5e9 linter/no-unused-vars: Simplify checking self call usage
(#11281) (Dunqing)

### Documentation

- eae51ca linter: Clarify jsdoc/check-tag-names configuration (#11394)
(Rägnar O'ock)
- cd354d4 oxlint: Remove incorrect doc comment (#11326) (camc314)

### Refactor

- 42738f0 linter: Shorten code of match arms (#11389) (Ulrich Stark)
- 8a34447 linter: Improve `unicorn/text-encoding-identifier-case`
(#11386) (shulaoda)
- eaa605e linter: Avoid some `Arc::clone` in linter runtime (#11388)
(Boshen)
- 1cd8b9c linter: Fixes in `react/forward-ref-uses-ref` are suggestions
(#11376) (Sysix)
- 50ef691 linter: Add `diagnostics_with_multiple_fixes` to `LintContext`
(#11357) (Sysix)
- 606bb34 linter: Accept `PossibleFixes` instead of `Fix` for `Messages`
(#11295) (Sysix)
- 042a3f3 linter: Use `PossibleFixes` instead of `Option<Fix>` (#11284)
(Sysix)
- ffcfb46 linter: Improve `unicorn/throw-new-error` (#11364) (shulaoda)
- 8fb55c3 linter: Cleanup docs and simplify code of
`eslint/no-fallthrough` (#11331) (Ulrich Stark)
- e2f0f0a linter: Improve docs and simplify code of
`eslint/no-duplicate-imports` (#11320) (Ulrich Stark)
- b53b053 linter: Simplify accessing span of NameSpan (#11305) (Ulrich
Stark)
- 4bc2650 linter: Improve `eslint/no-void` (#11285) (shulaoda)

### Styling

- 49b664c linter: Remove needless newline in `declare_oxc_lint` (#11400)
(camc314)

### Testing

- c4f64aa linter: Explicitly disable correctness for clarity (#11327)
(camc314)
- a404b2c linter: `eslint/no-duplicate-imports` shouldn't report the
same span (#11324) (Ulrich Stark)

Co-authored-by: camc314 <[email protected]>
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