noBarrelFile
¥Summary
-
规则生效日期:
v1.6.0¥Rule available since:
v1.6.0 -
诊断类别:
lint/performance/noBarrelFile¥Diagnostic Category:
lint/performance/noBarrelFile -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
-
灵感来自
barrel-files/avoid-barrel-files¥Inspired from
barrel-files/avoid-barrel-files
-
¥How to configure
{ "linter": { "rules": { "performance": { "noBarrelFile": "error" } } }}¥Description
禁止使用 barrel 文件。
¥Disallow the use of barrel file.
桶文件是重新导出目录中其他文件的所有导出的文件。此结构导致许多模块不必要地加载,严重影响大型应用的性能。此外,它使代码库复杂化,使得导航和理解项目的依赖图变得困难。此规则忽略 .d.ts 文件和仅类型导出。
¥A barrel file is a file that re-exports all of the exports from other files in a directory. This structure results in the unnecessary loading of many modules, significantly impacting performance in large-scale applications. Additionally, it complicates the codebase, making it difficult to navigate and understand the project’s dependency graph. This rule ignores .d.ts files and type-only exports.
有关更详细的说明,请查看 https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7/
¥For a more detailed explanation, check out https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7/
¥Examples
¥Invalid
export * from "foo";export * from "bar";code-block.js:1:1 lint/performance/noBarrelFile ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Avoid barrel files, they slow down performance, and cause large module graphs with modules that go unused.
> 1 │ export * from “foo”;
│ ^^^^^^^^^^^^^^^^^^^^
2 │ export * from “bar”;
3 │
ℹ Check this thorough explanation to better understand the context.
export { foo } from "foo";export { bar } from "bar";code-block.js:1:1 lint/performance/noBarrelFile ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Avoid barrel files, they slow down performance, and cause large module graphs with modules that go unused.
> 1 │ export { foo } from “foo”;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │ export { bar } from “bar”;
3 │
ℹ Check this thorough explanation to better understand the context.
export { default as module1 } from "./module1";code-block.js:1:1 lint/performance/noBarrelFile ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Avoid barrel files, they slow down performance, and cause large module graphs with modules that go unused.
> 1 │ export { default as module1 } from “./module1”;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Check this thorough explanation to better understand the context.
¥Valid
export type * from "foo";export type { foo } from "foo";¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号