Skip to content

Commit

Permalink
Merge pull request #5 from snacks02/ameba
Browse files Browse the repository at this point in the history
Add Ameba for linting
  • Loading branch information
eliasjpr authored Sep 23, 2024
2 parents f98ac46 + c2fd88b commit 4402d11
Show file tree
Hide file tree
Showing 24 changed files with 242 additions and 233 deletions.
5 changes: 5 additions & 0 deletions .ameba.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Documentation/DocumentationAdmonition:
Enabled: false

Lint/NotNil:
Enabled: false
2 changes: 2 additions & 0 deletions .github/workflows/crystal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
run: shards install
- name: Check code style
run: crystal tool format --check
- name: Check code linting with Ameba
run: bin/ameba
- name: Run tests
env:
DATABASE_URL: postgres://example:example@postgres:5432/example
Expand Down
2 changes: 2 additions & 0 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ dependencies:
tallboy:
github: epoch/tallboy
development_dependencies:
ameba:
github: crystal-ameba/ameba
sqlite3:
github: crystal-lang/crystal-sqlite3
mysql:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions spec/table_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe Cql::Table do

customer = CustomerModel.new(1, "John", "New York", 100)

insert_query = TableDB.insert.into(:customers).values(
TableDB.insert.into(:customers).values(
id: customer.id,
name: customer.name,
city: customer.city,
Expand Down Expand Up @@ -40,7 +40,7 @@ describe Cql::Table do
count_query = TableDB.query.from(:customers).count
count_query.first!(as: Int32).should eq 2

result = TableDB.delete.from(:customers).commit
TableDB.delete.from(:customers).commit
count_query.first!(as: Int32).should eq 0
end

Expand All @@ -50,7 +50,7 @@ describe Cql::Table do
check_query = "SELECT name FROM sqlite_master WHERE type='table' AND name='#{table}'"

expect_raises(DB::NoResultsError) do
name = TableDB.db.query_one(check_query, as: String)
TableDB.db.query_one(check_query, as: String)
end
end
end
8 changes: 4 additions & 4 deletions src/alter_table.cr
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ module Cql
# sql = to_sql(visitor)
# ```
def to_sql(visitor : Expression::Visitor)
String::Builder.build do |sb|
String.build do |string|
@actions.each do |action|
case action
when Expression::CreateIndex, Expression::DropIndex, Expression::RenameTable
sb << action.accept(visitor)
string << action.accept(visitor)
else
sb << Expression::AlterTable.new(@table, action).accept(visitor)
string << Expression::AlterTable.new(@table, action).accept(visitor)
end
sb << ";\n"
string << ";\n"
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions src/dialects/mysql_dialect.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ module Expression
end

def auto_increment_primary_key(column : Cql::BaseColumn, col_type : String) : String
String::Builder.build do |sb|
sb << column.name
sb << " "
sb << col_type
sb << " PRIMARY KEY"
sb << " AUTO_INCREMENT" if column.auto_increment?
String.build do |string|
string << column.name
string << " "
string << col_type
string << " PRIMARY KEY"
string << " AUTO_INCREMENT" if column.auto_increment?
end
end

Expand Down
14 changes: 7 additions & 7 deletions src/dialects/postgres_dialect.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ module Expression
end

def auto_increment_primary_key(column : Cql::BaseColumn, col_type : String) : String
String::Builder.build do |sb|
sb << column.name
sb << " "
sb << col_type
sb << " GENERATED"
sb << " ALWAYS" if column.auto_increment?
sb << " AS IDENTITY PRIMARY KEY"
String.build do |string|
string << column.name
string << " "
string << col_type
string << " GENERATED"
string << " ALWAYS" if column.auto_increment?
string << " AS IDENTITY PRIMARY KEY"
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/dialects/sqlite_dialect.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module Expression
end

def drop_foreign_key(table_name : String, constraint_name : String) : String
message = <<-MSG
<<-MSG
SQLite does not support dropping foreign keys directly via the ALTER TABLE
statement. You need to recreate the table without the foreign key constraint.
Expand Down
24 changes: 12 additions & 12 deletions src/expression/aggregator_builder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ module Expression
def initialize(@aggregate_function : Condition)
end

def >(value : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, ">", value))
def >(other : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, ">", other))
end

def <(value : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "<", value))
def <(other : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "<", other))
end

def >=(value : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, ">=", value))
def >=(other : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, ">=", other))
end

def <=(value : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "<=", value))
def <=(other : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "<=", other))
end

def ==(value : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "=", value))
def ==(other : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "=", other))
end

def !=(value : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "!=", value))
def !=(other : Column | DB::Any)
ConditionBuilder.new(CompareCondition.new(@aggregate_function, "!=", other))
end
end
end
Loading

0 comments on commit 4402d11

Please sign in to comment.