Skip to content

Commit 182ecdc

Browse files
feat(use_filenaming_convention): add support for $ prefix (#8007)
Co-authored-by: Victorien Elvinger <[email protected]>
1 parent 0dec346 commit 182ecdc

8 files changed

Lines changed: 65 additions & 5 deletions

File tree

.changeset/funny-pans-act.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Added support for dollar-sign-prefixed filenames in the [`useFilenamingConvention`](https://biomejs.dev/linter/rules/use-filenaming-convention/) rule.
6+
7+
Biome now allows filenames starting with the dollar-sign (e.g. `$postId.tsx`) by default to support naming conventions used by frameworks such as [TanStack Start](https://tanstack.com/start/latest/docs/framework/react/guide/routing#file-based-routing) for file-based-routing.

crates/biome_js_analyze/src/lint/style/use_filenaming_convention.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ declare_lint_rule! {
2424
///
2525
/// The rule supports the following exceptions:
2626
///
27-
/// - The name of the file can start with a dot or a plus sign, be prefixed and suffixed by underscores `_`.
28-
/// For example, `.filename.js`, `+filename.js`, `__filename__.js`, or even `.__filename__.js`.
27+
/// - The name of the file can start with a dot, a plus sign, or a dollar sign, be prefixed and suffixed by underscores `_`.
28+
/// For example, `.filename.js`, `+filename.js`, `$filename.js`, `__filename__.js`, or even `.__filename__.js`.
2929
///
30-
/// The convention of prefixing a filename with a plus sign is used by [Sveltekit](https://kit.svelte.dev/docs/routing#page) and [Vike](https://vike.dev/route).
30+
/// - The convention of prefixing a filename with a plus sign is used by [Sveltekit](https://kit.svelte.dev/docs/routing#page) and [Vike](https://vike.dev/route).
31+
/// - The convention of prefixing a filename with a dollar sign is used by [TanStack Start](https://tanstack.com/start/latest/docs/framework/react/guide/routing#file-based-routing) for file-based routing.
3132
///
3233
/// - Also, the rule supports dynamic route syntaxes of [Next.js](https://nextjs.org/docs/pages/building-your-application/routing/dynamic-routes#catch-all-segments), [SolidStart](https://docs.solidjs.com/solid-start/building-your-application/routing#renaming-index), [Nuxt](https://nuxt.com/docs/guide/directory-structure/server#catch-all-route), and [Astro](https://docs.astro.build/en/guides/routing/#rest-parameters).
3334
/// For example `[...slug].js` and `[[...slug]].js` are valid filenames.
3435
///
35-
/// Note that if you specify the `match' option, the previous exceptions will no longer be handled.
36+
/// Note that if you specify the `match` option, the previous exceptions will no longer be handled.
3637
///
3738
/// ## Ignoring some files
3839
///
@@ -217,7 +218,9 @@ impl Rule for UseFilenamingConvention {
217218
//
218219
// Support [Sveltekit](https://kit.svelte.dev/docs/routing#page) and
219220
// [Vike](https://vike.dev/route) routing conventions where page name starts with `+`.
220-
let file_name = if matches!(first_char, b'.' | b'+') {
221+
//
222+
// Support filenames starting with `$`.
223+
let file_name = if matches!(first_char, b'.' | b'+' | b'$') {
221224
&file_name[1..]
222225
} else {
223226
file_name
@@ -306,6 +309,8 @@ impl Rule for UseFilenamingConvention {
306309
split.next()?
307310
} else if let Some(stripped_name) = name.strip_prefix('+') {
308311
stripped_name
312+
} else if let Some(stripped_name) = name.strip_prefix('$') {
313+
stripped_name
309314
} else {
310315
name
311316
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* should generate diagnostics */
2+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
source: crates/biome_js_analyze/tests/spec_tests.rs
3+
expression: $INVALID.js
4+
---
5+
# Input
6+
```js
7+
/* should generate diagnostics */
8+
9+
10+
```
11+
12+
# Diagnostics
13+
```
14+
$INVALID.js lint/style/useFilenamingConvention ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
15+
16+
i The filename should be in camelCase or kebab-case or snake_case or equal to the name of an export.
17+
18+
i The filename could be renamed to one of the following names:
19+
$invalid.js
20+
21+
22+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* should not generate diagnostics */
2+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: crates/biome_js_analyze/tests/spec_tests.rs
3+
expression: $dollarValid.js
4+
---
5+
# Input
6+
```js
7+
/* should not generate diagnostics */
8+
9+
10+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* should not generate diagnostics */
2+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: crates/biome_js_analyze/tests/spec_tests.rs
3+
expression: $dollar_snake.js
4+
---
5+
# Input
6+
```js
7+
/* should not generate diagnostics */
8+
9+
10+
```

0 commit comments

Comments
 (0)