← All posts

Ameba 1.5.0 has been released

This release brings 3 new rules, Crystal 1.9 compatibility, several breaking changes and various improvements. Check out the release notes to see a full scope of changes.

Crystal compatibility

This release introduces Crystal 1.9 compatibility and drops support for Crystal < 1.9. Use the latest Ameba bugfix release 1.4.3 if you need compatibility with Crystal 1.8.x or below.

New rules

Lint/Documentation

A rule that enforces documentation for public types: classes, modules, enums, methods, and macros. Since reopened classes are less common than modules, classes are checked by default while modules are not — you can adjust this via the IgnoreClasses and IgnoreModules configuration options.

class Foo
  def bar # error: Missing documentation
  end
end

This rule is disabled by default and will produce an issue for every public type without a doc comment:

Lint/Documentation:
  Enabled: true # enable to opt-in
  IgnoreClasses: false
  IgnoreModules: true
  IgnoreEnums: false
  IgnoreDefs: true
  IgnoreMacros: false
  IgnoreMacroHooks: true

Performance/ExcessiveAllocations

A rule that flags excessive collection allocations that can be avoided by using each_<member> methods instead of allocating intermediary collections with .each.

Bad

"Alice".chars.each { |c| puts c }
"Alice\nBob".lines.each { |l| puts l }

Good

"Alice".each_char { |c| puts c }
"Alice\nBob".each_line { |l| puts l }

The set of checked collection methods is configurable:

Performance/ExcessiveAllocations:
  Enabled: true
  CallNames:
    codepoints: each_codepoint
    graphemes: each_grapheme
    chars: each_char
    lines: each_line

This rule also supports autocorrection.

Performance/MinMaxAfterMap

A rule that flags min/max/minmax calls following map, and suggests using dedicated *_of methods instead.

Bad

%w[Alice Bob].map(&.size).min
%w[Alice Bob].map(&.size).max
%w[Alice Bob].map(&.size).minmax

Good

%w[Alice Bob].min_of(&.size)
%w[Alice Bob].max_of(&.size)
%w[Alice Bob].minmax_of(&.size)

This rule also supports autocorrection.

Breaking changes

  • Lint/NotNilAfterNoBang now also reports calls to #rindex in addition to #index (#323).
  • Invalid config file paths now raise an error instead of being silently ignored (#393).
  • Empty severity values in YAML configuration now raise an error instead of being silently accepted (#373).
  • Style/VerboseBlock rule was fixed to work correctly with binary operations like a + b inside blocks (#384).

Other improvements

  • Portable postinstall: The postinstall script now uses shards build directly instead of make build, improving portability across platforms including Windows (#391).
  • Dockerfile updated to support pcre2 engine, and a smoke check (ameba -v) was added to verify the binary works at build time (#369).
  • AST::NodeVisitor::Category was introduced to simplify the rule codebase (#378).
  • Several internal tweaks and refactors (#379).