Skip to content

Commit

Permalink
fix(useFilenamingConvention): don't suggest names with disallowed case (
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos authored Sep 17, 2024
1 parent 1fe6f78 commit deb062e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

#### Bug fixes

- [useFilenamingConvention](https://biomejs.dev/linter/rules/use-filenaming-convention) no longer suggests names with a disallowed case. Contributed by @Conaclos

- [useSemanticElements](https://biomejs.dev/linter/rules/use-semantic-elements/) now ignores `alert` and `alertdialog` roles ([3858](https://github.com/biomejs/biome/issues/3858)). Contributed by @Conaclos

- [noUndeclaredDependencies](https://biomejs.dev/linter/rules/no-undeclared-dependencies/) now ignores `@/` imports and recognizes type imports from Definitely Typed and `bun` imports. Contributed by @Conaclos
Expand Down
5 changes: 1 addition & 4 deletions crates/biome_aria_metadata/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,7 @@ 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(
&Case::Pascal.convert(&property.replace('-', "_")),
Span::call_site(),
);
let name = Ident::new(&Case::Pascal.convert(property), Span::call_site());
let property = Literal::string(property);
from_enum_metadata.push(quote! {
#enum_name::#name => #property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,31 @@ impl Rule for UseFilenamingConvention {
}
let suggested_filenames = allowed_cases
.into_iter()
.map(|case| file_name.replacen(trimmed_name, &case.convert(trimmed_name), 1))
.filter_map(|case| {
let new_trimmed_name = case.convert(trimmed_name);
// Filter out names that have not an allowed case
if allowed_cases.contains(Case::identify(&new_trimmed_name, options.strict_case)) {
Some(file_name.replacen(trimmed_name, &new_trimmed_name, 1))
} else {
None
}
})
// Deduplicate suggestions
.collect::<FxHashSet<_>>()
.into_iter()
.collect::<SmallVec<[_; 3]>>()
.join("\n");
Some(RuleDiagnostic::new(
let diagnostic = RuleDiagnostic::new(
rule_category!(),
None as Option<TextRange>,
markup! {
"The filename"{trimmed_info}" should be in "<Emphasis>{allowed_case_names}</Emphasis>"."
},
).note(markup! {
);
if suggested_filenames.is_empty() {
return Some(diagnostic);
}
Some(diagnostic.note(markup! {
"The filename could be renamed to one of the following names:\n"{suggested_filenames}
}))
},
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: 0_start_with_digit.ts
---
# Input
```ts

```

# Diagnostics
```
0_start_with_digit.ts lint/style/useFilenamingConvention ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The filename should be in camelCase or kebab-case or snake_case or equal to the name of an export.
```

0 comments on commit deb062e

Please sign in to comment.