oxc/no-barrel-file Restriction
Qué hace
Prohíbe el uso de barrel files where the file contains export * statements, and the total number of modules exceed a threshold.
The default threshold is 100.
¿Por qué es problemático?
Barrel files that re-export many modules can significantly slow down applications and bundlers. When a barrel file exports a large number of modules, importing from it forces the runtime or bundler to process all the exported modules, even if only a few are actually used. This leads to slower startup times and larger bundle sizes.
References:
- https://github.com/thepassle/eslint-plugin-barrel-files
- https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7
Ejemplos
Invalid:
export * from "foo"; // where `foo` loads a subtree of 100 modules
import * as ns from "foo"; // where `foo` loads a subtree of 100 modulesValid:
export { foo } from "foo";Configuración
Esta regla acepta un objeto de configuración con las siguientes propiedades:
threshold
tipo: integer
predeterminado: 100
The maximum number of modules that can be re-exported via export * before the rule is triggered.
Cómo usarla
To enable this rule using the config file or in the CLI, you can use:
{
"rules": {
"oxc/no-barrel-file": "error"
}
}import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"oxc/no-barrel-file": "error",
},
});oxlint --deny oxc/no-barrel-fileVersión
Esta regla se añadió en v0.3.0.