Skip to content

Commit

Permalink
feat(tasks): Add eslint-plugin-jsdoc rulegen (oxc-project#1965)
Browse files Browse the repository at this point in the history
Hello. 👋🏻 

This PR makes `just new-jsdoc-rule xxxx` command works.

---

Initially, I planned to implement some basic rules later.
However, after struggling for half a day, I realized that it would be
challenging for a beginner like me to do it now. 😓

Once I have looked for something else I can do, and/or read more into
the codebase, I hope to be able to try again at some point.
  • Loading branch information
leaysgur authored and IWANABETHATGUY committed May 29, 2024
1 parent bd4a2a2 commit 5f3ed64
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
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

0 comments on commit 5f3ed64

Please sign in to comment.