Skip to content

Commit

Permalink
chore(tasks): support init vitest lint rule (oxc-project#4752)
Browse files Browse the repository at this point in the history
Related to oxc-project#4656
  • Loading branch information
shulaoda authored Aug 8, 2024
1 parent 4d0b40a commit 6cf38cb
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 @@ -148,6 +148,9 @@ new-n-rule name:
new-promise-rule name:
cargo run -p rulegen {{name}} promise

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

clone-submodule dir url sha:
git clone --depth=1 {{url}} {{dir}} || true
cd {{dir}} && git fetch origin {{sha}} && git reset --hard {{sha}}
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 @@ -58,6 +58,9 @@ const TREE_SHAKING_PATH: &str =
const PROMISE_TEST_PATH: &str =
"https://raw.githubusercontent.com/eslint-community/eslint-plugin-promise/main/__tests__";

const VITEST_TEST_PATH: &str =
"https://raw.githubusercontent.com/veritem/eslint-plugin-vitest/main/tests";

struct TestCase {
source_text: String,
code: Option<String>,
Expand Down Expand Up @@ -574,6 +577,7 @@ pub enum RuleKind {
Node,
TreeShaking,
Promise,
Vitest,
}

impl RuleKind {
Expand All @@ -591,6 +595,7 @@ impl RuleKind {
"n" => Self::Node,
"tree-shaking" => Self::TreeShaking,
"promise" => Self::Promise,
"vitest" => Self::Vitest,
_ => Self::ESLint,
}
}
Expand All @@ -612,6 +617,7 @@ impl Display for RuleKind {
Self::Node => write!(f, "eslint-plugin-n"),
Self::TreeShaking => write!(f, "eslint-plugin-tree-shaking"),
Self::Promise => write!(f, "eslint-plugin-promise"),
Self::Vitest => write!(f, "eslint-plugin-vitest"),
}
}
}
Expand Down Expand Up @@ -639,6 +645,7 @@ fn main() {
RuleKind::Node => format!("{NODE_TEST_PATH}/{kebab_rule_name}.js"),
RuleKind::TreeShaking => format!("{TREE_SHAKING_PATH}/{kebab_rule_name}.test.ts"),
RuleKind::Promise => format!("{PROMISE_TEST_PATH}/{kebab_rule_name}.js"),
RuleKind::Vitest => format!("{VITEST_TEST_PATH}/{kebab_rule_name}.test.ts"),
RuleKind::Oxc => 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 @@ -43,6 +43,7 @@ impl<'a> Template<'a> {
RuleKind::Node => Path::new("crates/oxc_linter/src/rules/node"),
RuleKind::TreeShaking => Path::new("crates/oxc_linter/src/rules/tree_shaking"),
RuleKind::Promise => Path::new("crates/oxc_linter/src/rules/promise"),
RuleKind::Vitest => Path::new("crates/oxc_linter/src/rules/vitest"),
};

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

0 comments on commit 6cf38cb

Please sign in to comment.