From 2ceba79dcd004eff2c8c1a7c5f4a7fe252dc07e9 Mon Sep 17 00:00:00 2001 From: kaykdm <34934746+kaykdm@users.noreply.github.com> Date: Fri, 2 Feb 2024 19:50:58 +0900 Subject: [PATCH] feat(tasks): add eslint-plugin-n rulegen (#2272) related: https://github.com/oxc-project/oxc/issues/493 Support generate rules from [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n). --- justfile | 3 +++ tasks/rulegen/src/main.rs | 7 +++++++ tasks/rulegen/src/template.rs | 1 + 3 files changed, 11 insertions(+) diff --git a/justfile b/justfile index 344a7abb6..41dea3878 100755 --- a/justfile +++ b/justfile @@ -112,6 +112,9 @@ new-jsdoc-rule name: new-react-perf-rule name: cargo run -p rulegen {{name}} react-perf +new-n-rule name: + cargo run -p rulegen {{name}} n + # Sync all submodules with their own remote repos (this is for Boshen updating the submodules) sync-submodules: git submodule update --init --remote diff --git a/tasks/rulegen/src/main.rs b/tasks/rulegen/src/main.rs index fb6fad36e..bbfbedc82 100644 --- a/tasks/rulegen/src/main.rs +++ b/tasks/rulegen/src/main.rs @@ -50,6 +50,9 @@ const JSDOC_TEST_PATH: &str = const REACT_PERF_TEST_PATH: &str = "https://raw.githubusercontent.com/cvazac/eslint-plugin-react-perf/main/tests/lib/rules"; +const NODE_TEST_PATH: &str = + "https://raw.githubusercontent.com/eslint-community/eslint-plugin-n/master/tests/lib/rules"; + struct TestCase<'a> { source_text: String, code: Option, @@ -437,6 +440,7 @@ pub enum RuleKind { DeepScan, NextJS, JSDoc, + Node, } impl RuleKind { @@ -452,6 +456,7 @@ impl RuleKind { "deepscan" => Self::DeepScan, "nextjs" => Self::NextJS, "jsdoc" => Self::JSDoc, + "n" => Self::Node, _ => Self::ESLint, } } @@ -471,6 +476,7 @@ impl Display for RuleKind { Self::Oxc => write!(f, "oxc"), Self::NextJS => write!(f, "eslint-plugin-next"), Self::JSDoc => write!(f, "eslint-plugin-jsdoc"), + Self::Node => write!(f, "eslint-plugin-n"), } } } @@ -495,6 +501,7 @@ fn main() { 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::JSDoc => format!("{JSDOC_TEST_PATH}/{camel_rule_name}.js"), + RuleKind::Node => format!("{NODE_TEST_PATH}/{kebab_rule_name}.js"), RuleKind::Oxc | RuleKind::DeepScan => String::new(), }; diff --git a/tasks/rulegen/src/template.rs b/tasks/rulegen/src/template.rs index 693067218..14e05755a 100644 --- a/tasks/rulegen/src/template.rs +++ b/tasks/rulegen/src/template.rs @@ -41,6 +41,7 @@ impl<'a> Template<'a> { RuleKind::DeepScan => Path::new("crates/oxc_linter/src/rules/deepscan"), RuleKind::NextJS => Path::new("crates/oxc_linter/src/rules/nextjs"), RuleKind::JSDoc => Path::new("crates/oxc_linter/src/rules/jsdoc"), + RuleKind::Node => Path::new("crates/oxc_linter/src/rules/node"), }; std::fs::create_dir_all(path)?;