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:
Wenzhe Wang 2024-01-07 10:23:22 +08:00 committed by GitHub
parent e550b4bd97
commit f46ed71d8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

View file

@ -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

View file

@ -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(),
};

View file

@ -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())?;