Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "migration-eslint-lint-staged",
"scripts": {
"lint": "eslint ."
"lint": "eslint --cache --cache-location node_modules/.cache/eslint ."
},
"devDependencies": {
"eslint": "^9.0.0",
"vite": "^7.0.0"
},
"lint-staged": {
"*.ts": "eslint --fix"
"*.ts": "eslint --no-color --no-warn-ignored --fix"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default defineConfig({
]
},
staged: {
"*.ts": "vp lint --fix"
"*.ts": "vp lint --no-error-on-unmatched-pattern --fix"
},
});
```
104 changes: 100 additions & 4 deletions crates/vp_migration/src/eslint.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
use crate::script_rewrite::{ScriptRewriteConfig, rewrite_script};
use crate::script_rewrite::{FlagConversion, ScriptRewriteConfig, rewrite_script};

const ESLINT_CONFIG: ScriptRewriteConfig = ScriptRewriteConfig {
source_command: "eslint",
target_subcommand: "lint",
boolean_flags: &[
"--cache",
"--no-eslintrc",
"--no-error-on-unmatched-pattern",
"--debug",
"--no-inline-config",
"--color",
"--no-color",
"--exit-on-fatal-error",
"--stats",
"--pass-on-unpruned-suppressions",
],
value_flags: &[
"--ext",
Expand All @@ -17,10 +21,20 @@ const ESLINT_CONFIG: ScriptRewriteConfig = ScriptRewriteConfig {
"--parser",
"--parser-options",
"--plugin",
"-o",
"--output-file",
"--env",
"--cache-location",
"--cache-file",
"--cache-strategy",
"--concurrency",
],
flag_conversions: &[],
// ESLint only warns about ignored files, but Oxlint fails when they leave nothing to lint.
flag_conversions: &[FlagConversion {
source_flags: &["--no-warn-ignored"],
target_flag: "--no-error-on-unmatched-pattern",
Comment thread
jong-kyung marked this conversation as resolved.
Resolved
dedup_flag: "--no-error-on-unmatched-pattern",
}],
};

/// Rewrite a single script: rename `eslint` → `vp lint` and strip ESLint-only flags.
Expand Down Expand Up @@ -57,11 +71,39 @@ mod tests {
assert_eq!(rewrite_eslint_script("eslint --cache --fix ."), "vp lint --fix .");
assert_eq!(rewrite_eslint_script("eslint --no-eslintrc --fix ."), "vp lint --fix .");
assert_eq!(rewrite_eslint_script("eslint --debug ."), "vp lint .");
// Oxlint supports this flag with the same meaning, so it is kept
assert_eq!(
rewrite_eslint_script("eslint --no-error-on-unmatched-pattern --fix ."),
"vp lint --fix ."
"vp lint --no-error-on-unmatched-pattern --fix ."
);
// ignored-only file lists keep succeeding, as they did with ESLint
assert_eq!(
rewrite_eslint_script("eslint --max-warnings 0 --no-warn-ignored --fix"),
"vp lint --max-warnings 0 --no-error-on-unmatched-pattern --fix"
);
assert_eq!(
rewrite_eslint_script(
"eslint --no-warn-ignored --no-error-on-unmatched-pattern --fix ."
),
"vp lint --no-error-on-unmatched-pattern --fix ."
);
assert_eq!(rewrite_eslint_script("eslint --no-inline-config ."), "vp lint .");
assert_eq!(rewrite_eslint_script("eslint --no-color --stats --fix ."), "vp lint --fix .");

// Oxlint has no cache, so cache options go with --cache
assert_eq!(
rewrite_eslint_script(
"eslint --cache --cache-location node_modules/.cache/eslint --cache-strategy content --fix ."
),
"vp lint --fix ."
);
assert_eq!(rewrite_eslint_script("eslint -o report.txt ."), "vp lint .");

// flags Oxlint accepts stay
assert_eq!(
rewrite_eslint_script("eslint --quiet --max-warnings 0 --ignore-pattern dist ."),
"vp lint --quiet --max-warnings 0 --ignore-pattern dist ."
);

// multiple flags stripped at once
assert_eq!(
Expand Down Expand Up @@ -109,6 +151,60 @@ mod tests {
);
}

#[test]
fn test_rewrite_eslint_strips_flags_oxlint_rejects() {
// Each value flag must also drop its value; a boolean flag must keep the next token.
for flags in [
"-o report.txt",
"--cache-location .eslintcache",
"--cache-file .eslintcache",
"--cache-strategy content",
"--concurrency 2",
"--color",
"--no-color",
"--stats",
"--exit-on-fatal-error",
"--pass-on-unpruned-suppressions",
] {
assert_eq!(
rewrite_eslint_script(&format!("eslint {flags} --fix .")),
"vp lint --fix .",
"{flags}"
);
}

// Stripping these would change what the script checks or fixes, so they stay and fail loudly.
assert_eq!(
rewrite_eslint_script("eslint -c eslint.ci.config.mjs src"),
"vp lint -c eslint.ci.config.mjs src"
);
assert_eq!(
rewrite_eslint_script("eslint --rule 'no-console: error' src"),
"vp lint --rule 'no-console: error' src"
);
for flags in [
"--no-config-lookup",
"--global appRuntime",
"--report-unused-inline-configs error",
"--suppress-rule no-console",
"--suppressions-location suppressions.json",
"--flag v10_config_lookup_from_file",
] {
assert_eq!(
rewrite_eslint_script(&format!("eslint {flags} --fix src")),
format!("vp lint {flags} --fix src"),
);
}
assert_eq!(
rewrite_eslint_script("eslint --fix --pass-on-no-patterns $FILES"),
"vp lint --fix --pass-on-no-patterns $FILES"
);
assert_eq!(
rewrite_eslint_script("eslint --fix --fix-type layout src"),
"vp lint --fix --fix-type layout src"
);
}

#[test]
fn test_rewrite_eslint_compound_commands() {
// subshell (brush-parser adds spaces inside parentheses)
Expand Down
Loading