Skip to content

Code structure rules

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.

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.

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.

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.

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.

Import from the leaf module directly.

The import import { a } from "./index.js"; reports index. If a.js declares the value, use import { a } from "./a.js";.

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.

Export the source value under its own name, or import the source where the renamed constant was used.

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 };.

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.

Rename the export to the name that the file needs, or use the exported name in the file.

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.

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.

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.

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.

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.

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.

Follow the message of the finding, which names the shape to write instead.

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.

Option 1: List.