From f46ed71d8a9e8d511f1cf5c8248202cb10c814cc Mon Sep 17 00:00:00 2001 From: Wenzhe Wang Date: Sun, 7 Jan 2024 10:23:22 +0800 Subject: [PATCH] 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). --- justfile | 3 +++ tasks/rulegen/src/main.rs | 7 +++++++ tasks/rulegen/src/template.rs | 2 ++ 3 files changed, 12 insertions(+) diff --git a/justfile b/justfile index 522a77157..04fb14fd4 100755 --- a/justfile +++ b/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 diff --git a/tasks/rulegen/src/main.rs b/tasks/rulegen/src/main.rs index 5775261fe..661522792 100644 --- a/tasks/rulegen/src/main.rs +++ b/tasks/rulegen/src/main.rs @@ -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, @@ -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(), }; diff --git a/tasks/rulegen/src/template.rs b/tasks/rulegen/src/template.rs index bab131a30..ed7c7523f 100644 --- a/tasks/rulegen/src/template.rs +++ b/tasks/rulegen/src/template.rs @@ -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())?;