Skip to content

Commit

Permalink
Merge pull request #425 from crystal-ameba/prepare-release-1.6.0
Browse files Browse the repository at this point in the history
Prepare release 1.6.0
  • Loading branch information
Sija authored Nov 17, 2023
2 parents 52a3e47 + 10b577d commit 5aac63e
Show file tree
Hide file tree
Showing 52 changed files with 209 additions and 192 deletions.
2 changes: 1 addition & 1 deletion .ameba.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Documentation/DocumentationAdmonition:

Lint/Typos:
Excluded:
- spec/ameba/rule/lint/typos_spec.cr
- spec/ameba/rule/lint/typos_spec.cr
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ Add this to your application's `shard.yml`:
development_dependencies:
ameba:
github: crystal-ameba/ameba
version: ~> 1.4.0
```
Build `bin/ameba` binary within your project directory while running `shards install`.
Expand Down Expand Up @@ -165,7 +164,7 @@ Generate new file by running `ameba --gen-config`.
**List of sources to run Ameba on can be configured globally via:**

- `Globs` section - an array of wildcards (or paths) to include to the
inspection. Defaults to `%w(**/*.cr !lib)`, meaning it includes all project
inspection. Defaults to `%w[**/*.cr !lib]`, meaning it includes all project
files with `*.cr` extension except those which exist in `lib` folder.
- `Excluded` section - an array of wildcards (or paths) to exclude from the
source list defined by `Globs`. Defaults to an empty array.
Expand All @@ -186,8 +185,8 @@ Excluded:
``` yaml
Style/RedundantBegin:
Excluded:
- src/server/processor.cr
- src/server/api.cr
- src/server/processor.cr
- src/server/api.cr
```

### Rules
Expand Down Expand Up @@ -240,4 +239,4 @@ time = Time.epoch(1483859302) # ameba:disable Style, Lint
## Contributors

- [veelenga](https://github.com/veelenga) Vitalii Elenhaupt - creator, maintainer
- [Sija](https://github.com/Sija) Sijawusz Pur Rahnama - maintainer
- [Sija](https://github.com/Sija) Sijawusz Pur Rahnama - contributor, maintainer
7 changes: 4 additions & 3 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
name: ameba
version: 1.5.0
version: 1.6.0

authors:
- Vitalii Elenhaupt <[email protected]>
- Sijawusz Pur Rahnama <[email protected]>

targets:
ameba:
main: src/cli.cr

scripts:
# TODO: remove pre-compiled executable in future releases
postinstall: shards build -Dpreview_mt

# TODO: remove pre-compiled executable in future releases
executables:
- ameba
- ameba.cr

crystal: "~> 1.9.0"
crystal: ~> 1.10

license: MIT
37 changes: 37 additions & 0 deletions spec/ameba/ast/util_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,43 @@ module Ameba::AST
end
end

describe "#static/dynamic_literal?" do
[
Crystal::ArrayLiteral.new,
Crystal::ArrayLiteral.new([Crystal::StringLiteral.new("foo")] of Crystal::ASTNode),
Crystal::BoolLiteral.new(false),
Crystal::CharLiteral.new('a'),
Crystal::HashLiteral.new,
Crystal::NamedTupleLiteral.new,
Crystal::NilLiteral.new,
Crystal::NumberLiteral.new(42),
Crystal::RegexLiteral.new(Crystal::StringLiteral.new("")),
Crystal::StringLiteral.new("foo"),
Crystal::SymbolLiteral.new("foo"),
Crystal::TupleLiteral.new([] of Crystal::ASTNode),
Crystal::TupleLiteral.new([Crystal::StringLiteral.new("foo")] of Crystal::ASTNode),
Crystal::RangeLiteral.new(
Crystal::NumberLiteral.new(0),
Crystal::NumberLiteral.new(10),
true),
].each do |literal|
it "properly identifies static node #{literal}" do
subject.static_literal?(literal).should be_true
subject.dynamic_literal?(literal).should be_false
end
end

[
Crystal::ArrayLiteral.new([Crystal::Path.new(%w[IO])] of Crystal::ASTNode),
Crystal::TupleLiteral.new([Crystal::Path.new(%w[IO])] of Crystal::ASTNode),
].each do |literal|
it "properly identifies dynamic node #{literal}" do
subject.dynamic_literal?(literal).should be_true
subject.static_literal?(literal).should be_false
end
end
end

describe "#node_source" do
it "returns original source of the node" do
s = <<-CRYSTAL
Expand Down
12 changes: 6 additions & 6 deletions spec/ameba/base_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Ameba::Rule
end

it "contains rules across all the available groups" do
Rule.rules.map(&.group_name).uniq!.reject!(&.empty?).sort.should eq %w(
Rule.rules.map(&.group_name).uniq!.reject!(&.empty?).sort.should eq %w[
Ameba
Documentation
Layout
Expand All @@ -19,7 +19,7 @@ module Ameba::Rule
Naming
Performance
Style
)
]
end
end

Expand Down Expand Up @@ -50,25 +50,25 @@ module Ameba::Rule

it "returns false if source is not excluded from this rule" do
rule = DummyRule.new
rule.excluded = %w(some_source.cr)
rule.excluded = %w[some_source.cr]
rule.excluded?(Source.new "", "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 = %w[source.cr]
rule.excluded?(Source.new "", "source.cr").should be_true
end

it "returns true if source matches the wildcard" do
rule = DummyRule.new
rule.excluded = %w(**/*.cr)
rule.excluded = %w[**/*.cr]
rule.excluded?(Source.new "", __FILE__).should be_true
end

it "returns false if source does not match the wildcard" do
rule = DummyRule.new
rule.excluded = %w(*_spec.cr)
rule.excluded = %w[*_spec.cr]
rule.excluded?(Source.new "", "source.cr").should be_false
end
end
Expand Down
56 changes: 28 additions & 28 deletions spec/ameba/cli/cmd_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ module Ameba::Cli
describe "Cmd" do
describe ".run" do
it "runs ameba" do
r = Cli.run %w(-f silent -c spec/fixtures/config.yml spec/fixtures/source.cr)
r = Cli.run %w[-f silent -c spec/fixtures/config.yml spec/fixtures/source.cr]
r.should be_nil
end
end

describe ".parse_args" do
%w(-s --silent).each do |flag|
%w[-s --silent].each do |flag|
it "accepts #{flag} flag" do
c = Cli.parse_args [flag]
c.formatter.should eq :silent
end
end

%w(-c --config).each do |flag|
%w[-c --config].each do |flag|
it "accepts #{flag} flag" do
c = Cli.parse_args [flag, "config.yml"]
c.config.should eq Path["config.yml"]
end
end

%w(-f --format).each do |flag|
%w[-f --format].each do |flag|
it "accepts #{flag} flag" do
c = Cli.parse_args [flag, "my-formatter"]
c.formatter.should eq "my-formatter"
Expand All @@ -34,68 +34,68 @@ module Ameba::Cli

it "accepts --only flag" do
c = Cli.parse_args ["--only", "RULE1,RULE2"]
c.only.should eq %w(RULE1 RULE2)
c.only.should eq %w[RULE1 RULE2]
end

it "accepts --except flag" do
c = Cli.parse_args ["--except", "RULE1,RULE2"]
c.except.should eq %w(RULE1 RULE2)
c.except.should eq %w[RULE1 RULE2]
end

it "defaults rules? flag to false" do
c = Cli.parse_args %w(spec/fixtures/source.cr)
c = Cli.parse_args %w[spec/fixtures/source.cr]
c.rules?.should be_false
end

it "defaults skip_reading_config? flag to false" do
c = Cli.parse_args %w(spec/fixtures/source.cr)
c = Cli.parse_args %w[spec/fixtures/source.cr]
c.skip_reading_config?.should be_false
end

it "accepts --rules flag" do
c = Cli.parse_args %w(--rules)
c = Cli.parse_args %w[--rules]
c.rules?.should eq true
end

it "defaults all? flag to false" do
c = Cli.parse_args %w(spec/fixtures/source.cr)
c = Cli.parse_args %w[spec/fixtures/source.cr]
c.all?.should be_false
end

it "accepts --all flag" do
c = Cli.parse_args %w(--all)
c = Cli.parse_args %w[--all]
c.all?.should eq true
end

it "accepts --gen-config flag" do
c = Cli.parse_args %w(--gen-config)
c = Cli.parse_args %w[--gen-config]
c.formatter.should eq :todo
end

it "accepts --no-color flag" do
c = Cli.parse_args %w(--no-color)
c = Cli.parse_args %w[--no-color]
c.colors?.should be_false
end

it "accepts --without-affected-code flag" do
c = Cli.parse_args %w(--without-affected-code)
c = Cli.parse_args %w[--without-affected-code]
c.without_affected_code?.should be_true
end

it "doesn't disable colors by default" do
c = Cli.parse_args %w(--all)
c = Cli.parse_args %w[--all]
c.colors?.should be_true
end

it "ignores --config if --gen-config flag passed" do
c = Cli.parse_args %w(--gen-config --config my_config.yml)
c = Cli.parse_args %w[--gen-config --config my_config.yml]
c.formatter.should eq :todo
c.skip_reading_config?.should be_true
end

describe "-e/--explain" do
it "configures file/line/column" do
c = Cli.parse_args %w(--explain spec/fixtures/source.cr:3:5)
c = Cli.parse_args %w[--explain spec/fixtures/source.cr:3:5]

location_to_explain = c.location_to_explain.should_not be_nil
location_to_explain[:file].should eq "spec/fixtures/source.cr"
Expand All @@ -105,59 +105,59 @@ module Ameba::Cli

it "raises an error if location is not valid" do
expect_raises(Exception, "location should have PATH:line:column") do
Cli.parse_args %w(--explain spec/fixtures/source.cr:3)
Cli.parse_args %w[--explain spec/fixtures/source.cr:3]
end
end

it "raises an error if line number is not valid" do
expect_raises(Exception, "location should have PATH:line:column") do
Cli.parse_args %w(--explain spec/fixtures/source.cr:a:3)
Cli.parse_args %w[--explain spec/fixtures/source.cr:a:3]
end
end

it "raises an error if column number is not valid" do
expect_raises(Exception, "location should have PATH:line:column") do
Cli.parse_args %w(--explain spec/fixtures/source.cr:3:&)
Cli.parse_args %w[--explain spec/fixtures/source.cr:3:&]
end
end

it "raises an error if line/column are missing" do
expect_raises(Exception, "location should have PATH:line:column") do
Cli.parse_args %w(--explain spec/fixtures/source.cr)
Cli.parse_args %w[--explain spec/fixtures/source.cr]
end
end
end

context "--fail-level" do
it "configures fail level Convention" do
c = Cli.parse_args %w(--fail-level convention)
c = Cli.parse_args %w[--fail-level convention]
c.fail_level.should eq Severity::Convention
end

it "configures fail level Warning" do
c = Cli.parse_args %w(--fail-level Warning)
c = Cli.parse_args %w[--fail-level Warning]
c.fail_level.should eq Severity::Warning
end

it "configures fail level Error" do
c = Cli.parse_args %w(--fail-level error)
c = Cli.parse_args %w[--fail-level error]
c.fail_level.should eq Severity::Error
end

it "raises if fail level is incorrect" do
expect_raises(Exception, "Incorrect severity name JohnDoe") do
Cli.parse_args %w(--fail-level JohnDoe)
Cli.parse_args %w[--fail-level JohnDoe]
end
end
end

it "accepts unknown args as globs" do
c = Cli.parse_args %w(source1.cr source2.cr)
c.globs.should eq %w(source1.cr source2.cr)
c = Cli.parse_args %w[source1.cr source2.cr]
c.globs.should eq %w[source1.cr source2.cr]
end

it "accepts one unknown arg as explain location if it has correct format" do
c = Cli.parse_args %w(source.cr:3:22)
c = Cli.parse_args %w[source.cr:3:22]

location_to_explain = c.location_to_explain.should_not be_nil
location_to_explain[:file].should eq "source.cr"
Expand Down
Loading

0 comments on commit 5aac63e

Please sign in to comment.