Skip to content
Merged
7 changes: 7 additions & 0 deletions .changeset/funny-pans-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@biomejs/biome": patch
---

Added support for dollar-sign-prefixed filenames in the [`useFilenamingConvention`](https://biomejs.dev/linter/rules/use-filenaming-convention/) rule.

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.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ declare_lint_rule! {
///
/// The rule supports the following exceptions:
///
/// - The name of the file can start with a dot or a plus sign, be prefixed and suffixed by underscores `_`.
/// For example, `.filename.js`, `+filename.js`, `__filename__.js`, or even `.__filename__.js`.
/// - The name of the file can start with a dot, a plus sign, or a dollar sign, be prefixed and suffixed by underscores `_`.
/// For example, `.filename.js`, `+filename.js`, `$filename.js`, `__filename__.js`, or even `.__filename__.js`.
///
/// 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).
/// - 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).
/// - 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.
///
/// - 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).
/// For example `[...slug].js` and `[[...slug]].js` are valid filenames.
///
/// Note that if you specify the `match' option, the previous exceptions will no longer be handled.
/// Note that if you specify the `match` option, the previous exceptions will no longer be handled.
///
/// ## Ignoring some files
///
Expand Down Expand Up @@ -217,7 +218,9 @@ impl Rule for UseFilenamingConvention {
//
// Support [Sveltekit](https://kit.svelte.dev/docs/routing#page) and
// [Vike](https://vike.dev/route) routing conventions where page name starts with `+`.
let file_name = if matches!(first_char, b'.' | b'+') {
//
// Support filenames starting with `$`.
let file_name = if matches!(first_char, b'.' | b'+' | b'$') {
&file_name[1..]
} else {
file_name
Expand Down Expand Up @@ -306,6 +309,8 @@ impl Rule for UseFilenamingConvention {
split.next()?
} else if let Some(stripped_name) = name.strip_prefix('+') {
stripped_name
} else if let Some(stripped_name) = name.strip_prefix('$') {
stripped_name
} else {
name
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* should generate diagnostics */

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: $INVALID.js
---
# Input
```js
/* should generate diagnostics */
```

# Diagnostics
```
$INVALID.js lint/style/useFilenamingConvention ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
i The filename should be in camelCase or kebab-case or snake_case or equal to the name of an export.
i The filename could be renamed to one of the following names:
$invalid.js
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* should not generate diagnostics */

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: $dollarValid.js
---
# Input
```js
/* should not generate diagnostics */
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* should not generate diagnostics */

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: crates/biome_js_analyze/tests/spec_tests.rs
expression: $dollar_snake.js
---
# Input
```js
/* should not generate diagnostics */
```