vet
supports path exclusions for scenarios where a directory is the scan target but certain path patterns within the directory should be excluded from the scan. This feature is available only for the scan
command and helps optimize scan performance and focus on relevant code.
Basic Usage
Exclude a single path pattern during directory scanning:
vet scan -D /path/to/target --exclude 'docs/*'
Multiple Exclusions
Specify multiple path patterns for exclusion:
vet scan -D /path/to/target \
--exclude 'docs/*' \
--exclude 'sub/dir/path/*' \
--exclude '*.test.js'
The exclusion pattern matches any path, directory, or file. Internally, it uses Go’s regexp.MatchString function.
Common Exclusion Patterns
Documentation and Build Artifacts
vet scan -D . \
--exclude 'docs/*' \
--exclude 'build/*' \
--exclude 'dist/*' \
--exclude 'target/*' \
--exclude '*.generated.*'
Test Files and Directories
vet scan -D . \
--exclude 'test/*' \
--exclude 'tests/*' \
--exclude '*_test.go' \
--exclude '*.test.js' \
--exclude 'spec/*'
Version Control and Dependencies
vet scan -D . \
--exclude '.git/*' \
--exclude 'node_modules/*' \
--exclude 'vendor/*' \
--exclude '.venv/*' \
--exclude '__pycache__/*'
vet scan -D . \
--exclude '.idea/*' \
--exclude '.vscode/*' \
--exclude '*.log' \
--exclude 'tmp/*' \
--exclude 'temp/*'
Advanced Pattern Examples
File Extension Exclusions
# Exclude specific file types
vet scan -D . \
--exclude '.*\.md$' \
--exclude '.*\.txt$' \
--exclude '.*\.png$' \
--exclude '.*\.jpg$'
Environment-Specific Exclusions
# Development environment
vet scan -D . \
--exclude 'dev-tools/*' \
--exclude 'local-config/*' \
--exclude '.*\.dev\..*'
# Production build
vet scan -D . \
--exclude 'test/*' \
--exclude 'examples/*' \
--exclude 'dev-dependencies/*'
Complex Pattern Matching
# Exclude multiple similar patterns
vet scan -D . \
--exclude '.*/test/.*' \
--exclude '.*/tests/.*' \
--exclude '.*/spec/.*' \
--exclude '.*/mocks/.*'
Use Cases
Performance Optimization Skip large directories that don’t contain relevant package manifests
Test Environment Exclusion Focus on production dependencies by excluding test files
Build Artifact Filtering Avoid scanning generated files and build outputs
Monorepo Management Selectively scan specific parts of large monorepos
Makefile Integration
# Makefile with different scan targets
.PHONY : scan-prod scan-dev scan-all
scan-prod :
vet scan -D . \
--exclude 'test/*' \
--exclude 'dev-tools/*' \
--exclude 'docs/*' \
--report-json production-scan.json
scan-dev :
vet scan -D . \
--exclude 'node_modules/*' \
--exclude '.git/*' \
--report-json development-scan.json
scan-all :
vet scan -D . \
--exclude '.git/*' \
--report-json complete-scan.json