Merge branch 'develop'

This commit is contained in:
Vitalii Elenhaupt 2020-08-26 22:46:03 +03:00
commit f8d57345d4
No known key found for this signature in database
GPG key ID: CD0BF17825928BC0
5 changed files with 33 additions and 3 deletions

View file

@ -1,11 +1,11 @@
FROM alpine:3.8 as builder FROM alpine:3.12 as builder
RUN apk add --update crystal shards openssl-dev yaml-dev musl-dev make RUN apk add --update crystal shards openssl-dev yaml-dev musl-dev make
RUN mkdir /ameba RUN mkdir /ameba
WORKDIR /ameba WORKDIR /ameba
COPY . /ameba/ COPY . /ameba/
RUN make clean && make RUN make clean && make
FROM alpine:3.8 FROM alpine:3.12
RUN apk add --update openssl yaml pcre gc libevent libgcc RUN apk add --update openssl yaml pcre gc libevent libgcc
RUN mkdir /src RUN mkdir /src
WORKDIR /src WORKDIR /src

View file

@ -140,6 +140,23 @@ module Ameba::AST
end end
end end
describe "#ignored?" do
it "is true if variable is ignored" do
variable = Variable.new(Crystal::Var.new("_var"), scope)
variable.ignored?.should be_true
end
it "is false if variable is not ignored" do
variable = Variable.new(Crystal::Var.new("v_ar"), scope)
variable.ignored?.should be_false
end
it "is true if variable is a black hole" do
variable = Variable.new(Crystal::Var.new("_"), scope)
variable.ignored?.should be_true
end
end
describe "#eql?" do describe "#eql?" do
var = Crystal::Var.new("foo").at(Crystal::Location.new(nil, 1, 2)) var = Crystal::Var.new("foo").at(Crystal::Location.new(nil, 1, 2))
variable = Variable.new var, scope variable = Variable.new var, scope

View file

@ -54,6 +54,14 @@ module Ameba::Rule::Lint
subject.catch(s).should_not be_valid subject.catch(s).should_not be_valid
end end
it "does not report ignored assigments" do
s = Source.new %(
payload, _header = decode
puts payload
)
subject.catch(s).should be_valid
end
it "reports a useless assignment in a proc inside a block" do it "reports a useless assignment in a proc inside a block" do
s = Source.new %( s = Source.new %(
def method def method

View file

@ -143,6 +143,11 @@ module Ameba::AST
end end
end end
# Returns true if the name starts with '_', false if not.
def ignored?
name.starts_with? '_'
end
# Returns true if the `node` represents exactly # Returns true if the `node` represents exactly
# the same Crystal node as `@node`. # the same Crystal node as `@node`.
def eql?(node) def eql?(node)

View file

@ -39,7 +39,7 @@ module Ameba::Rule::Lint
def test(source, node, scope : AST::Scope) def test(source, node, scope : AST::Scope)
scope.variables.each do |var| scope.variables.each do |var|
next if var.captured_by_block? || var.used_in_macro? next if var.captured_by_block? || var.used_in_macro? || var.ignored?
var.assignments.each do |assign| var.assignments.each do |assign|
next if assign.referenced? || assign.transformed? next if assign.referenced? || assign.transformed?