structure
Layout rules for code: import rules for Python and Swift, and the files that no import rule covers. Level all adds lone files, pass-through folders, shared name prefixes, file and folder clashes, long files, trivial functions, private functions below public ones, bare Swift do blocks, and environment reads outside the environment readers.
Selected when
Section titled “Selected when”Always.
Checks
Section titled “Checks”Reports every block of code copied between files, naming both places.
Runs at the push stage, only at the all level, once per scope.
A fix in one place leaves the copied block broken in the other.
What to do
Section titled “What to do”Move the shared block into one function both callers use.
Example
Section titled “Example”Two files with the same long block of code report that block. Move it into one function, and call it from both places.
Turn it off
Section titled “Turn it off”gspot ignore structure/jscpd --paths "<path>" --reason "<why>"import-rules
Section titled “import-rules”Applies [[import_rule]] to Python and Swift imports and to the types that Swift files name, and reports code files that no import rule covers. ESLint applies the rules to JavaScript and TypeScript imports.
Runs at the commit stage, once per scope. It skips until you set import_rule.
An import across the layers, or a file outside every rule, breaks the structure that the rules describe.
What to do
Section titled “What to do”Move the code into a rule that may import it, move that rule above, list the rule in can_import, or add the file to the paths of a rule.
Example
Section titled “Example”With [[import_rule]] records, a Python file under app/ that imports storage.models from a rule it may not import reports refused-import. A code file that no rule covers reports uncovered-file.
Lint rules
Section titled “Lint rules”| Rule | What it checks | What to do |
|---|---|---|
refused-import |
A Python or Swift file imports only from its own import rule and from those that can_import lists, or every rule above it when the rule has no can_import. A Swift file also names only the types of those rules, because files of one target use each other with no import. |
Move the code into a layer that the file may import, or move the importing code up a layer. |
uncovered-file |
Each code file matches the paths of an [[import_rule]] record. |
Extend the paths of the import rule that the file belongs to. |
Turn it off
Section titled “Turn it off”gspot ignore structure/import-rules --paths "<path>" --reason "<why>"gspot ignore structure/import-rules --rule refused-import --reason "<why>"empty-folders
Section titled “empty-folders”Finds a folder that holds no files, directly or through its subfolders, and a folder that holds only .gitkeep or .keep.
Runs at the commit stage, once for the repository.
An empty folder promises code that is not there, and Git does not keep it, so it exists on one machine only.
What to do
Section titled “What to do”Delete the folder.
Example
Section titled “Example”An empty src/old/, or a src/old/ that holds only an empty src/old/tmp/, reports empty-folder, and so does a logs/ that holds only .gitkeep. Delete the folder.
Turn it off
Section titled “Turn it off”gspot ignore structure/empty-folders --paths "<path>" --reason "<why>"lone-files
Section titled “lone-files”Finds a folder that holds one code file and nothing else.
Runs at the commit stage, only at the all level, once per scope.
A folder with one file adds a level to every import path and groups nothing.
What to do
Section titled “What to do”Move the file up beside its neighbors.
Example
Section titled “Example”With TypeScript at level all, a feature/only.ts alone in its folder reports lone-file. Move it up beside related code, and update its imports.
Turn it off
Section titled “Turn it off”gspot ignore structure/lone-files --paths "<path>" --reason "<why>"pass-through-folders
Section titled “pass-through-folders”Finds a folder whose only entry is one folder.
Runs at the commit stage, only at the all level, once per scope.
A folder that only holds one folder adds a level to every path and groups nothing.
What to do
Section titled “What to do”Move the inner folder up one level.
Example
Section titled “Example”At level all, a src/models/ whose only entry is src/models/user/ reports pass-through-folder. Move user/ up to src/user/, and update its imports.
Turn it off
Section titled “Turn it off”gspot ignore structure/pass-through-folders --paths "<path>" --reason "<why>"shared-prefixes
Section titled “shared-prefixes”Finds sibling files that share a name prefix, such as asset-card, asset-list, and asset-row.
Runs at the commit stage, only at the all level, once per scope.
Sibling files with one prefix split a single concept by suffix, and a folder of that name groups them.
What to do
Section titled “What to do”Move the files into a folder named after the shared prefix, or raise limits.min_shared_prefix_files with a reason.
Example
Section titled “Example”Sibling files asset-card.ts, asset-list.ts, and asset-row.ts share a repeated prefix. Move them into asset/ with names card.ts, list.ts, and row.ts, then update imports.
Turn it off
Section titled “Turn it off”gspot ignore structure/shared-prefixes --paths "<path>" --reason "<why>"file-folder-clashes
Section titled “file-folder-clashes”Finds a file and a folder with the same name, apart from the extension, in the same place, such as turn.ts beside turn/.
Runs at the commit stage, only at the all level, once per scope.
An import of ./turn names both, and a reader cannot tell which one loads.
What to do
Section titled “What to do”Rename the file or the folder so their names differ.
Example
Section titled “Example”A report.ts beside a report/ folder reports a clash. Rename one after its job, and update each reference.
Turn it off
Section titled “Turn it off”gspot ignore structure/file-folder-clashes --paths "<path>" --reason "<why>"long-files
Section titled “long-files”Checks the code line count of each Python, SQL and shell file against limits.<language>.max_file_lines. ESLint and SwiftLint count the other languages.
Runs at the commit stage, only at the all level.
A long file hides independent responsibilities from the reader.
What to do
Section titled “What to do”Split the file by responsibility, or raise limits.<language>.max_file_lines with a reason.
Example
Section titled “Example”A Python file over its line limit reports the count. Split it by responsibility.
Turn it off
Section titled “Turn it off”gspot ignore structure/long-files --paths "<path>" --reason "<why>"trivial-functions
Section titled “trivial-functions”Finds Python, Swift, and Bash functions at or under limits.trivial_function_statements that at most one place calls, exported JavaScript and TypeScript functions of that size that one place calls, and files that hold only imports, re-exports, and aliases.
Runs at the commit stage, only at the all level.
A function of one statement that one place calls makes the reader jump for nothing.
What to do
Section titled “What to do”Inline the function at its call and delete it, or import from the module that defines the code and delete the forwarding file.
Example
Section titled “Example”A Bash function that only calls another, and that one place calls, reports a finding. Inline the call at that place, and delete the wrapper.
Lint rules
Section titled “Lint rules”| Rule | What it checks | What to do |
|---|---|---|
trivial-function |
A named function has limits.<language>.trivial_function_statements statements or fewer, and one place in the scope calls it at most. |
Move the body into its caller, and delete the function. When a framework calls it by name, ignore the finding. |
trivial-file |
A file holds only imports, re-exports, and aliases, and no code of its own. | Point each import at the module that defines the code, then delete the file. |
Turn it off
Section titled “Turn it off”gspot ignore structure/trivial-functions --paths "<path>" --reason "<why>"gspot ignore structure/trivial-functions --rule trivial-function --reason "<why>"function-order
Section titled “function-order”Finds a private top-level function below a public one in Python, Swift, JavaScript, and TypeScript.
Runs at the commit stage, only at the all level.
When each private function sits above the public functions, a reader finds a helper next to the code that uses it.
What to do
Section titled “What to do”Move each private function above the public function that calls it.
Example
Section titled “Example”A TypeScript file whose function parseRow sits below export function loadRows reports private-below-public. Move parseRow above loadRows.
Turn it off
Section titled “Turn it off”gspot ignore structure/function-order --paths "<path>" --reason "<why>"bare-blocks
Section titled “bare-blocks”Finds Swift do blocks without catch. ESLint reports the bare blocks of JavaScript and TypeScript.
Runs at the commit stage, only at the all level.
A block that only groups statements hides a step that a named function would explain.
What to do
Section titled “What to do”Move the statements into a function named after their step, or remove the do and keep the statements.
Example
Section titled “Example”A Swift do { ... } without catch reports bare-block. Move its statements into a function named after their step, or remove the do.
Turn it off
Section titled “Turn it off”gspot ignore structure/bare-blocks --paths "<path>" --reason "<why>"environment-readers
Section titled “environment-readers”Finds environment reads outside the files listed in structure.environment_readers.
Runs at the commit stage, only at the all level, once per scope. It skips until you set structure.environment_readers.
Environment reads spread through the code hide which settings a program needs.
What to do
Section titled “What to do”Move the environment read into a file listed in structure.environment_readers, then pass the value to callers.
Example
Section titled “Example”A Python file that uses os.environ outside structure.environment_readers reports a finding. Move that access into an environment reader, and pass the value to callers.
Turn it off
Section titled “Turn it off”gspot ignore structure/environment-readers --paths "<path>" --reason "<why>"Settings
Section titled “Settings”| Setting | What it sets |
|---|---|
limits.max_file_lines |
The most lines one file may have, not counting blank lines and comment-only lines. |
limits.max_function_lines |
The most lines one function may have. |
limits.max_function_parameters |
The most parameters one function may take. |
limits.max_function_statements |
The most statements one function may have. |
limits.max_block_nesting |
How deep blocks may nest inside one function. |
limits.max_callback_nesting |
How deep callbacks may nest. |
limits.max_cognitive_complexity |
The highest cognitive score one function may have; the score grows as the function gets harder to follow. |
limits.max_cyclomatic_complexity |
The most paths that may run through one function. |
limits.max_function_branches |
The most branches one function may have. |
limits.max_function_returns |
The most return statements one function may have. |
limits.max_function_assignments |
The most variable assignments one shell function may make. |
limits.max_closure_lines |
The most lines one Swift closure may have. |
limits.max_type_lines |
The most lines one Swift type body may have. |
limits.max_index_exports |
The most re-exports one index file may hold. |
limits.trivial_function_statements |
A function with this many statements or fewer, nested functions included, is reported when at most one place calls it. |
limits.min_shared_prefix_files |
The number of siblings sharing a name prefix that makes a finding. |
structure.reexports |
Where re-exports may go: none, or an index file that re-exports other files. |
structure.min_duplicate_lines |
The fewest lines a copied block has before it counts. |
structure.min_duplicate_tokens |
The fewest tokens a copied block has before it counts. |
structure.environment_readers |
The files that may read environment variables; other files get the values passed in. Empty turns the check off. |
import_rule |
Code may import its own files and the files of every import rule listed above it, never below. can_import replaces the rules above with an exact list. When import rules exist, every code file belongs to one, apart from tests, tool settings files, scripts, and generated files. |
Tools and versions
Section titled “Tools and versions”| Tool | Version |
|---|---|
| jscpd | 5.4.1 |
Files gspot writes
Section titled “Files gspot writes”.gspot/configurations/structure/jscpd.json