All posts

Ameba 1.6.0 has been released

This release adds 9 new rules, a new --describe CLI switch, reorganized rule groups, and several bug fixes. Check out the release notes to see a full scope of changes.

New rules

This release brings the total number of rules to 77.

Documentation/DocumentationAdmonition

A rule that reports documentation admonitions like TODO, FIXME, and BUG in comments. Optionally checks whether a date associated with the admonition has already passed.

# TODO(2024-04-24) Fix this hack when the database migration is complete
def get_user(id)
  # ...
end

The Admonitions and Timezone configuration properties let you customize which keywords to look for and how to parse dates.

Lint/Typos

A rule that reports typos found in source files using the excellent typos CLI tool. When only one correction is suggested, it can autocorrect the typo automatically.

Lint/Typos:
  Enabled: true
  BinPath: /usr/local/bin/typos
  FailOnError: false

Lint/SpecFilename

Enforces that spec filenames have the _spec suffix as recommended by the Crystal testing guide. Supports autocorrection by renaming the file.

$ ameba spec/my.cr
- spec/my.cr:1:1 [Correctable]
  Lint/SpecFilename: Spec filename should have `_spec` suffix: my_spec.cr, not my.cr

Naming/Filename

A rule that enforces file names to be in underscored case (snake_case).

$ ameba src/MyClass.cr
- src/MyClass.cr:1:1
  Naming/Filename: Filename should be underscore-cased: my_class.cr, not MyClass.cr

Naming/AccessorMethodName

Makes sure that accessor methods are named properly — favouring user / user= over get_user / set_user.

Bad

def get_user
  @user
end

def set_user(value)
  @user = value
end

Good

def user
  @user
end

def user=(value)
  @user = value
end

Naming/AsciiIdentifiers

Disallows non-ASCII characters in identifiers such as class names, method names, variables, and symbol literals.

Bad

class BigAwesome🐺
end

Good

class BigAwesomeWolf
end

Naming/RescuedExceptionsVariableName

Makes sure that rescued exception variables use expected names (by default e, ex, or exception).

Bad

rescue wtf
  Log.error(exception: wtf) { "Error" }
end

Good

rescue ex
  Log.error(exception: ex) { "Error" }
end

Naming/BlockParameterName

Reports non-descriptive block parameter names. By default, names shorter than 3 characters are flagged, with exceptions for common short names like _, e, i, j, k, v, x, y, and others.

Bad

tokens.each do |t|
  t.last_accessed_at = Time.utc
end

Good

tokens.each do |token|
  token.last_accessed_at = Time.utc
end

Naming/BinaryOperatorParameterName

Enforces that certain binary operator methods have their sole parameter named other.

Bad

def +(amount)
  # ...
end

Good

def +(other)
  # ...
end

Breaking changes

Rule group reorganization

Naming-related rules (#413) and documentation-related rules (#412) were moved into their own rule groups, Naming and Documentation respectively. If you reference these rules in # ameba:disable pragmas or your .ameba.yml configuration, you may need to update their names:

  • Style/PredicateNameNaming/PredicateName
  • Style/TypeNamesNaming/TypeNames
  • Style/MethodNamesNaming/MethodNames
  • Style/VariableNamesNaming/VariableNames
  • Style/ConstantNamesNaming/ConstantNames
  • Style/QueryBoolMethodsNaming/QueryBoolMethods
  • Lint/DocumentationDocumentation/Documentation

Invalid file paths now raise errors

Passing non-existent file paths to Ameba now raises an error (#394) instead of silently skipping them.

Notable improvements

Refactored --rules CLI switch output

This change makes the rule list formatted and nicely colored for better visual grepability.

New --describe <rule-name> CLI switch

New switch was added (#390), allowing you to quickly inspect a rule’s description and configuration:

Enhanced Lint/NotNilAfterNoBang

The Lint/NotNilAfterNoBang rule now also reports calls to #match (#423).

Improved Naming/AsciiIdentifiers

The rule now additionally reports non-ASCII characters in symbol literals (#424).

Bug fixes

  • Fixed Lint/LiteralsComparison false positive with dynamic literals (#417).
  • Fixed ShadowingOuterLocalVar false positive with expanded arguments (#426).
  • Fixed Crystal next compatibility by removing deprecated API calls (#407).
  • Reverted an incorrect improvement to Performance/ExcessiveAllocations (#428).