diff --git a/.ameba.yml b/.ameba.yml new file mode 100644 index 000000000000..d42e4b69d24a --- /dev/null +++ b/.ameba.yml @@ -0,0 +1,194 @@ +# This configuration file was generated by `ameba --gen-config` +# on 2025-06-02 13:57:07 UTC using Ameba version 1.7.0-dev. +# The point is for the user to remove these configuration records +# one by one as the reported problems are removed from the code base. +# +# For more details on any individual rule, run `ameba --only RuleName`. + +# Indicators for comment annotations: +# +# * `Disabled`: The rule is disabled because it does not seem useful for this repo (or in general). +# * `BUG`: A bug in ameba prevents using this rule either entirely or for specific files. +# * `FIXME`: The rule seems useful, but requires some effort to resolve. That's deferred for later. +# * `TODO`: The rule might be useful, but we need to investigate whether we want to use it or not. + +Version: "1.7.0-dev" + +# Documentation +# ========================= + +# Disabled: What's the point in alerting about existing TODOs in code? +Documentation/DocumentationAdmonition: + Enabled: false + +# Lint +# ========================= + +Lint/DebugCalls: + Excluded: + # Samples may legitimately use DebugCalls + - samples/**/* + # Explicit tests + - spec/std/pp_spec.cr + +Lint/DebuggerStatement: + Excluded: + # Explicit tests + - spec/debug/**/* + +# Disabled: `else nil` can be useful to explicitly show the consequence of the else branch +Lint/ElseNil: + Enabled: false + +Lint/LiteralInCondition: + Excluded: + # Samples may legitimately use literals in conditions + - samples/**/* + +Lint/LiteralInInterpolation: + Excluded: + - spec/std/random_spec.cr # BUG: https://github.com/crystal-ameba/ameba/issues/611 + +Lint/LiteralsComparison: + Excluded: + # Explicit tests for case equality on tuple literals + - spec/std/tuple_spec.cr + +# TODO: Investigate if some `not_nil!` calls can be avoided. +Lint/NotNil: + Enabled: false + +Lint/RandZero: + Excluded: + # Explicit tests + - spec/std/random_spec.cr + +# FIXME: Resolve shadowing. +Lint/ShadowingOuterLocalVar: + Enabled: false + +# TODO: Investigate file names and move to data directories. +Lint/SpecFilename: + Enabled: false + +# BUG: https://github.com/crystal-ameba/ameba/issues/612 +Lint/TopLevelOperatorDefinition: + Enabled: false + +# Disabled: We have an explicit CI job for `typos`. No reason to run it through +# ameba. +Lint/Typos: + Enabled: false + +# TODO: Investigate unused arguments. +Lint/UnusedArgument: + Enabled: false + +# TODO: Investigate unused block arguments. +Lint/UnusedBlockArgument: + Enabled: false + +# FIXME: Investigate useless assigns. +Lint/UselessAssign: + Enabled: false + +# Metrics +# ========================= + +# Disabled: Lot's of violations. Complexity is very individual. +Metrics/CyclomaticComplexity: + Enabled: false + +# Naming +# ========================= +# All disabled. There are many violations and some of the rules are questionable. +# TODO: Consider enabling some of these rules. + +Naming/AccessorMethodName: + Enabled: false + +Naming/BinaryOperatorParameterName: + Enabled: false + +Naming/BlockParameterName: + Enabled: false + +# Disabled: All violations follow the spelling of identifiers in upstream +# projects, e.g. for lib bindings. +Naming/ConstantNames: + Enabled: false + +Naming/MethodNames: + Enabled: false + +Naming/PredicateName: + Enabled: false + +Naming/QueryBoolMethods: + Enabled: false + +Naming/RescuedExceptionsVariableName: + Enabled: false + +Naming/TypeNames: + Enabled: false + +Naming/VariableNames: + Enabled: false + +# Performance +# ========================= + +Performance/AnyInsteadOfEmpty: + Excluded: + # These specs explicitly test `#any?` implementations + - spec/std/bit_array_spec.cr + - spec/std/enumerable_spec.cr + - spec/std/hash_spec.cr + +# Style +# ========================= +# All disabled. There are many violations and some of the rules are questionable. +# TODO: Consider enabling some of these rules. + +Style/HeredocEscape: + Enabled: false + +Style/HeredocIndent: + Enabled: false + +Style/MultilineCurlyBlock: + Enabled: false + +# Disabled: This rule seems too strict when any negation inside a complex condition is +# considered a violation. https://github.com/crystal-ameba/ameba/issues/621 +Style/NegatedConditionsInUnless: + Enabled: false + +# BUG: https://github.com/crystal-ameba/ameba/issues/614 +Style/ParenthesesAroundCondition: + Enabled: false + +Style/PercentLiteralDelimiters: + Enabled: false + +Style/RedundantBegin: + Enabled: false + +Style/RedundantNext: + Enabled: false + +Style/RedundantReturn: + Enabled: false + +Style/RedundantSelf: + Enabled: false + +Style/UnlessElse: + Enabled: false + +Style/VerboseBlock: + Enabled: false + +Style/WhileTrue: + Enabled: false diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index e79611b3d339..dd2927f4a847 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -113,3 +113,12 @@ jobs: uses: crate-ci/typos@v1.33.1 env: CLICOLOR: 1 + + lint_ameba: + runs-on: ubuntu-latest + container: ghcr.io/crystal-ameba/ameba:sha-d861f4ed0f904e0ecdad11c26f98e968f7d95afa # 1.7.0-dev + steps: + - name: Download Crystal source + uses: actions/checkout@v4 + + - run: ameba diff --git a/scripts/generate_windows_zone_names.cr b/scripts/generate_windows_zone_names.cr index adcd43bd97b6..cf0365263241 100755 --- a/scripts/generate_windows_zone_names.cr +++ b/scripts/generate_windows_zone_names.cr @@ -45,7 +45,7 @@ windows_zone_names_items = entries.compact_map do |tzdata_name, territory, windo {windows_name, zone1.name, zone2.name, location.name} rescue err : Time::Location::InvalidLocationNameError - pp err + puts err nil end diff --git a/spec/llvm-ir/pass-closure-to-c-debug-loc.cr b/spec/llvm-ir/pass-closure-to-c-debug-loc.cr index 6891ae6ae92f..388f1c8bbdd5 100644 --- a/spec/llvm-ir/pass-closure-to-c-debug-loc.cr +++ b/spec/llvm-ir/pass-closure-to-c-debug-loc.cr @@ -3,7 +3,7 @@ lib Foo end def raise(msg) - while true + while true # ameba:disable Lint/EmptyLoop end end diff --git a/spec/std/iterator_spec.cr b/spec/std/iterator_spec.cr index b7f000a871cb..5a5dda28cfd4 100644 --- a/spec/std/iterator_spec.cr +++ b/spec/std/iterator_spec.cr @@ -663,7 +663,7 @@ describe Iterator do describe "uniq" do it "without block" do - iter = (1..8).each.map { |x| x % 3 }.uniq + iter = (1..8).each.map { |x| x % 3 }.uniq # ameba:disable Performance/ChainedCallWithNoBang iter.next.should eq(1) iter.next.should eq(2) iter.next.should eq(0) @@ -806,7 +806,7 @@ describe Iterator do end it "flattens nested struct iterators with internal state being value types" do - iter = (1..2).each.map { |i| StructIter.new(10 * i + 1, 10 * i + 3) }.flatten + iter = (1..2).each.map { |i| StructIter.new(10 * i + 1, 10 * i + 3) }.flatten # ameba:disable Performance/FlattenAfterMap iter.next.should eq(11) iter.next.should eq(12) diff --git a/src/kernel.cr b/src/kernel.cr index a9e372174d49..41243b3f7dd0 100644 --- a/src/kernel.cr +++ b/src/kernel.cr @@ -468,7 +468,7 @@ end # See also: `Object#inspect(io)`. def p(*objects) objects.each do |obj| - p obj + p obj # ameba:disable Lint/DebugCalls end objects end @@ -482,7 +482,7 @@ end # # See `Object#inspect(io)` def p(**objects) - p(objects) unless objects.empty? + p(objects) unless objects.empty? # ameba:disable Lint/DebugCalls end # Pretty prints *object* to `STDOUT` followed @@ -501,7 +501,7 @@ end # See also: `Object#pretty_print(pp)`. def pp(*objects) objects.each do |obj| - pp obj + pp obj # ameba:disable Lint/DebugCalls end objects end @@ -515,7 +515,7 @@ end # # See `Object#pretty_print(pp)` def pp(**objects) - pp(objects) unless objects.empty? + pp(objects) unless objects.empty? # ameba:disable Lint/DebugCalls end # Registers the given `Proc` for execution when the program exits regularly.