Skip to content

Commit 46a5f13

Browse files
Add ameba (#15875)
Adds configuration and a CI job for https://github.com/crystal-ameba/ameba I let ameba generate a config (`ameba --gen-config`) but replaced all exclusions with hard disables. Then I fixed the violations for some of the rules, which have already been merged in the last couple of days. So I removed the disables for these rules. The configuration is annotated with explanations in code. I have disabled most `Naming` and `Style` rules because most had large numbers of violations and some of them seem questionable. We can consider enabling some of the in the future, piece by piece
1 parent 4a6169b commit 46a5f13

File tree

6 files changed

+211
-8
lines changed

6 files changed

+211
-8
lines changed

.ameba.yml

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# This configuration file was generated by `ameba --gen-config`
2+
# on 2025-06-02 13:57:07 UTC using Ameba version 1.7.0-dev.
3+
# The point is for the user to remove these configuration records
4+
# one by one as the reported problems are removed from the code base.
5+
#
6+
# For more details on any individual rule, run `ameba --only RuleName`.
7+
8+
# Indicators for comment annotations:
9+
#
10+
# * `Disabled`: The rule is disabled because it does not seem useful for this repo (or in general).
11+
# * `BUG`: A bug in ameba prevents using this rule either entirely or for specific files.
12+
# * `FIXME`: The rule seems useful, but requires some effort to resolve. That's deferred for later.
13+
# * `TODO`: The rule might be useful, but we need to investigate whether we want to use it or not.
14+
15+
Version: "1.7.0-dev"
16+
17+
# Documentation
18+
# =========================
19+
20+
# Disabled: What's the point in alerting about existing TODOs in code?
21+
Documentation/DocumentationAdmonition:
22+
Enabled: false
23+
24+
# Lint
25+
# =========================
26+
27+
Lint/DebugCalls:
28+
Excluded:
29+
# Samples may legitimately use DebugCalls
30+
- samples/**/*
31+
# Explicit tests
32+
- spec/std/pp_spec.cr
33+
34+
Lint/DebuggerStatement:
35+
Excluded:
36+
# Explicit tests
37+
- spec/debug/**/*
38+
39+
# Disabled: `else nil` can be useful to explicitly show the consequence of the else branch
40+
Lint/ElseNil:
41+
Enabled: false
42+
43+
Lint/LiteralInCondition:
44+
Excluded:
45+
# Samples may legitimately use literals in conditions
46+
- samples/**/*
47+
48+
Lint/LiteralInInterpolation:
49+
Excluded:
50+
- spec/std/random_spec.cr # BUG: https://github.com/crystal-ameba/ameba/issues/611
51+
52+
Lint/LiteralsComparison:
53+
Excluded:
54+
# Explicit tests for case equality on tuple literals
55+
- spec/std/tuple_spec.cr
56+
57+
# TODO: Investigate if some `not_nil!` calls can be avoided.
58+
Lint/NotNil:
59+
Enabled: false
60+
61+
Lint/RandZero:
62+
Excluded:
63+
# Explicit tests
64+
- spec/std/random_spec.cr
65+
66+
# FIXME: Resolve shadowing.
67+
Lint/ShadowingOuterLocalVar:
68+
Enabled: false
69+
70+
# TODO: Investigate file names and move to data directories.
71+
Lint/SpecFilename:
72+
Enabled: false
73+
74+
# BUG: https://github.com/crystal-ameba/ameba/issues/612
75+
Lint/TopLevelOperatorDefinition:
76+
Enabled: false
77+
78+
# Disabled: We have an explicit CI job for `typos`. No reason to run it through
79+
# ameba.
80+
Lint/Typos:
81+
Enabled: false
82+
83+
# TODO: Investigate unused arguments.
84+
Lint/UnusedArgument:
85+
Enabled: false
86+
87+
# TODO: Investigate unused block arguments.
88+
Lint/UnusedBlockArgument:
89+
Enabled: false
90+
91+
# FIXME: Investigate useless assigns.
92+
Lint/UselessAssign:
93+
Enabled: false
94+
95+
# Metrics
96+
# =========================
97+
98+
# Disabled: Lot's of violations. Complexity is very individual.
99+
Metrics/CyclomaticComplexity:
100+
Enabled: false
101+
102+
# Naming
103+
# =========================
104+
# All disabled. There are many violations and some of the rules are questionable.
105+
# TODO: Consider enabling some of these rules.
106+
107+
Naming/AccessorMethodName:
108+
Enabled: false
109+
110+
Naming/BinaryOperatorParameterName:
111+
Enabled: false
112+
113+
Naming/BlockParameterName:
114+
Enabled: false
115+
116+
# Disabled: All violations follow the spelling of identifiers in upstream
117+
# projects, e.g. for lib bindings.
118+
Naming/ConstantNames:
119+
Enabled: false
120+
121+
Naming/MethodNames:
122+
Enabled: false
123+
124+
Naming/PredicateName:
125+
Enabled: false
126+
127+
Naming/QueryBoolMethods:
128+
Enabled: false
129+
130+
Naming/RescuedExceptionsVariableName:
131+
Enabled: false
132+
133+
Naming/TypeNames:
134+
Enabled: false
135+
136+
Naming/VariableNames:
137+
Enabled: false
138+
139+
# Performance
140+
# =========================
141+
142+
Performance/AnyInsteadOfEmpty:
143+
Excluded:
144+
# These specs explicitly test `#any?` implementations
145+
- spec/std/bit_array_spec.cr
146+
- spec/std/enumerable_spec.cr
147+
- spec/std/hash_spec.cr
148+
149+
# Style
150+
# =========================
151+
# All disabled. There are many violations and some of the rules are questionable.
152+
# TODO: Consider enabling some of these rules.
153+
154+
Style/HeredocEscape:
155+
Enabled: false
156+
157+
Style/HeredocIndent:
158+
Enabled: false
159+
160+
Style/MultilineCurlyBlock:
161+
Enabled: false
162+
163+
# Disabled: This rule seems too strict when any negation inside a complex condition is
164+
# considered a violation. https://github.com/crystal-ameba/ameba/issues/621
165+
Style/NegatedConditionsInUnless:
166+
Enabled: false
167+
168+
# BUG: https://github.com/crystal-ameba/ameba/issues/614
169+
Style/ParenthesesAroundCondition:
170+
Enabled: false
171+
172+
Style/PercentLiteralDelimiters:
173+
Enabled: false
174+
175+
Style/RedundantBegin:
176+
Enabled: false
177+
178+
Style/RedundantNext:
179+
Enabled: false
180+
181+
Style/RedundantReturn:
182+
Enabled: false
183+
184+
Style/RedundantSelf:
185+
Enabled: false
186+
187+
Style/UnlessElse:
188+
Enabled: false
189+
190+
Style/VerboseBlock:
191+
Enabled: false
192+
193+
Style/WhileTrue:
194+
Enabled: false

.github/workflows/linux.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,12 @@ jobs:
113113
uses: crate-ci/[email protected]
114114
env:
115115
CLICOLOR: 1
116+
117+
lint_ameba:
118+
runs-on: ubuntu-latest
119+
container: ghcr.io/crystal-ameba/ameba:sha-d861f4ed0f904e0ecdad11c26f98e968f7d95afa # 1.7.0-dev
120+
steps:
121+
- name: Download Crystal source
122+
uses: actions/checkout@v4
123+
124+
- run: ameba

scripts/generate_windows_zone_names.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ windows_zone_names_items = entries.compact_map do |tzdata_name, territory, windo
4545

4646
{windows_name, zone1.name, zone2.name, location.name}
4747
rescue err : Time::Location::InvalidLocationNameError
48-
pp err
48+
puts err
4949
nil
5050
end
5151

spec/llvm-ir/pass-closure-to-c-debug-loc.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ lib Foo
33
end
44

55
def raise(msg)
6-
while true
6+
while true # ameba:disable Lint/EmptyLoop
77
end
88
end
99

spec/std/iterator_spec.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ describe Iterator do
663663

664664
describe "uniq" do
665665
it "without block" do
666-
iter = (1..8).each.map { |x| x % 3 }.uniq
666+
iter = (1..8).each.map { |x| x % 3 }.uniq # ameba:disable Performance/ChainedCallWithNoBang
667667
iter.next.should eq(1)
668668
iter.next.should eq(2)
669669
iter.next.should eq(0)
@@ -806,7 +806,7 @@ describe Iterator do
806806
end
807807

808808
it "flattens nested struct iterators with internal state being value types" do
809-
iter = (1..2).each.map { |i| StructIter.new(10 * i + 1, 10 * i + 3) }.flatten
809+
iter = (1..2).each.map { |i| StructIter.new(10 * i + 1, 10 * i + 3) }.flatten # ameba:disable Performance/FlattenAfterMap
810810

811811
iter.next.should eq(11)
812812
iter.next.should eq(12)

src/kernel.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ end
468468
# See also: `Object#inspect(io)`.
469469
def p(*objects)
470470
objects.each do |obj|
471-
p obj
471+
p obj # ameba:disable Lint/DebugCalls
472472
end
473473
objects
474474
end
@@ -482,7 +482,7 @@ end
482482
#
483483
# See `Object#inspect(io)`
484484
def p(**objects)
485-
p(objects) unless objects.empty?
485+
p(objects) unless objects.empty? # ameba:disable Lint/DebugCalls
486486
end
487487

488488
# Pretty prints *object* to `STDOUT` followed
@@ -501,7 +501,7 @@ end
501501
# See also: `Object#pretty_print(pp)`.
502502
def pp(*objects)
503503
objects.each do |obj|
504-
pp obj
504+
pp obj # ameba:disable Lint/DebugCalls
505505
end
506506
objects
507507
end
@@ -515,7 +515,7 @@ end
515515
#
516516
# See `Object#pretty_print(pp)`
517517
def pp(**objects)
518-
pp(objects) unless objects.empty?
518+
pp(objects) unless objects.empty? # ameba:disable Lint/DebugCalls
519519
end
520520

521521
# Registers the given `Proc` for execution when the program exits regularly.

0 commit comments

Comments
 (0)