### Install from Sources Source: https://github.com/fe3dback/go-arch-lint/blob/master/README.md Instructions for installing the go-arch-lint tool directly from its Go module source. Requires Go 1.20 or later. ```bash go install github.com/fe3dback/go-arch-lint@latest ``` -------------------------------- ### Running from Project Directory Source: https://github.com/fe3dback/go-arch-lint/blob/master/README.md Demonstrates how to run the go-arch-lint command after installation, either by specifying the project path or by navigating into the project directory. ```bash go-arch-lint check --project-path ~/code/my-project # or cd ~/code/my-project go-arch-lint check ``` -------------------------------- ### Pre-Commit Hook Installation and Management Source: https://github.com/fe3dback/go-arch-lint/blob/master/README.md These shell commands are used to manage the pre-commit hooks after configuring them. `pre-commit autoupdate` fetches the latest versions of the hooks, and `pre-commit install` enables the hooks for the current repository. ```shell pre-commit autoupdate pre-commit install ``` -------------------------------- ### Docker Installation and Run Source: https://github.com/fe3dback/go-arch-lint/blob/master/README.md Provides instructions for running the go-arch-lint tool using Docker. It mounts the current project directory to the container and executes the 'check' command. ```bash docker run --rm -v ${PWD}:/app fe3dback/go-arch-lint:latest-stable-release check --project-path /app ``` -------------------------------- ### YAML Configuration Example Source: https://github.com/fe3dback/go-arch-lint/blob/master/README.md Defines project architecture components and their dependencies using a semantic YAML configuration. It specifies work directories, component definitions with wildcard matching, common components, and dependency rules (mayDependOn). ```yaml version: 3 workdir: internal components: handler: { in: handlers/* } # wildcard one level service: { in: services/** } # wildcard many levels repository: { in: domain/*/repository } # wildcard DDD repositories model: { in: models } # match exactly one package commonComponents: - models deps: handler: mayDependOn: - service service: mayDependOn: - repository ``` -------------------------------- ### Broken Code Example Source: https://github.com/fe3dback/go-arch-lint/blob/master/README.md Illustrates a common architectural violation where a repository is directly injected into a handler, bypassing the service layer. The linter identifies this as a bad flow. ```go func main() { // .. repository := booksRepository.NewRepository() handler := booksHandler.NewHandler( service, repository, // !!! ) // .. } ``` -------------------------------- ### Pre-Commit Configuration for go-arch-lint Source: https://github.com/fe3dback/go-arch-lint/blob/master/README.md This YAML configuration sets up go-arch-lint to run as pre-commit hooks. It includes hooks for checking architecture compliance and generating dependency graphs, with options to customize graph output. ```yaml repos: - repo: https://github.com/fe3dback/go-arch-lint rev: master hooks: - id: go-arch-lint-check - id: go-arch-lint-graph args: ['--include-vendors=true', '--out=go-arch-lint-graph.svg'] ``` -------------------------------- ### Run Tests Source: https://github.com/fe3dback/go-arch-lint/blob/master/CONTRIBUTING.md Executes unit and functional tests for the project. This command is crucial for ensuring code quality before pushing changes. ```bash make tests ``` -------------------------------- ### Map Project Files (List Mode) Source: https://github.com/fe3dback/go-arch-lint/blob/master/docs/README.md Displays the mapping of architecture files to source files in list mode. This shows each module and its associated project packages. ```bash go-arch-lint mapping ``` -------------------------------- ### Archfile Configuration Schema Source: https://github.com/fe3dback/go-arch-lint/blob/master/docs/syntax/README.md Defines the structure and types for the Archfile, used to configure go-arch-lint. It specifies rules for components, vendors, dependencies, and exclusions. ```APIDOC Archfile: version: int (required, schema version, latest: 3) workdir: str (optional, relative directory for analysis) allow: map (optional, global rules) . depOnAnyVendor: bool (optional, allow import any vendor code to any project file) . deepScan: bool (optional, use advanced AST code analyse, default true since v3+) . ignoreNotFoundComponents: bool (optional, ignore not found components, default false) exclude: []str (optional, list of directories to exclude from analysis) excludeFiles: []str (optional, regex rules for file names to exclude) components: map (required, component abstraction on go packages) . %name%: str (required, name of component) . . in: str, []str (required, one or more relative directory names, supports glob masking) vendors: map (optional, vendor libs) . %name%: str (required, name of vendor component) . . in: str, []str (required, one or more import paths of vendor libs, supports glob masking) commonComponents: []str (optional, list of components allowed for import in any code) commonVendors: []str (optional, list of vendors allowed for import in any code) deps: map (required, dependency rules) . %name%: str (required, name of component, must match 'components' section) . . anyVendorDeps: bool (optional, all component code can import any vendor code) . . anyProjectDeps: bool (optional, all component code can import any other project code) . . mayDependOn: []str (optional, list of components that can be imported in %name%) . . canUse: []str (optional, list of vendors that can be imported in %name%) . . deepScan: bool (optional, override of allow.deepScan for this component, default nil) Example: - [.go-arch-lint.yml](../../.go-arch-lint.yml) ``` -------------------------------- ### go-arch-lint CLI Usage Source: https://github.com/fe3dback/go-arch-lint/blob/master/README.md Details the command-line interface for the go-arch-lint tool, specifically the 'check' command. It outlines available flags for specifying the architecture file, maximum warnings, project path, and output types (ASCII, JSON). ```APIDOC Usage: go-arch-lint check [flags] Flags: --arch-file string arch file path (default ".go-arch-lint.yml") -h, --help help for check --max-warnings int max number of warnings to output (default 512) --project-path string absolute path to project directory (where '.go-arch-lint.yml' is located) (default "./") Global Flags: --json (alias for --output-type=json) --output-color use ANSI colors in terminal output (default true) --output-json-one-line format JSON as single line payload (without line breaks), only for json output type --output-type string type of command output, variants: [ascii, json] (default "default") ``` -------------------------------- ### Graph Generation Command Source: https://github.com/fe3dback/go-arch-lint/blob/master/README.md Command to generate a dependency graph of the project based on the architecture configuration. Refer to the documentation for detailed graph configuration options. ```bash go-arch-lint graph ``` -------------------------------- ### Go Arch Lint Graph CLI Source: https://github.com/fe3dback/go-arch-lint/blob/master/docs/graph/README.md Command-line interface for generating architectural graphs. Supports flow and DI graph types, focusing on specific components, and including vendor dependencies. ```APIDOC go-arch-lint graph [flags] Aliases: graph, g Flags: --arch-file string arch file path (default ".go-arch-lint.yml") --focus string render only specified component (should match component name exactly) -h, --help help for graph -r, --include-vendors include vendor dependencies (from "canUse" block)? --out string svg graph output file (default "./go-arch-lint-graph.svg") --project-path string absolute path to project directory (where '.go-arch-lint.yml' is located) (default "./") -t, --type string render graph type [flow,di] (default "flow") Usage Examples: # Generate a default flow graph go-arch-lint graph # Generate a flow graph focusing on the 'operations' component go-arch-lint graph --focus operations # Generate a flow graph including vendor dependencies go-arch-lint graph --include-vendors # Generate a dependency injection (DI) graph go-arch-lint graph --type di ``` -------------------------------- ### Map Project Files (JSON Output) Source: https://github.com/fe3dback/go-arch-lint/blob/master/docs/README.md Retrieves the project file mapping in JSON format using the `--json` option. This is useful for programmatic access and integration with other tools. ```bash go-arch-lint mapping --json ``` -------------------------------- ### Map Project Files (Grouped Mode) Source: https://github.com/fe3dback/go-arch-lint/blob/master/docs/README.md Displays the mapping of architecture files to source files, grouped by component. This provides a hierarchical view of project packages within components. ```bash go-arch-lint mapping --scheme grouped ``` -------------------------------- ### Generate JSON Schema Source: https://github.com/fe3dback/go-arch-lint/blob/master/docs/README.md Exports the JSON schema for architecture files using the `schema --version X` command. This schema is useful for auto-completion and validation in editors. ```bash go-arch-lint schema --version 3 ``` ```json {"$schema":"http://json-schema.org/draft-07/schema#","additionalProperties":false,"definitions":{"commonComponents":{"description":"All project packages ..."}}} ``` -------------------------------- ### Exit Status Codes Source: https://github.com/fe3dback/go-arch-lint/blob/master/README.md Explains the meaning of the exit status codes returned by the go-arch-lint tool. A status code of 0 indicates a correct architecture, while 1 signifies that warnings were found. ```APIDOC Exit Status: | Status Code | Description | |-------------|----------------------------------| | 0 | Project has correct architecture | | 1 | Found warnings | ``` -------------------------------- ### Update Functional Tests Source: https://github.com/fe3dback/go-arch-lint/blob/master/CONTRIBUTING.md Updates the functional test files when command outputs have changed. This is used to re-baseline tests after modifications. ```bash make tests-functional-update-ct ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.