Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tasks): Add eslint-plugin-jsdoc rulegen #1965

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ new-oxc-rule name:
new-nextjs-rule name:
cargo run -p rulegen {{name}} nextjs

new-jsdoc-rule name:
cargo run -p rulegen {{name}} jsdoc

# Sync all submodules with their own remote repos (this is for Boshen updating the submodules)
sync:
git submodule update --init --remote
Expand Down
8 changes: 8 additions & 0 deletions tasks/rulegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const JSX_A11Y_TEST_PATH: &str =
const NEXT_JS_TEST_PATH: &str =
"https://raw.githubusercontent.com/vercel/next.js/canary/test/unit/eslint-plugin-next";

const JSDOC_TEST_PATH: &str =
"https://raw.githubusercontent.com/gajus/eslint-plugin-jsdoc/main/test/rules/assertions";

struct TestCase<'a> {
source_text: String,
code: Option<String>,
Expand Down Expand Up @@ -422,6 +425,7 @@ pub enum RuleKind {
Oxc,
DeepScan,
NextJS,
JSDoc,
}

impl RuleKind {
Expand All @@ -435,6 +439,7 @@ impl RuleKind {
"oxc" => Self::Oxc,
"deepscan" => Self::DeepScan,
"nextjs" => Self::NextJS,
"jsdoc" => Self::JSDoc,
_ => Self::ESLint,
}
}
Expand All @@ -452,6 +457,7 @@ impl Display for RuleKind {
Self::DeepScan => write!(f, "deepscan"),
Self::Oxc => write!(f, "oxc"),
Self::NextJS => write!(f, "eslint-plugin-next"),
Self::JSDoc => write!(f, "eslint-plugin-jsdoc"),
}
}
}
Expand All @@ -463,6 +469,7 @@ fn main() {
let rule_name = args.next().expect("expected rule name").to_case(Case::Snake);
let rule_kind = args.next().map_or(RuleKind::ESLint, |kind| RuleKind::from(&kind));
let kebab_rule_name = rule_name.to_case(Case::Kebab);
let camel_rule_name = rule_name.to_case(Case::Camel);
let plugin_name = rule_kind.to_string();

let rule_test_path = match rule_kind {
Expand All @@ -473,6 +480,7 @@ fn main() {
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::JSDoc => format!("{JSDOC_TEST_PATH}/{camel_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 @@ -39,6 +39,7 @@ impl<'a> Template<'a> {
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"),
RuleKind::JSDoc => Path::new("crates/oxc_linter/src/rules/jsdoc"),
};

std::fs::create_dir_all(path)?;
Expand Down