| name | ameba-configuration |
| user-invocable | false |
| description | Use when configuring Ameba rules and settings for Crystal projects including .ameba.yml setup, rule management, severity levels, and code quality enforcement. |
| allowed-tools | ["Bash","Read"] |
Ameba Configuration
Configure Ameba, the static code analysis tool for Crystal, to enforce consistent code style and catch code smells in your Crystal projects.
Understanding Ameba
Ameba is a static code analysis tool for the Crystal programming language that:
- Enforces consistent Crystal code style
- Catches code smells and wrong code constructions
- Provides configurable rules organized into categories
- Supports inline disabling of rules
- Offers auto-correction for many issues
- Integrates seamlessly with Crystal development workflows
Core Configuration File: .ameba.yml
Generating Default Configuration
ameba --gen-config
Basic Configuration Structure
Globs:
- "**/*.cr"
- "**/*.ecr"
- "!lib"
Excluded:
- src/legacy/**
- spec/fixtures/**
Lint/UnusedArgument:
Enabled: true
Severity: Warning
Style/RedundantReturn:
Enabled: true
Severity: Convention
Performance/AnyInsteadOfEmpty:
Enabled: true
Severity: Warning
Source File Configuration
Globs: Defining What to Analyze
Globs:
- "**/*.cr"
- "**/*.ecr"
- "!lib/**"
- "!vendor/**"
Excluded: Fine-Grained Exclusions
Excluded:
- src/compiler/**
- src/legacy/**
- spec/fixtures/**
- db/migrations/**
Globs:
- "**/*.cr"
- "!lib"
Excluded:
- src/external/generated/**
- src/legacy/**
- spec/support/fixtures/**
Source Configuration Examples
Globs:
- "src/**/*.cr"
- "spec/**/*.cr"
- "!lib"
Excluded:
- src/assets/**
- spec/fixtures/**
Globs:
- "src/**/*.cr"
- "spec/**/*.cr"
- "examples/**/*.cr"
- "!lib"
Excluded:
- spec/support/**
Globs:
- "apps/**/src/**/*.cr"
- "apps/**/spec/**/*.cr"
- "packages/**/src/**/*.cr"
- "!lib"
- "!**/node_modules/**"
Excluded:
- apps/legacy/**
Rule Categories
Lint Rules (Code Correctness)
Lint rules catch potential bugs and incorrect code:
Lint/UnusedArgument:
Enabled: true
Severity: Warning
Lint/UselessAssign:
Enabled: true
Severity: Warning
Lint/ShadowingOuterLocalVar:
Enabled: true
Severity: Warning
Lint/UnreachableCode:
Enabled: true
Severity: Error
Lint/Syntax:
Enabled: true
Severity: Error
Lint/EmptyBlock:
Enabled: true
Severity: Warning
ExcludeEmptyBlocks: false
Lint/DebuggerStatement:
Enabled: true
Severity: Warning
Style Rules (Code Conventions)
Style rules enforce Crystal code conventions:
Style/ConstantNames:
Enabled: true
Severity: Convention
Style/MethodNames:
Enabled: true
Severity: Convention
Style/TypeNames:
Enabled: true
Severity: Convention
Style/PredicateName:
Enabled: true
Severity: Convention
Style/RedundantReturn:
Enabled: true
Severity: Convention
AllowMultipleReturnValues: true
Style/RedundantBegin:
Enabled: true
Severity: Convention
Style/LargeNumbers:
Enabled: true
Severity: Convention
IntMinDigits:
Performance Rules
Performance rules identify inefficient code patterns:
Performance/AnyInsteadOfEmpty:
Enabled: true
Severity: Warning
FilterFirstNegativeCondition: true
Performance/SizeAfterFilter:
Enabled: true
Severity: Warning
FilterNames: [select, reject]
Performance/CompactAfterMap:
Enabled: true
Severity: Warning
Performance/FlattenAfterMap:
Enabled: true
Severity: Warning
Rule Configuration Options
Per-Rule Configuration
Style/LargeNumbers:
Enabled: true
Style/RedundantReturn:
Enabled: true
Severity: Warning
Style/LargeNumbers:
Enabled: true
Severity: Convention
IntMinDigits: 5
Lint/UnusedArgument:
Enabled: true
IgnoreTypeDeclarations: false
IgnoreParameterNames: []
Style/RedundantBegin:
Enabled: true
Excluded:
- src/server/processor.cr
- src/server/api.cr
Advanced Rule Configuration Examples
Lint/UselessAssign:
Enabled: true
Severity: Error
Style/RedundantReturn:
Enabled: true
Severity: Convention
AllowMultipleReturnValues: true
Lint/UnusedArgument:
Enabled: true
IgnoreParameterNames:
- "_*"
- "unused_*"
Style/LargeNumbers:
Enabled: true
IntMinDigits: 5
Performance/SizeAfterFilter:
Enabled: true
FilterNames:
- select
- reject
- filter
Severity Levels
Understanding Severity
Lint/Syntax:
Severity: Error
Lint/UnusedArgument:
Severity: Warning
Style/RedundantReturn:
Severity: Convention
Severity Configuration Strategy
Lint/Syntax:
Severity: Error
Lint/UnreachableCode:
Severity: Error
Style/RedundantReturn:
Severity: Warning
Style/LargeNumbers:
Severity: Convention
Lint/UnusedArgument:
Severity: Error
Style/RedundantReturn:
Severity: Error
Style/VariableNames:
Severity: Error
Lint/UselessAssign:
Severity: Warning
Style/RedundantBegin:
Severity: Convention
Inline Rule Control
Disabling Rules in Code
# Disable single rule for one line
time = Time.epoch(1483859302) # ameba:disable Style/LargeNumbers
# Disable multiple rules for one line
result = calculate() # ameba:disable Style/RedundantReturn, Lint/UselessAssign
# Disable rule categories
# ameba:disable Style, Lint
def legacy_method
# Old code with known issues
end
# ameba:enable Style, Lint
# Disable specific rule for block
# ameba:disable Style/RedundantBegin
def process
begin
perform_operation
rescue
handle_error
end
end
# ameba:enable Style/RedundantBegin
# Common patterns
class LegacyService
# ameba:disable Lint/UnusedArgument
def process(data, context)
# Only using data for now
data.process
end
# ameba:enable Lint/UnusedArgument
end
Inline Disable Best Practices
# GOOD - Specific and temporary
def parse_timestamp(value)
Time.epoch(1483859302) # ameba:disable Style/LargeNumbers
end
# GOOD - With explanation
# This API requires exact numeric format
# ameba:disable Style/LargeNumbers
LEGACY_TIMESTAMP = 1483859302
# ameba:enable Style/LargeNumbers
# BAD - Too broad
# ameba:disable Style
# Disables all style rules - too permissive
def messy_method
# ...
end
# BAD - Never re-enabled
# ameba:disable Lint/UselessAssign
# Disables for rest of file
# GOOD - Scoped to minimum area
def external_api_call
# ameba:disable Style/VariableNames
responseData = call_api() # External API uses camelCase
# ameba:enable Style/VariableNames
response_data = responseData # Convert to Crystal convention
end
Complete Configuration Examples
Minimal Configuration (Permissive)
Globs:
- "**/*.cr"
- "!lib"
Lint/Syntax:
Enabled: true
Severity: Error
Lint/UnreachableCode:
Enabled: true
Severity: Error
Standard Configuration (Balanced)
Globs:
- "**/*.cr"
- "**/*.ecr"
- "!lib"
Excluded:
- spec/fixtures/**
Lint/Syntax:
Enabled: true
Severity: Error
Lint/UnusedArgument:
Enabled: true
Severity: Warning
Lint/UselessAssign:
Enabled: true
Severity: Warning
Lint/UnreachableCode:
Enabled: true
Severity: Error
Style/RedundantReturn:
Enabled: true
Severity: Convention
Style/RedundantBegin:
Enabled: true
Severity: Convention
Style/LargeNumbers:
Enabled: true
Severity: Convention
IntMinDigits: 5
Style/VariableNames:
Enabled: true
Severity:
Strict Configuration (Comprehensive)
Globs:
- "src/**/*.cr"
- "spec/**/*.cr"
- "!lib"
Excluded:
- spec/fixtures/**
- spec/support/mocks/**
Lint/Syntax:
Enabled: true
Severity: Error
Lint/UnusedArgument:
Enabled: true
Severity: Error
Lint/UselessAssign:
Enabled: true
Severity: Error
Lint/UnreachableCode:
Enabled: true
Severity: Error
Lint/ShadowingOuterLocalVar:
Enabled: true
Severity: Error
Lint/DebuggerStatement:
Enabled: true
Severity: Error
Style/RedundantReturn:
Enabled: true
Severity: Error
Style/RedundantBegin:
Enabled: true
Severity:
When to Use This Skill
Use the ameba-configuration skill when:
- Setting up Ameba for a new Crystal project
- Configuring code quality standards for a team
- Customizing rule severity levels for CI/CD
- Excluding legacy code or generated files from analysis
- Troubleshooting rule conflicts or false positives
- Migrating from one Ameba version to another
- Establishing project-specific coding standards
- Balancing code quality with development velocity
- Integrating Ameba into existing Crystal projects
- Creating configuration templates for multiple projects
Best Practices
- Start with generated config - Run
ameba --gen-config to see all available rules and their defaults
- Use version control - Commit
.ameba.yml so team members share the same configuration
- Enable incrementally - Start permissive, gradually enable more rules as team adapts
- Set appropriate severities - Use Error for blocking issues, Warning for important, Convention for style
- Document exceptions - Add comments explaining why specific rules are disabled or configured differently
- Scope exclusions narrowly - Exclude specific files/directories rather than disabling rules globally
- Use inline disables sparingly - Prefer fixing issues over disabling rules; when necessary, be specific
- Review generated config - Don't blindly use default config; review and customize for your project
- Separate concerns - Use different severity levels for different types of issues (bugs vs style)
- Test configuration changes - Run
ameba locally before committing configuration changes
- Keep config maintainable - Group related rules together and use comments to explain sections
- Align with team standards - Configuration should reflect team consensus, not individual preferences
- Update regularly - Review and update configuration when upgrading Ameba versions
- Use rule-specific exclusions - Exclude files from specific rules rather than globally when possible
- Monitor false positives - Adjust rules that generate too many false positives for your codebase
Common Pitfalls
- Too strict initially - Enabling all rules at maximum severity in existing projects creates overwhelming technical debt
- Too permissive permanently - Never tightening rules means missing valuable code quality improvements
- Excluding too broadly - Using
Excluded: ["**/*"] defeats the purpose of static analysis
- Inconsistent severity - Mixing up severity levels (making style issues errors, making bugs conventions)
- Not using version control - Team members using different configurations causes confusion
- Ignoring upgrade guides - New Ameba versions may change rule names or behaviors
- Disabling without understanding - Turning off rules that flag legitimate issues
- Overusing inline disables - Littering code with
ameba:disable comments instead of fixing issues
- Not excluding generated code - Wasting time analyzing auto-generated files
- Forgetting about ECR files - Not including
**/*.ecr in Globs for web applications
- Conflicting with formatter - Enabling rules that conflict with
crystal tool format
- Missing test files - Not including
spec/**/*.cr in Globs
- Global disables in code - Using
ameba:disable at file level without re-enabling
- Not testing CI integration - Configuration works locally but fails in CI environment
- Ignoring performance impact - Enabling every rule without considering analysis time on large codebases
Resources