Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
aa1dbf1
Tweak rules’ docs a bit moar
Sija Feb 12, 2025
f910703
Use the unescaped literal value in specs
Sija Feb 12, 2025
28f9df5
Minor spec cleanups
Sija Feb 12, 2025
fc19f01
Use trailing `if` for better readability
Sija Feb 14, 2025
269871f
Add additional test case
Sija Feb 14, 2025
216e132
Call `super` instead of duplicating the method body
Sija Feb 14, 2025
ba14e77
Fix example in docs for `Lint/AmbiguousAssignment` rule
Sija Feb 16, 2025
ded99da
Fix case where only named arguments are passed to `issue_for` macro
Sija Feb 16, 2025
9ee7f06
Tweak specs for `Style/ParenthesesAroundCondition` rule
Sija Feb 17, 2025
cee0d8b
Optimize a bit `Lint/DuplicatedRequire` rule
Sija Feb 18, 2025
ef01426
Don’t use parentheses when calling `issue_for` unless necessary
Sija Feb 18, 2025
a3dcc39
Simplify code in `Lint/ShadowedException` rule
Sija Feb 18, 2025
671d978
Use `%{}` interpolation variant consistently
Sija Feb 19, 2025
e15a59d
Use `ASTNode#accept(Visitor)` consistently
Sija Feb 19, 2025
58ee592
Make `Typos::Typo` record private
Sija Feb 19, 2025
b806aa1
Spec helper cleanups
Sija Feb 25, 2025
956e0c6
Assign variables within the `describe <class>` block
Sija Feb 25, 2025
1b5bd5d
Tweak code comment
Sija Feb 26, 2025
bc4a444
Fix `Style/HeredocIndent` rule docs
Sija Feb 28, 2025
44f5f24
Cleanup doc comments in `Crystal::Location` extensions
Sija Feb 28, 2025
fdefe16
Simplify code in `Style/HeredocIndent` rule
Sija Feb 28, 2025
f9947d4
Simplify code in `Lint/AmbiguousAssignment` rule
Sija Feb 28, 2025
e6faeca
Remove unused code
Sija Feb 28, 2025
1c043e8
Add backticks around a keyword in rule description
Sija Feb 28, 2025
0b64799
Call `#accept_children(visitor)` instead
Sija Feb 28, 2025
2eebf99
Cleanup redundant definitions in `AST::ImplicitReturnVisitor`
Sija Feb 28, 2025
362a032
Simplify code in `AST::ImplicitReturnVisitor`
Sija Mar 1, 2025
0c87d17
Add `begin`…`ensure` to be on the safe side
Sija Mar 1, 2025
c3e152a
Stylistic refactors
Sija Mar 1, 2025
55b136a
Cleanup `Config#update_rules` API
Sija Mar 1, 2025
98b76d7
Cleanup `Source::Rewriter::Action` a bit
Sija Mar 3, 2025
c436ac0
Reorder method definitions in `Style/VerboseBlock`
Sija Mar 3, 2025
1d3e1f2
Tweak reported location in `Documentation/DocumentationAdmonition` rule
Sija Mar 14, 2025
fb1a821
Fix spec to use interpolation-less variant of heredoc
Sija Mar 14, 2025
bf04db8
Slight test case refactor
Sija Mar 14, 2025
8bea249
Add missing `:` in YAML configuration examples
Sija Mar 14, 2025
2a04355
Apply suggestions from code review
Sija Mar 22, 2025
ce5fced
Cleanup test case
Sija Apr 5, 2025
8f889c7
Make `@code` argument passed to `Source#initialize` optional
Sija Apr 7, 2025
79b2136
Make the error message include the end range
Sija Apr 7, 2025
3b9c8dc
Add pending test case for autocorrect-incompatible rules correction
Sija Apr 7, 2025
83d6fc1
Rename `Source#correct?` to `#correct!` to avoid confusion re: whethe…
Sija Apr 7, 2025
04cae57
Merge branch 'master' into some-moar-refactors
Sija Jun 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions spec/ameba/ast/visitors/node_visitor_spec.cr
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
require "../../../spec_helper"

module Ameba::AST
rule = DummyRule.new
source = Source.new ""

describe NodeVisitor do
describe "visit" do
it "allow to visit ASTNode" do
visitor = NodeVisitor.new rule, source
rule = DummyRule.new
visitor = NodeVisitor.new rule, Source.new

nodes = Crystal::Parser.new("").parse
nodes.accept visitor
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require "../../../spec_helper"

module Ameba::AST
source = Source.new ""
rule = RedundantControlExpressionRule.new

describe RedundantControlExpressionVisitor do
source = Source.new
rule = RedundantControlExpressionRule.new

node = as_node <<-CRYSTAL
a = 1
b = 2
Expand Down
8 changes: 4 additions & 4 deletions spec/ameba/base_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ module Ameba::Rule

describe "#excluded?" do
it "returns false if a rule does no have a list of excluded source" do
DummyRule.new.excluded?(Source.new "", "source.cr").should_not be_true
DummyRule.new.excluded?(Source.new path: "source.cr").should_not be_true
end

it "returns false if source is not excluded from this rule" do
rule = DummyRule.new
rule.excluded = %w[some_source.cr]
rule.excluded?(Source.new "", "another_source.cr").should_not be_true
rule.excluded?(Source.new path: "another_source.cr").should_not be_true
end

it "returns true if source is excluded from this rule" do
rule = DummyRule.new
rule.excluded = %w[source.cr]
rule.excluded?(Source.new "", "source.cr").should be_true
rule.excluded?(Source.new path: "source.cr").should be_true
end

it "returns true if source matches the wildcard" do
Expand All @@ -70,7 +70,7 @@ module Ameba::Rule
it "returns false if source does not match the wildcard" do
rule = DummyRule.new
rule.excluded = %w[*_spec.cr]
rule.excluded?(Source.new "", "source.cr").should be_false
rule.excluded?(Source.new path: "source.cr").should be_false
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/ameba/formatter/disabled_formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ module Ameba::Formatter

describe "#finished" do
it "writes a final message" do
subject.finished [Source.new ""]
subject.finished [Source.new]
output.to_s.should contain "Disabled rules using inline directives:"
end

it "writes disabled rules if any" do
Colorize.enabled = false

path = "source.cr"
s = Source.new("", path).tap do |source|
s = Source.new(path: path).tap do |source|
source.add_issue(ErrorRule.new, {1, 2}, message: "ErrorRule", status: :disabled)
source.add_issue(NamedRule.new, location: {2, 2}, message: "NamedRule", status: :disabled)
end
Expand All @@ -32,7 +32,7 @@ module Ameba::Formatter
end

it "does not write not-disabled rules" do
s = Source.new("", "source.cr").tap do |source|
s = Source.new(path: "source.cr").tap do |source|
source.add_issue(ErrorRule.new, {1, 2}, "ErrorRule")
source.add_issue(NamedRule.new, location: {2, 2},
message: "NamedRule", status: :disabled)
Expand Down
14 changes: 7 additions & 7 deletions spec/ameba/formatter/dot_formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ module Ameba::Formatter

describe "#started" do
it "writes started message" do
subject.started [Source.new ""]
subject.started [Source.new]
output.to_s.should eq "Inspecting 1 file\n\n"
end
end

describe "#source_finished" do
it "writes valid source" do
subject.source_finished Source.new ""
subject.source_finished Source.new
output.to_s.should contain "."
end

it "writes invalid source" do
s = Source.new ""
s = Source.new
s.add_issue DummyRule.new, Crystal::Nop.new, "message"
subject.source_finished s
output.to_s.should contain "F"
Expand All @@ -32,18 +32,18 @@ module Ameba::Formatter

describe "#finished" do
it "writes a final message" do
subject.finished [Source.new ""]
subject.finished [Source.new]
output.to_s.should contain "1 inspected, 0 failures"
end

it "writes the elapsed time" do
subject.finished [Source.new ""]
subject.finished [Source.new]
output.to_s.should contain "Finished in"
end

context "when issues found" do
it "writes each issue" do
s = Source.new("").tap do |source|
s = Source.new.tap do |source|
source.add_issue(DummyRule.new, {1, 1}, "DummyRuleError")
source.add_issue(NamedRule.new, {1, 2}, "NamedRuleError")
end
Expand Down Expand Up @@ -96,7 +96,7 @@ module Ameba::Formatter
end

it "does not write disabled issues" do
s = Source.new("").tap do |source|
s = Source.new.tap do |source|
source.add_issue(DummyRule.new, {1, 1}, "DummyRuleError", status: :disabled)
source.add_issue(NamedRule.new, {1, 2}, "NamedRuleError")
end
Expand Down
2 changes: 1 addition & 1 deletion spec/ameba/formatter/flycheck_formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Ameba::Formatter

context "problems not found" do
it "reports nothing" do
subject.source_finished Source.new ""
subject.source_finished Source.new
subject.output.to_s.empty?.should be_true
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/ameba/formatter/github_actions_formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ module Ameba::Formatter

describe "#source_finished" do
it "writes valid source" do
source = Source.new "", "/path/to/file.cr"
source = Source.new path: "/path/to/file.cr"

subject.source_finished(source)
output.to_s.should be_empty
end

it "writes invalid source" do
source = Source.new "", "/path/to/file.cr"
source = Source.new path: "/path/to/file.cr"
location = Crystal::Location.new("/path/to/file.cr", 1, 2)

source.add_issue DummyRule.new, location, location, "message\n2nd line"
Expand All @@ -33,15 +33,15 @@ module Ameba::Formatter

describe "#finished" do
it "doesn't do anything if 'GITHUB_STEP_SUMMARY' ENV var is not set" do
subject.finished [Source.new ""]
subject.finished [Source.new]
output.to_s.should be_empty
end

it "writes a Markdown summary to a filename given in 'GITHUB_STEP_SUMMARY' ENV var" do
prev_summary = ENV["GITHUB_STEP_SUMMARY"]?
ENV["GITHUB_STEP_SUMMARY"] = summary_filename = File.tempname
begin
sources = [Source.new ""]
sources = [Source.new]

subject.started(sources)
subject.finished(sources)
Expand All @@ -67,7 +67,7 @@ module Ameba::Formatter
repo = ENV["GITHUB_REPOSITORY"]?
sha = ENV["GITHUB_SHA"]?
begin
source = Source.new("", "src/source.cr")
source = Source.new path: "src/source.cr"
source.add_issue(DummyRule.new, {1, 1}, {2, 1}, "DummyRuleError")
source.add_issue(DummyRule.new, {1, 1}, "DummyRuleError 2")
source.add_issue(NamedRule.new, {1, 2}, "NamedRuleError", status: :disabled)
Expand Down
20 changes: 10 additions & 10 deletions spec/ameba/formatter/json_formatter_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

private def get_result(sources = [Ameba::Source.new ""])
private def get_result(sources = [Ameba::Source.new])
output = IO::Memory.new
formatter = Ameba::Formatter::JSONFormatter.new output

Expand All @@ -25,36 +25,36 @@ module Ameba::Formatter

context "sources" do
it "shows path to the source" do
result = get_result [Source.new "", "source.cr"]
result = get_result [Source.new path: "source.cr"]
result["sources"][0]["path"].should eq "source.cr"
end

it "shows rule name" do
s = Source.new ""
s = Source.new
s.add_issue DummyRule.new, {1, 2}, "message1"

result = get_result [s]
result["sources"][0]["issues"][0]["rule_name"].should eq DummyRule.rule_name
end

it "shows severity" do
s = Source.new ""
s = Source.new
s.add_issue DummyRule.new, {1, 2}, "message"

result = get_result [s]
result["sources"][0]["issues"][0]["severity"].should eq "Convention"
end

it "shows a message" do
s = Source.new ""
s = Source.new
s.add_issue DummyRule.new, {1, 2}, "message"

result = get_result [s]
result["sources"][0]["issues"][0]["message"].should eq "message"
end

it "shows issue location" do
s = Source.new ""
s = Source.new
s.add_issue DummyRule.new, {1, 2}, "message"

result = get_result [s]
Expand All @@ -64,7 +64,7 @@ module Ameba::Formatter
end

it "shows issue end_location" do
s = Source.new ""
s = Source.new
s.add_issue DummyRule.new,
Crystal::Location.new("path", 3, 3),
Crystal::Location.new("path", 5, 4),
Expand All @@ -79,16 +79,16 @@ module Ameba::Formatter

context "summary" do
it "shows a target sources count" do
result = get_result [Source.new(""), Source.new("")]
result = get_result [Source.new, Source.new]
result["summary"]["target_sources_count"].should eq 2
end

it "shows issues count" do
s1 = Source.new ""
s1 = Source.new
s1.add_issue DummyRule.new, {1, 2}, "message1"
s1.add_issue DummyRule.new, {1, 2}, "message2"

s2 = Source.new ""
s2 = Source.new
s2.add_issue DummyRule.new, {1, 2}, "message3"

result = get_result [s1, s2]
Expand Down
4 changes: 2 additions & 2 deletions spec/ameba/formatter/todo_formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ module Ameba
context "problems not found" do
it "does not create file" do
with_formatter do |formatter|
file = formatter.finished [Source.new ""]
file = formatter.finished [Source.new]
file.should be_nil
end
end

it "reports a message saying file is not created" do
with_formatter do |formatter, io|
formatter.finished [Source.new ""]
formatter.finished [Source.new]
io.to_s.should contain "No issues found. File is not generated"
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/ameba/reportable_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Ameba
describe Reportable do
describe "#add_issue" do
it "adds a new issue for node" do
s = Source.new "", "source.cr"
s = Source.new path: "source.cr"
s.add_issue(DummyRule.new, Crystal::Nop.new, "Error!")

issue = s.issues.first
Expand All @@ -14,7 +14,7 @@ module Ameba
end

it "adds a new issue by line and column number" do
s = Source.new "", "source.cr"
s = Source.new path: "source.cr"
s.add_issue(DummyRule.new, {23, 2}, "Error!")

issue = s.issues.first
Expand All @@ -26,12 +26,12 @@ module Ameba

describe "#valid?" do
it "returns true if no issues added" do
s = Source.new "", "source.cr"
s = Source.new path: "source.cr"
s.should be_valid
end

it "returns false if there are issues added" do
s = Source.new "", "source.cr"
s = Source.new path: "source.cr"
s.add_issue DummyRule.new, {22, 2}, "ERROR!"
s.should_not be_valid
end
Expand Down
2 changes: 1 addition & 1 deletion spec/ameba/rule/base_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Ameba
describe Rule::Base do
describe "#catch" do
it "accepts and returns source" do
s = Source.new "", ""
s = Source.new
DummyRule.new.catch(s).should eq s
end
end
Expand Down
Loading
Loading