Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum-iterator.workspace = true
reqwest = { version = "0.12.9", features = ["blocking", "json"] }
serde.workspace = true
convert_case.workspace = true
camino.workspace = true

[lints]
workspace = true
38 changes: 24 additions & 14 deletions crates/xtask/src/new_rule.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use anyhow::Result;
use camino::Utf8PathBuf;
use convert_case::{Case, Casing};

use crate::NewRuleArgs;
use std::{env, fs, path::PathBuf};
use std::{env, fs};

fn make_lint(name: &str) -> String {
let rule_name_snake = name.to_case(Case::Snake);
let rule_name_pascal = name.to_case(Case::Pascal);
format!(
r###"
use squawk_syntax::{{
Expand All @@ -14,11 +17,20 @@ use squawk_syntax::{{

use crate::{{Linter, Violation, Rule}};

pub(crate) fn {rule_name}(ctx: &mut Linter, parse: &Parse<SourceFile>) {{
pub(crate) fn {rule_name_snake}(ctx: &mut Linter, parse: &Parse<SourceFile>) {{
let file = parse.tree();
for item in file.items() {{
todo!();
match item {{
// TODO: update to the item you want to check
ast::Item::CreateTable(create_table) => {{
ctx.report(Violation::new(
Rule::{rule_name_pascal},
"todo".to_string(),
create_table.syntax().text_range(),
"todo or none".to_string(),
));
todo!();
}}
_ => (),
}}
}}
Expand Down Expand Up @@ -54,15 +66,13 @@ mod test {{
assert_eq!(errors.len(), 0);
}}
}}
"###,
rule_name = name,
rule_name_pascal = name.to_case(Case::Pascal),
"###
)
}

fn root_path() -> PathBuf {
let binding = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
PathBuf::from(binding.parent().unwrap().parent().unwrap())
fn root_path() -> Utf8PathBuf {
let binding = Utf8PathBuf::from(env!("CARGO_MANIFEST_DIR"));
Utf8PathBuf::from(binding.parent().unwrap().parent().unwrap())
}

fn create_rule_file(name: &str) -> Result<()> {
Expand All @@ -71,13 +81,13 @@ fn create_rule_file(name: &str) -> Result<()> {
let lint_path = root.join(format!("crates/squawk_linter/src/rules/{}.rs", name));

if fs::exists(&lint_path)? {
println!("skipping rule definition file creation, it already exists");
println!("skipping rule file creation, it already exists {lint_path}");
return Ok(());
}

let lint_data = make_lint(&name);
fs::write(&lint_path, lint_data)?;
println!("created rule file");
println!("created rule file {lint_path}");
Ok(())
}

Expand Down Expand Up @@ -211,12 +221,12 @@ fn docs_create_rule(name: &str) -> Result<()> {
let name_kebab = name.to_case(Case::Kebab);
let rule_doc_path = docs.join(format!("docs/{name_kebab}.md"));
if fs::exists(&rule_doc_path)? {
println!("skipping rule doc file creation, it already exists");
println!("skipping rule doc file creation, it already exists {rule_doc_path}");
return Ok(());
}
let doc = make_doc(&name);
let doc = make_doc(name);
fs::write(&rule_doc_path, doc)?;
println!("created rule doc");
println!("created rule doc {rule_doc_path}");
Ok(())
}

Expand Down
Loading