useFilenamingConvention
诊断类别:lint/style/useFilenamingConvention
¥Diagnostic Category: lint/style/useFilenamingConvention
自从:v1.5.0
来源:
¥Since: v1.5.0
Sources:
-
¥Inspired from:
unicorn/filename-case
强制相对导入的文件扩展名。
¥Enforce naming conventions for JavaScript and TypeScript filenames.
强制 命名约定 有助于保持代码库的一致性。
¥Enforcing naming conventions helps to keep the codebase consistent.
文件名由两部分组成:名称和一组连续扩展。例如,my-filename.test.js
的名称为 my-filename
,并且有两个连续的扩展名:.test
和 .js
。
¥A filename consists of two parts: a name and a set of consecutive extension.
For instance, my-filename.test.js
has my-filename
as name, and two consecutive extensions: .test
and .js
.
文件名可以以点或加号开头,前缀和后缀为 _
下划线。例如,.filename.js
、+filename.js
、__filename__.js
,甚至 .__filename__.js
。
¥The filename 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
.
Sveltekit 和 Vike 使用在文件名前加加号的惯例。
¥The convention of prefixing a filename with a plus sign is used by Sveltekit and Vike.
此外,规则支持 Next.js、SolidStart、Nuxt 和 Astro 的动态路由语法。例如 [...slug].js
和 [[...slug]].js
是有效的文件名。
¥Also, the rule supports dynamic route syntaxes of Next.js, SolidStart, Nuxt, and Astro.
For example [...slug].js
and [[...slug]].js
are valid filenames.
默认情况下,规则确保文件名为 camelCase
、kebab-case
、snake_case
或等于文件中一个导出的名称。
¥By default, the rule ensures that the filename is either in camelCase
, kebab-case
, snake_case
,
or equal to the name of one export in the file.
忽略某些文件
Section titled 忽略某些文件¥Ignoring some files
有时你想完全忽略某些文件。Biome 忽略注释不能使用,因为该规则适用于文件名而不是文件内容。要忽略文件,你可以使用 overrides
。如果你想忽略 test
目录中的所有文件,则可以仅针对这些文件禁用规则:
¥Sometimes you want to completely ignore some files.
Biome ignore comments cannot be used because the rule applies on filenames not file contents.
To ignore files, you can use overrides
.
If you want to ignore all files in the test
directory, then you can disable the rule for those files only:
¥Options
规则提供了几个选项,详见以下小节。
¥The rule provides several options that are detailed in the following subsections.
strictCase
Section titled strictCase当此选项设置为 true
时,它禁止在 camelCase
和 PascalCase
中使用连续的大写字符。例如,当选项设置为 true
时,agentID
将抛出错误。此名称应重命名为 agentId
。
¥When this option is set to true
, it forbids consecutive uppercase characters in camelCase
and PascalCase
.
For instance, when the option is set to true
, agentID
will throw an error.
This name should be renamed to agentId
.
当选项设置为 false
时,允许连续的大写字符。agentID
非常有效。
¥When the option is set to false
, consecutive uppercase characters are allowed.
agentID
is so valid.
默认:true
¥Default: true
requireAscii
Section titled requireAscii当此选项设置为 true
时,它禁止包含非 ASCII 字符的名称。例如,当选项设置为 true
时,café
或 안녕하세요
将抛出错误。
¥When this option is set to true
, it forbids names that include non-ASCII characters.
For instance, when the option is set to true
, café
or 안녕하세요
will throw an error.
当选项设置为 false
时,名称可能包含非 ASCII 字符。café
和 안녕하세요
非常有效。
¥When the option is set to false
, a name may include non-ASCII characters.
café
and 안녕하세요
are so valid.
默认:false
¥Default: false
此选项将在 Biome 2.0 中默认启用。
¥This option will be turned on by default in Biome 2.0.
filenameCases
Section titled filenameCases默认情况下,规则强制文件名为 camelCase
、kebab-case
、snake_case
或等于文件中一个导出的名称。
¥By default, the rule enforces that the filename is either in camelCase
, kebab-case
, snake_case
, or equal to the name of one export in the file.
你可以通过设置 filenameCases
选项来强制执行更严格的约定。filenameCases
接受以下情况中的一组情况:camelCase
、kebab-case
、PascalCase
、snake_case
和 export
。
¥You can enforce a stricter convention by setting filenameCases
option.
filenameCases
accepts an array of cases among the following cases: camelCase
, kebab-case
, PascalCase
, snake_case
, and export
.
¥Related links