Code structure rules
import-boundaries
Section titled “import-boundaries”Finds relative imports that leave the nearest boundary folder, every second-level folder such as src/cart by default. The folders option names other boundaries.
On in the all config. eslint --fix fixes it.
Relative paths between folders couple separate parts of a project to the tree shape.
What to do
Section titled “What to do”Keep relative imports within the selected folder. eslint --fix uses a configured alias when one exists, and keeps a query such as ?raw. Otherwise, add an alias for the target in package.json imports, or in tsconfig paths when a bundler resolves them, run gspot install, and import through it. Or move the shared code into a package that both folders depend on, and import its package name.
Example
Section titled “Example”With @/* mapped to src/*, import { a } from "../turn/a.js"; in src/other/b.ts reports alias. Correct the import to import { a } from "@/turn/a.js";. With folders api and supabase, a relative import from api into supabase reports escape.
Options
Section titled “Options”| Option | Type | Default | What it does |
|---|---|---|---|
folders |
List | ["*/*"] |
Boundary folders or folder globs. The nearest matching ancestor owns each file. |
aliases |
Table | {} |
Import alias patterns mapped to repository paths, as in tsconfig paths and package.json imports: @/* to src/* or ./src/*, or an exact key to an exact path. |
externals |
List | [] |
Import specifiers, or globs of them, that the runtime provides, such as ../../scripts/app.js in a host application. |
no-index-imports
Section titled “no-index-imports”Finds an import, re-export, require, or test mock path that names an index file instead of the module that declares the value.
On in the all config.
An import that names an index file hides the module that declares the value.
What to do
Section titled “What to do”Import from the leaf module directly.
Example
Section titled “Example”The import import { a } from "./index.js"; reports index. If a.js declares the value, use import { a } from "./a.js";.
no-renamed-exports
Section titled “no-renamed-exports”Finds an export that only renames another value, such as an exported constant set to another binding, or an export specifier written a as b.
On in the all config.
Two names for one value split every search and every reader in two.
What to do
Section titled “What to do”Export the source value under its own name, or import the source where the renamed constant was used.
Example
Section titled “Example”The declaration import { b } from "./owner"; export const a = b; reports renamed, and so do export { b as a };, export const { b: a } = owner;, and import { b as a } from "./owner"; export { a };. Remove a and update its consumers to use b from its owner. A declaration that owns a value, such as export const a = 1;, does not report this finding, and neither does export { main as default };.
no-renamed-imports
Section titled “no-renamed-imports”Reports an import that renames a value of a module of the repository, such as import { a as b } from a relative path, a # subpath import, or a workspace package, when nothing else in the file is named a.
On in the all config.
Two names for one value split every search and every reader in two.
What to do
Section titled “What to do”Rename the export to the name that the file needs, or use the exported name in the file.
Example
Section titled “Example”import { RULES as NAMING_RULES } from '#cli/config/naming.ts'; reports renamed. Export the value as NAMING_RULES. import { stringify as stringifyToml } from '@decimalturn/toml-patch'; does not report this finding, because another project owns the package, and neither does an alias in a file that already holds the bare name.
no-trivial-files
Section titled “no-trivial-files”Reports each export … from, and a file whose other top-level statements are only imports and aliases. With reexports: "index-only", an index file may re-export up to indexExports names.
On in the all config.
A file that only forwards to another module adds a step to every import and hides where the code lives.
What to do
Section titled “What to do”Import re-exported values from the modules that define them, and use the original name of each alias. Then delete the forwarding file or the re-export. Split an index file that exports too many names.
Example
Section titled “Example”A file containing only import { value } from "./owner"; export { value }; reports trivial. Change consumers to import directly from owner, then delete the forwarding file. export { value } from "./owner"; reports reexport once, in any file. With reexports: "index-only", a file named index may re-export, and reports barrel when it exports more names than it declares and more than indexExports. A file that the nearest package.json names in exports, main, or bin passes, because other packages import it by that path.
Options
Section titled “Options”| Option | Type | Default | What it does |
|---|---|---|---|
reexports |
Text | "none" |
Where export … from may go: none reports each one, and index-only allows them in files named index. |
indexExports |
Whole number | 20 |
With index-only, the most names an index file may export when it exports more names than it declares. |
forwardingFiles |
List | [] |
Globs of files that may only forward, such as route files that a framework discovers by name. They still report each re-export. Paths are relative to settings.gspot.root, or to the working folder of ESLint. |
restricted-syntax
Section titled “restricted-syntax”Reports each node that an option selector matches, with the message of that option, like the core no-restricted-syntax. Each option can name the files it applies to and the ignores it skips.
On in the recommended and all configs.
A pattern that a project bans should report everywhere it applies, with the reason in the message.
What to do
Section titled “What to do”Follow the message of the finding, which names the shape to write instead.
Example
Section titled “Example”With the option { selector: "TSEnumDeclaration", message: "Use a literal union instead of an enum." }, enum Color { Red } reports restricted with that message. With files: ["src/**"], a file outside src/ does not report it.
Options
Section titled “Options”Option 1: List.