feat(linter): accept multiple fixes when fix code#3842
Conversation
Your org has enabled the Graphite merge queue for merging into mainAdd the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix. You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. |
|
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @mysteryven and the rest of your teammates on |
CodSpeed Performance ReportMerging #3842 will not alter performanceComparing Summary
|
Boshen
left a comment
There was a problem hiding this comment.
What's the difference between this and
oxc/crates/oxc_linter/src/fixer.rs
Line 29 in d76f34b
Ideally we should only have 1 - a port from eslint.
|
I need to compose multi #[derive(Debug, Clone, Default)]
pub struct Fix<'a> {
- pub contents: Cow<'a, str>,
+ pub contents: Vec<Cow<'a, str>>,
- pub spans: Span,
+ pub spans: Vec<Span>,
}
ctx.diagnostic_with_fix(
no_import_type_side_effects_diagnostic(import_decl.span),
|fixer| {
let raw = ctx.source_range(import_decl.span);
let mut string_fixer = StringFixer::new(raw);
let mut fix = fixer.new_fix();
fix.replace(span, "abc");
fix.delete(span, "abc");
fix
})I checked rule-fixer.js, and found change Fix is not keep same with ESLint, ESLint produces one fix in RuleFixer's method, so I didn't change The third option is let the fixer return #[derive(Clone)]
pub struct Message<'a> {
pub error: OxcDiagnostic,
pub start: u32,
pub end: u32,
+ pub fixs: Option<Vec<Fix<'a>>>,
- pub fix: Option<Fix<'a>>,
fixed: bool,
}Finally I chose option 1. I thought this way only need to change the least things =.= Now, looks like option 3 is better, are we to accept it? or would you like to give me some advice? |
|
My question is always how does eslint do it? Can we align our implementation with theirs? |
8ba5e23 to
2671cd9
Compare
StringFixer to help modify fixer text2671cd9 to
f67c21b
Compare
Boshen
left a comment
There was a problem hiding this comment.
Are there unit tests from eslint? We should port them over.
4249817 to
ecc2988
Compare
Added now, and it really exposed my bug 😥 |
ecc2988 to
db7c7a6
Compare
Merge activity
|
Want to add this because of there are bunch of fix codes in [consistent-type-import](https://github.com/typescript-eslint/typescript-eslint/blob/e408b93e48e5199d83a8d99d1e27126d2dd8bc8f/packages/eslint-plugin/src/rules/consistent-type-imports.ts#L610-L945) are not easy to port.
db7c7a6 to
63b98bd
Compare
## [0.5.0] - 2024-06-27 - 6796891 ast: [**BREAKING**] Rename all instances of `BigintLiteral` to `BigIntLiteral`. (#3898) (rzvxa) - ae09a97 ast: [**BREAKING**] Remove `Modifiers` from ts nodes (#3846) (Boshen) - 1af5ed3 ast: [**BREAKING**] Replace `Modifiers` with `declare` and `const` on `EnumDeclaration` (#3845) (Boshen) - ee6ec4e ast: [**BREAKING**] Replace `Modifiers` with `declare` and `abstract` on `Class` (#3841) (Boshen) - 4456034 ast: [**BREAKING**] Add `IdentifierReference` to `ExportSpecifier` (#3820) (Boshen) - 0537d29 cfg: [**BREAKING**] Move control flow to its own crate. (#3728) (rzvxa) - 5c38a0f codegen: [**BREAKING**] New code gen API (#3740) (Boshen) - 4bce59d semantic/cfg: [**BREAKING**] Re-export `petgraph` as `control_flow::graph`. (#3722) (rzvxa) ### Features - 3ae2628 linter: Change `no-import-assign` to correctness (#3928) (Boshen) - a89d501 linter: Implement @typescript-eslint/no-non-null-asserted-nulli… (#3850) (kaykdm) - fc48cb4 linter: �eslint-plugin-jest/prefer-jest-mocked (#3865) (cinchen) - 63b98bd linter: Accept multiple fixes when fix code (#3842) (mysteryven) - 328445b linter: Support `vitest/no-disabled-tests` (#3717) (mysteryven) - 8c61f9c linter: Implement @typescript-eslint/no-non-null-assertion (#3825) (kaykdm) - 080ecbd linter: Add `no-fallthrough`. (#3673) (rzvxa) - 9493fbe linter: Add `oxc/no-optional-chaining` rule (#3700) (mysteryven) - 139adfe linter: Add `@typescript-eslint/no-import-type-side_effects` (#3699) (mysteryven) - 5f84500 linter/eslint-plugin-react: Implement prefer-es6-class (#3812) (Jelle van der Waa) - fafe67c linter/import: Implement max-dependencies (#3814) (Jelle van der Waa) - d5f6aeb semantic: Check for illegal symbol modifiers (#3838) (Don Isaac) ### Bug Fixes - 4bd2c88 linter: Fix and promote `getter-return` to correctness. (#3777) (rzvxa) - 1190dee linter: False positives with setters in the `getter-return` rule. (#3714) (rzvxa) - de0690f linter: Do not run getter-return in typescript (#3693) (Boshen) - cf71c23 linter: Edge case with infinite loops. (#3672) (rzvxa) - 5902331 oxlint: Properly report error (#3889) (Luca Bruno) - 99a40ce semantic: `export default foo` should have `ExportLocalName::Default(NameSpan)` entry (#3823) (Boshen) - abd6ac8 semantic/cfg: Discrete finalization path after `NewFunction`s. (#3671) (rzvxa) ### Performance - 4f7ff7e Do not pass `&Atom` to functions (#3818) (overlookmotel) ### Refactor - 4d2b7f1 linter: `LintContext` can now only be constructed with a cfg enabled semantic. (#3761) (rzvxa) - 7302429 linter/prefer_number_properties: Remove the unused `IdentifierName` check (#3822) (Boshen) - d8ad321 semantic: Make control flow generation optional. (#3737) (rzvxa) ### Testing - 887da40 linter: Enable `no-fallthrough` test with `disable-next-line`. (#3766) (rzvxa) Co-authored-by: Boshen <[email protected]>

Want to add this because of there are bunch of fix codes in consistent-type-import are not easy to port.