mirror of
https://github.com/danbulant/oxc
synced 2026-05-21 13:18:59 +00:00
feat(tasks): add eslint-plugin-next rulegen (#1921)
closes: #1905 Support generate rules from [eslint-plugin-next](https://nextjs.org/docs/app/building-your-application/configuring/eslint#eslint-plugin).
This commit is contained in:
parent
e550b4bd97
commit
f46ed71d8a
3 changed files with 12 additions and 0 deletions
3
justfile
3
justfile
|
|
@ -99,6 +99,9 @@ new-jsx-a11y-rule name:
|
|||
new-oxc-rule name:
|
||||
cargo run -p rulegen {{name}} oxc
|
||||
|
||||
new-nextjs-rule name:
|
||||
cargo run -p rulegen {{name}} nextjs
|
||||
|
||||
# Sync all submodules with their own remote repos (this is for Boshen updating the submodules)
|
||||
sync:
|
||||
git submodule update --init --remote
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ const REACT_TEST_PATH: &str =
|
|||
const JSX_A11Y_TEST_PATH: &str =
|
||||
"https://raw.githubusercontent.com/jsx-eslint/eslint-plugin-jsx-a11y/main/__tests__/src/rules";
|
||||
|
||||
const NEXT_JS_TEST_PATH: &str =
|
||||
"https://raw.githubusercontent.com/vercel/next.js/canary/test/unit/eslint-plugin-next";
|
||||
|
||||
struct TestCase<'a> {
|
||||
source_text: String,
|
||||
code: Option<String>,
|
||||
|
|
@ -418,6 +421,7 @@ pub enum RuleKind {
|
|||
JSXA11y,
|
||||
Oxc,
|
||||
DeepScan,
|
||||
NextJS,
|
||||
}
|
||||
|
||||
impl RuleKind {
|
||||
|
|
@ -430,6 +434,7 @@ impl RuleKind {
|
|||
"jsx-a11y" => Self::JSXA11y,
|
||||
"oxc" => Self::Oxc,
|
||||
"deepscan" => Self::DeepScan,
|
||||
"nextjs" => Self::NextJS,
|
||||
_ => Self::ESLint,
|
||||
}
|
||||
}
|
||||
|
|
@ -446,6 +451,7 @@ impl Display for RuleKind {
|
|||
Self::JSXA11y => write!(f, "eslint-plugin-jsx-a11y"),
|
||||
Self::DeepScan => write!(f, "deepscan"),
|
||||
Self::Oxc => write!(f, "oxc"),
|
||||
Self::NextJS => write!(f, "eslint-plugin-next"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -466,6 +472,7 @@ fn main() {
|
|||
RuleKind::Unicorn => format!("{UNICORN_TEST_PATH}/{kebab_rule_name}.mjs"),
|
||||
RuleKind::React => format!("{REACT_TEST_PATH}/{kebab_rule_name}.js"),
|
||||
RuleKind::JSXA11y => format!("{JSX_A11Y_TEST_PATH}/{kebab_rule_name}-test.js"),
|
||||
RuleKind::NextJS => format!("{NEXT_JS_TEST_PATH}/{kebab_rule_name}.test.ts"),
|
||||
RuleKind::Oxc | RuleKind::DeepScan => String::new(),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,10 @@ impl<'a> Template<'a> {
|
|||
RuleKind::JSXA11y => Path::new("crates/oxc_linter/src/rules/jsx_a11y"),
|
||||
RuleKind::Oxc => Path::new("crates/oxc_linter/src/rules/oxc"),
|
||||
RuleKind::DeepScan => Path::new("crates/oxc_linter/src/rules/deepscan"),
|
||||
RuleKind::NextJS => Path::new("crates/oxc_linter/src/rules/nextjs"),
|
||||
};
|
||||
|
||||
std::fs::create_dir_all(path)?;
|
||||
let out_path = path.join(format!("{}.rs", self.context.snake_rule_name));
|
||||
|
||||
File::create(out_path.clone())?.write_all(rendered.as_bytes())?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue