Skip to content

Commit c4e3f66

Browse files
authored
Updated Ameba and more (#1114)
* Upgraded Ameba. Fixing ameba issues. Set min Crystal version to 1.15 and make sure 1.17 works * ignore the TODOs for now. Not ready to deal with them yet * Fixing some compilation errors
1 parent 8031155 commit c4e3f66

27 files changed

Lines changed: 134 additions & 99 deletions

.ameba.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This configuration file was generated by `ameba --gen-config`
2+
# on 2025-07-16 22:49:09 UTC using Ameba version 1.6.4.
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+
# Problems found: 452
7+
# Run `ameba --only Lint/UselessAssign` for details
8+
Lint/UselessAssign:
9+
Description: Disallows useless variable assignments
10+
ExcludeTypeDeclarations: true
11+
Enabled: true
12+
Severity: Warning
13+
14+
# Problems found: 30
15+
# Run `ameba --only Naming/BlockParameterName` for details
16+
Naming/BlockParameterName:
17+
Description: Disallows non-descriptive block parameter names
18+
MinNameLength: 3
19+
AllowNamesEndingInNumbers: true
20+
AllowedNames:
21+
- db
22+
- io
23+
- id
24+
ForbiddenNames: []
25+
Enabled: true
26+
Severity: Convention
27+
28+
Documentation/DocumentationAdmonition:
29+
Description: Disallows leaving TODO comments
30+
Enabled: false

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- 14
3838
- 16
3939
crystal_version:
40-
- 1.10.0
40+
- 1.15.1
4141
- latest
4242
experimental:
4343
- false

shard.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: avram
22
version: 1.4.2
33

4-
crystal: ">= 1.10.0"
4+
crystal: ">= 1.15.1"
55

66
license: MIT
77

@@ -46,7 +46,7 @@ dependencies:
4646
development_dependencies:
4747
ameba:
4848
github: crystal-ameba/ameba
49-
version: ~> 1.5.0
49+
version: ~> 1.6.4
5050
lucky:
5151
github: luckyframework/lucky
5252
branch: main

spec/avram/json_column_spec.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ describe "JSON Columns" do
4949
form1 = SaveBlob.new
5050
form1.set_doc_from_param(%w[a b c])
5151
form1.set_metadata_from_param(BlobMetadata.from_json("{}"))
52-
form1.doc.value.should eq %w[a b c].map { |v| JSON::Any.new(v) }
52+
form1.doc.value.should eq %w[a b c].map { |value| JSON::Any.new(value) }
5353
form1.save!
5454
blob1 = BlobQuery.new.last
55-
blob1.doc.should eq %w[a b c].map { |v| JSON::Any.new(v) }
55+
blob1.doc.should eq %w[a b c].map { |value| JSON::Any.new(value) }
5656

5757
form2 = SaveBlob.new
5858
form2.set_doc_from_param({"foo" => {"bar" => "baz"}})

spec/avram/operations/define_attribute_spec.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ describe "attribute in operations" do
175175
operation.terms_of_service.value.should be_nil
176176
post.should_not be_nil
177177

178-
SaveOperationWithAttributes.update(post.as(Post), best_kind_of_bear: "koala bear") do |op, _post|
179-
op.best_kind_of_bear.value.should eq("koala bear")
178+
SaveOperationWithAttributes.update(post.as(Post), best_kind_of_bear: "koala bear") do |inner_operation, _post|
179+
inner_operation.best_kind_of_bear.value.should eq("koala bear")
180180
end
181181
end
182182
end

spec/avram/operations/operation_errors_spec.cr

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,34 @@ end
2828

2929
describe Avram::OperationErrors do
3030
it "sets a custom error for Operation" do
31-
op = FailedOperation.new(failure: true)
32-
op.add_error(:fail, "Not valid")
33-
op.valid?.should eq false
34-
op.errors[:fail].should eq ["Not valid"]
31+
operation = FailedOperation.new(failure: true)
32+
operation.add_error(:fail, "Not valid")
33+
operation.valid?.should eq false
34+
operation.errors[:fail].should eq ["Not valid"]
3535
end
3636

3737
it "returns a nil value when there's a custom error on Operation" do
38-
FailedOperation.run(failure: true) do |op, value|
38+
FailedOperation.run(failure: true) do |operation, value|
3939
value.should eq nil
40-
op.valid?.should eq false
41-
op.errors[:oops].should eq ["this didn't work"]
42-
op.errors[:failure].should eq ["move right along"]
40+
operation.valid?.should eq false
41+
operation.errors[:oops].should eq ["this didn't work"]
42+
operation.errors[:failure].should eq ["move right along"]
4343
end
4444
end
4545

4646
it "sets a custom error for SaveOperation" do
47-
op = SaveUserButNotReally.new(failure: true)
48-
op.add_error(:fail, "User did not save")
49-
op.valid?.should eq false
50-
op.errors[:fail].should eq ["User did not save"]
47+
operation = SaveUserButNotReally.new(failure: true)
48+
operation.add_error(:fail, "User did not save")
49+
operation.valid?.should eq false
50+
operation.errors[:fail].should eq ["User did not save"]
5151
end
5252

5353
it "returns a failed save status for SaveOperation" do
54-
SaveUserButNotReally.create(failure: true) do |op, value|
54+
SaveUserButNotReally.create(failure: true) do |operation, value|
5555
value.should eq nil
56-
op.valid?.should eq false
57-
op.errors[:failure].should eq ["This failed quick", "Like, really quick"]
58-
op.save_status.should eq SaveUserButNotReally::OperationStatus::SaveFailed
56+
operation.valid?.should eq false
57+
operation.errors[:failure].should eq ["This failed quick", "Like, really quick"]
58+
operation.save_status.should eq SaveUserButNotReally::OperationStatus::SaveFailed
5959
end
6060
end
6161
end

spec/avram/operations/save_operation_spec.cr

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ end
117117

118118
describe "Avram::SaveOperation" do
119119
it "calls the default validations after the before_save" do
120-
UserWithDefaultValidations.create(name: "TestName", nickname: "TestNickname", joined_at: Time.utc, age: 400) do |op, u|
121-
op.starts_nil.should eq("not nil!")
122-
u.should_not be_nil
123-
u.as(User).nickname.should eq("TestNickname")
120+
UserWithDefaultValidations.create(name: "TestName", nickname: "TestNickname", joined_at: Time.utc, age: 400) do |operation, user|
121+
operation.starts_nil.should eq("not nil!")
122+
user.should_not be_nil
123+
user.as(User).nickname.should eq("TestNickname")
124124
end
125125
end
126126

@@ -241,8 +241,8 @@ describe "Avram::SaveOperation" do
241241
it "updates the record using the same default value" do
242242
TokenFactory.create(&.name("special").scopes(["name"]).next_id(4))
243243

244-
UpsertToken.upsert(next_id: 4, name: "Secret", scopes: ["red", "blue"]) do |op, token|
245-
op.valid?.should eq(true)
244+
UpsertToken.upsert(next_id: 4, name: "Secret", scopes: ["red", "blue"]) do |operation, token|
245+
operation.valid?.should eq(true)
246246
token.should_not eq(nil)
247247
token.as(Token).name.should eq("Secret")
248248
token.as(Token).scopes.should eq(["red", "blue"])
@@ -542,9 +542,9 @@ describe "Avram::SaveOperation" do
542542
it "has inherited attributes" do
543543
user = UserFactory.create &.nickname("taco shop")
544544

545-
RenameUser.update(user, should_not_override_permitted_columns: "yo") do |op, u|
546-
u.nickname.should eq("The 'taco shop'")
547-
op.should_not_override_permitted_columns.value.should eq("yo")
545+
RenameUser.update(user, should_not_override_permitted_columns: "yo") do |operation, updated_user|
546+
updated_user.nickname.should eq("The 'taco shop'")
547+
operation.should_not_override_permitted_columns.value.should eq("yo")
548548
end
549549
end
550550
end
@@ -684,8 +684,8 @@ describe "Avram::SaveOperation" do
684684

685685
context "with bytes" do
686686
it "saves the byte column" do
687-
Beat::SaveOperation.create(hash: "boots and pants".to_slice) do |op, beat|
688-
op.saved?.should eq(true)
687+
Beat::SaveOperation.create(hash: "boots and pants".to_slice) do |operation, beat|
688+
operation.saved?.should eq(true)
689689
beat.should_not be_nil
690690
beat.as(Beat).hash.blank?.should eq(false)
691691
beat.as(Beat).hash.should eq(Bytes[98, 111, 111, 116, 115, 32, 97, 110, 100, 32, 112, 97, 110, 116, 115])
@@ -698,8 +698,8 @@ describe "Avram::SaveOperation" do
698698
it "creates the JSON value from params" do
699699
params = build_params(%({"blob": {"doc": {"sort": "desc"}, "metadata": {"name": "filter", "code": 4}}}), content_type: "application/json")
700700

701-
ReturnOfTheBlob.create(params) do |op, blob|
702-
op.valid?.should eq(true)
701+
ReturnOfTheBlob.create(params) do |operation, blob|
702+
operation.valid?.should eq(true)
703703
blob.should_not eq(nil)
704704
blob.as(Blob).doc.as(JSON::Any)["sort"].as_s.should eq("desc")
705705
blob.as(Blob).metadata.name.should eq("filter")
@@ -853,8 +853,8 @@ describe "Avram::SaveOperation" do
853853
slime = BlobFactory.new.doc(JSON::Any.new({"sort" => JSON::Any.new("desc")})).create
854854
params = build_params(%({"blob": {"doc": {"sort": "asc"}}}), content_type: "application/json")
855855

856-
ReturnOfTheBlob.update(slime, params) do |op, blob|
857-
op.valid?.should eq(true)
856+
ReturnOfTheBlob.update(slime, params) do |operation, blob|
857+
operation.valid?.should eq(true)
858858
blob.should_not eq(nil)
859859
blob.as(Blob).doc.as(JSON::Any)["sort"].as_s.should eq("asc")
860860
end
@@ -984,25 +984,25 @@ describe "Avram::SaveOperation" do
984984
describe "skip_default_validations" do
985985
it "allows blank strings to be saved" do
986986
post = PostFactory.create
987-
AllowBlankComment.create(post_id: post.id, body: "") do |op, new_comment|
988-
op.valid?.should be_true
987+
AllowBlankComment.create(post_id: post.id, body: "") do |operation, new_comment|
988+
operation.valid?.should be_true
989989
comment = new_comment.as(Comment)
990990
comment.body.should eq("")
991991
end
992992
end
993993
it "allows blank strings from params" do
994994
post = PostFactory.create
995995
params = build_params({comment: {post_id: post.id, body: ""}}.to_json, content_type: "application/json")
996-
AllowBlankComment.create(params) do |op, new_comment|
997-
op.valid?.should be_true
996+
AllowBlankComment.create(params) do |operation, new_comment|
997+
operation.valid?.should be_true
998998
comment = new_comment.as(Comment)
999999
comment.body.should eq("")
10001000
end
10011001
end
10021002
it "still allows normal data to be saved" do
10031003
post = PostFactory.create
1004-
AllowBlankComment.create(post_id: post.id, body: "not blank") do |op, new_comment|
1005-
op.valid?.should be_true
1004+
AllowBlankComment.create(post_id: post.id, body: "not blank") do |operation, new_comment|
1005+
operation.valid?.should be_true
10061006
comment = new_comment.as(Comment)
10071007
comment.body.should eq("not blank")
10081008
end
@@ -1027,9 +1027,9 @@ describe "Avram::SaveOperation" do
10271027
describe "#database" do
10281028
it "has access to the database via a helper method" do
10291029
post = PostFactory.create
1030-
AllowBlankComment.create(post_id: post.id, body: "") do |op, _new_comment|
1030+
AllowBlankComment.create(post_id: post.id, body: "") do |operation, _new_comment|
10311031
expect_raises(Avram::Rollback) do
1032-
op.database.rollback
1032+
operation.database.rollback
10331033
end
10341034
end
10351035
end

spec/avram/polymorphic_spec.cr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ end
3939

4040
describe "polymorphic belongs to" do
4141
it "allows you to set the association before save" do
42-
TestPolymorphicSave.create do |op, tp|
43-
op.valid?.should eq(true)
44-
tp.should_not be_nil
42+
TestPolymorphicSave.create do |operation, poly|
43+
operation.valid?.should eq(true)
44+
poly.should_not be_nil
4545
end
4646
end
4747

spec/avram/queryable_spec.cr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,13 @@ describe Avram::Queryable do
484484

485485
it "wraps complex queries" do
486486
query = UserQuery.new.where { |user_q|
487-
user_q.where { |q|
488-
q.age(25).or(&.age(26))
489-
}.where { |q|
490-
q.name("Billy").or(&.name("Tommy"))
487+
user_q.where { |scope|
488+
scope.age(25).or(&.age(26))
489+
}.where { |scope|
490+
scope.name("Billy").or(&.name("Tommy"))
491491
}
492-
}.or { |q|
493-
q.nickname("Strange")
492+
}.or { |scope|
493+
scope.nickname("Strange")
494494
}.query
495495

496496
query.statement.should eq %(SELECT #{User::COLUMN_SQL} FROM users WHERE ( ( "users"."age" = $1 OR "users"."age" = $2 ) AND ( "users"."name" = $3 OR "users"."name" = $4 ) ) OR "users"."nickname" = $5)
@@ -507,12 +507,12 @@ describe Avram::Queryable do
507507
end
508508

509509
it "doesn't add parenthesis when query to wrap is provided" do
510-
query = UserQuery.new.name("Susan").where do |q|
510+
query = UserQuery.new.name("Susan").where do |scope|
511511
some_condition = false
512512
if some_condition
513-
q.name("john")
513+
scope.name("john")
514514
else
515-
q
515+
scope
516516
end
517517
end.age(25).query
518518

spec/lucky/support/context_helper.cr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# ameba:disable Lint/SpecFilename
12
module ContextHelper
23
extend self
34

0 commit comments

Comments
 (0)