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).
This commit is contained in:
kaykdm 2024-02-02 19:50:58 +09:00 committed by GitHub
parent d7feadedb4
commit 2ceba79dcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 0 deletions

View file

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

View file

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

View file

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