Skip to content

Commit

Permalink
build(deps): remove 'case' dependency (#2561)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos authored Apr 22, 2024
1 parent aba7b0c commit d6f1f2b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions crates/biome_aria_metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ version = "0.5.7"


[build-dependencies]
case = "1.0.0"
proc-macro2 = { version = "1.0.63", features = ["span-locations"] }
quote = { workspace = true }
biome_string_case = { workspace = true }
proc-macro2 = { version = "1.0.63", features = ["span-locations"] }
quote = { workspace = true }

[lints]
workspace = true
7 changes: 5 additions & 2 deletions crates/biome_aria_metadata/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! - ARIA property types
//! - ARIA roles

use case::CaseExt;
use biome_string_case::Case;
use proc_macro2::{Ident, Literal, Span, TokenStream};
use quote::quote;
use std::path::PathBuf;
Expand Down Expand Up @@ -250,7 +250,10 @@ fn generate_enums(len: usize, array: std::slice::Iter<&str>, enum_name: &str) ->
let mut from_enum_metadata = Vec::with_capacity(len);
let mut from_string_metadata = Vec::with_capacity(len);
for property in array {
let name = Ident::new(&property.replace('-', "_").to_camel(), Span::call_site());
let name = Ident::new(
&Case::Pascal.convert(&property.replace('-', "_")),
Span::call_site(),
);
let property = Literal::string(property);
from_enum_metadata.push(quote! {
#enum_name::#name => #property
Expand Down
1 change: 0 additions & 1 deletion xtask/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ version = "0.0.0"
[dependencies]
anyhow = "1.0.82"
bpaf = { workspace = true, features = ["derive"] }
case = "1.0.0"
filetime = "0.2.23"
fs_extra = "1.3.0"
git2 = { version = "0.18.3", default-features = false }
Expand Down
27 changes: 14 additions & 13 deletions xtask/codegen/src/generate_new_lintrule.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use biome_string_case::Case;
use bpaf::Bpaf;
use case::CaseExt;
use std::str::FromStr;
use xtask::project_root;

Expand Down Expand Up @@ -198,31 +197,33 @@ impl Rule for {rule_name_upper_camel} {{
}

pub fn generate_new_lintrule(kind: RuleKind, rule_name: &str) {
let rule_name_camel = Case::Camel.convert(rule_name);
let rule_kind = kind.as_str();
let crate_folder = project_root().join(format!("crates/biome_{rule_kind}_analyze"));
let rule_folder = crate_folder.join("src/lint/nursery");
let test_folder = crate_folder.join("tests/specs/nursery");
let rule_name_upper_camel = rule_name.to_camel();
let rule_name_snake = rule_name.to_snake();
let rule_name_lower_camel = rule_name_snake.to_camel_lowercase();

// Generate rule code
let code = generate_rule_template(
&kind,
rule_name_upper_camel.as_str(),
rule_name_lower_camel.as_str(),
Case::Pascal.convert(rule_name).as_str(),
rule_name_camel.as_str(),
);
let file_name = format!(
"{}/{}.rs",
rule_folder.display(),
Case::Snake.convert(rule_name)
);
let file_name = format!("{}/{rule_name_snake}.rs", rule_folder.display());
std::fs::write(file_name, code).unwrap();

let categories_path = "crates/biome_diagnostics_categories/src/categories.rs";
let mut categories = std::fs::read_to_string(categories_path).unwrap();

if !categories.contains(&rule_name_lower_camel) {
let kebab_case_rule = Case::Kebab.convert(&rule_name_lower_camel);
if !categories.contains(&rule_name_camel) {
let kebab_case_rule = Case::Kebab.convert(&rule_name_camel);
// We sort rules to reduce conflicts between contributions made in parallel.
let rule_line = format!(
r#" "lint/nursery/{rule_name_lower_camel}": "https://biomejs.dev/linter/rules/{kebab_case_rule}","#
r#" "lint/nursery/{rule_name_camel}": "https://biomejs.dev/linter/rules/{kebab_case_rule}","#
);
let lint_start = "define_categories! {\n";
let lint_end = "\n ;\n";
Expand All @@ -239,11 +240,11 @@ pub fn generate_new_lintrule(kind: RuleKind, rule_name: &str) {
}

// Generate test code
let tests_path = format!("{}/{rule_name_lower_camel}", test_folder.display());
let tests_path = format!("{}/{rule_name_camel}", test_folder.display());
let _ = std::fs::create_dir_all(tests_path);

let test_file = format!(
"{}/{rule_name_lower_camel}/valid.{rule_kind}",
"{}/{rule_name_camel}/valid.{rule_kind}",
test_folder.display()
);
if std::fs::File::open(&test_file).is_err() {
Expand All @@ -254,7 +255,7 @@ pub fn generate_new_lintrule(kind: RuleKind, rule_name: &str) {
}

let test_file = format!(
"{}/{rule_name_lower_camel}/invalid.{rule_kind}",
"{}/{rule_name_camel}/invalid.{rule_kind}",
test_folder.display()
);
if std::fs::File::open(&test_file).is_err() {
Expand Down
4 changes: 2 additions & 2 deletions xtask/codegen/src/promote_rule.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use case::CaseExt;
use biome_string_case::Case;
use fs_extra::dir::{create, move_dir, CopyOptions};
use fs_extra::file;
use fs_extra::file::move_file;
Expand Down Expand Up @@ -31,7 +31,7 @@ pub fn promote_rule(rule_name: &str, new_group: &str) {
)
}

let rule_name_snake = rule_name.to_snake();
let rule_name_snake = Case::Snake.convert(rule_name);

// look for the rule in the source code
let mut rule_path = None;
Expand Down

0 comments on commit d6f1f2b

Please sign in to comment.