diff --git a/.ameba.yml b/.ameba.yml new file mode 100644 index 00000000..9dcab208 --- /dev/null +++ b/.ameba.yml @@ -0,0 +1,154 @@ +# 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" + +Excluded: + # BUG: Workaround for https://github.com/crystal-ameba/ameba/issues/782, https://github.com/crystal-ameba/ameba/issues/786, and https://github.com/crystal-ameba/ameba/issues/781 + - spec/support/factories.cr + +# Documentation +# ========================= + +# Disabled: What's the point in alerting about existing TODOs in code? +Documentation/DocumentationAdmonition: + Enabled: false + +# Lint +# ========================= + +# Disabled: `else nil` can be useful to explicitly show the consequence of the else branch +Lint/ElseNil: + Enabled: false + +# Disabled: We have an explicit CI job for testing the formatter (both latest +# and head). No reason to run it through ameba. +Lint/Formatting: + Enabled: false + +# TODO: Investigate if some `not_nil!` calls can be avoided. +Lint/NotNil: + Enabled: false + +# FIXME: Resolve shadowing. +Lint/ShadowingOuterLocalVar: + 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 + +Lint/UselessAssign: + # BUG: https://github.com/crystal-ameba/ameba/issues/447 + # This setting is to avoid false positives from the common use of type + # declarations in macro arguments. + ExcludeTypeDeclarations: true + +# 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 + +# 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/RedundantNext: + Enabled: false + +Style/RedundantReturn: + Enabled: false + +Style/RedundantSelf: + Enabled: false + +Style/VerboseBlock: + Enabled: false + +Style/WhileTrue: + Enabled: false diff --git a/devenv.nix b/devenv.nix index 1960ca0c..9e0023b9 100644 --- a/devenv.nix +++ b/devenv.nix @@ -23,6 +23,14 @@ git-hooks.hooks = { actionlint.enable = true; + ameba = { + enable = true; + name = "Ameba"; + entry = "${pkgs.ameba}/bin/ameba --fix"; + files = "\\.cr$"; + excludes = ["^lib/"]; + pass_filenames = true; + }; check-toml.enable = true; check-vcs-permalinks.enable = true; circleci.enable = true; diff --git a/spec/integration/install_spec.cr b/spec/integration/install_spec.cr index 55a5a3e6..ef94d41e 100644 --- a/spec/integration/install_spec.cr +++ b/spec/integration/install_spec.cr @@ -533,7 +533,6 @@ describe "install" do override = {dependencies: { awesome: {git: git_url(:forked_awesome), branch: "feature/super"}, }} - expected_commit = git_commits(:forked_awesome).first with_shard(metadata, lock, override) do ex = expect_raises(FailedCommand) { run "shards install --no-color --#{flag}" } @@ -551,7 +550,6 @@ describe "install" do override = {dependencies: { awesome: {git: git_url(:forked_awesome), branch: "feature/super"}, }} - expected_commit = git_commits(:forked_awesome).first with_shard(metadata, lock, override) do ex = expect_raises(FailedCommand) { run "shards install --no-color --#{flag}" } diff --git a/spec/support/factories.cr b/spec/support/factories.cr index 1f28b4c8..d7b3181f 100644 --- a/spec/support/factories.cr +++ b/spec/support/factories.cr @@ -312,7 +312,7 @@ def fossil_commits(project, rev = "trunk") end retLines.reject! &.nil? - [/artifact:\s+(.+)/.match(run("fossil whatis #{retLines[0]}")).not_nil!.[1]] + [/artifact:\s+(.+)/.match(run("fossil whatis #{retLines[0]}")).not_nil![1]] # ameba:disable Lint/NotNilAfterNoBang (1.0 compatibility) end end @@ -321,7 +321,7 @@ def fossil_url(project) end def fossil_path(project) - File.join(tmp_path, "#{project.to_s}") + File.join(tmp_path, "#{project}") end def rel_path(project) diff --git a/src/commands/check.cr b/src/commands/check.cr index 56351099..9c9c56e9 100644 --- a/src/commands/check.cr +++ b/src/commands/check.cr @@ -15,7 +15,7 @@ module Shards end private def has_dependencies? - spec.dependencies.any? || (Shards.with_development? && spec.development_dependencies.any?) + !spec.dependencies.empty? || (Shards.with_development? && !spec.development_dependencies.empty?) end private def verify(dependencies) diff --git a/src/commands/list.cr b/src/commands/list.cr index dd61bfb3..7adc8dfa 100644 --- a/src/commands/list.cr +++ b/src/commands/list.cr @@ -30,7 +30,7 @@ module Shards # FIXME: duplicates Check#has_dependencies? private def has_dependencies? - spec.dependencies.any? || (Shards.with_development? && spec.development_dependencies.any?) + !spec.dependencies.empty? || (Shards.with_development? && !spec.development_dependencies.empty?) end end end diff --git a/src/commands/outdated.cr b/src/commands/outdated.cr index 89794706..4cd83480 100644 --- a/src/commands/outdated.cr +++ b/src/commands/outdated.cr @@ -112,7 +112,7 @@ module Shards # FIXME: duplicates Check#has_dependencies? private def has_dependencies? - spec.dependencies.any? || (Shards.with_development? && spec.development_dependencies.any?) + !spec.dependencies.empty? || (Shards.with_development? && !spec.development_dependencies.empty?) end private def dependency_by_name(name : String) diff --git a/src/molinillo_solver.cr b/src/molinillo_solver.cr index 4af8b502..dab73045 100644 --- a/src/molinillo_solver.cr +++ b/src/molinillo_solver.cr @@ -182,7 +182,7 @@ module Shards @search_results[{dependency.name, dependency.requirement}] ||= begin resolver = dependency.resolver - versions = Versions.sort(versions_for(dependency, resolver)).reverse + versions = Versions.sort(versions_for(dependency, resolver)).reverse! result = versions.map do |version| @specs[{dependency.name, version}] ||= begin resolver.spec(version).tap do |spec| diff --git a/src/target.cr b/src/target.cr index 19810d7c..b49c9fee 100644 --- a/src/target.cr +++ b/src/target.cr @@ -9,7 +9,7 @@ module Shards main = nil pull.each_in_mapping do - case key = pull.read_scalar + case pull.read_scalar when "main" main = pull.read_scalar else