Skip to content

Commit

Permalink
feat(tasks): add eslint-plugin-n rulegen (#2272)
Browse files Browse the repository at this point in the history
related: #493

Support generate rules from
[eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n).
  • Loading branch information
kaykdm authored Feb 2, 2024
1 parent d7feade commit 2ceba79
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tasks/rulegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -437,6 +440,7 @@ pub enum RuleKind {
DeepScan,
NextJS,
JSDoc,
Node,
}

impl RuleKind {
Expand All @@ -452,6 +456,7 @@ impl RuleKind {
"deepscan" => Self::DeepScan,
"nextjs" => Self::NextJS,
"jsdoc" => Self::JSDoc,
"n" => Self::Node,
_ => Self::ESLint,
}
}
Expand All @@ -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"),
}
}
}
Expand All @@ -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(),
};

Expand Down
1 change: 1 addition & 0 deletions tasks/rulegen/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down

0 comments on commit 2ceba79

Please sign in to comment.