-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #351 from crystal-ameba/fix/useless-assign-type-def
fix(lint): useless assignment for type definition
- Loading branch information
Showing
8 changed files
with
128 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require "../../../spec_helper" | ||
|
||
module Ameba::AST | ||
describe TypeDecVariable do | ||
var = Crystal::Var.new("foo") | ||
declared_type = Crystal::Path.new("String") | ||
type_dec = Crystal::TypeDeclaration.new(var, declared_type) | ||
|
||
describe "#initialize" do | ||
it "creates a new type dec variable" do | ||
variable = TypeDecVariable.new(type_dec) | ||
variable.node.should_not be_nil | ||
end | ||
end | ||
|
||
describe "#name" do | ||
it "returns var name" do | ||
variable = TypeDecVariable.new(type_dec) | ||
variable.name.should eq var.name | ||
end | ||
|
||
it "raises if type declaration is incorrect" do | ||
type_dec = Crystal::TypeDeclaration.new(declared_type, declared_type) | ||
|
||
expect_raises(Exception, "Unsupported var node type: Crystal::Path") do | ||
TypeDecVariable.new(type_dec).name | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Ameba::AST | ||
class TypeDecVariable | ||
getter node : Crystal::TypeDeclaration | ||
|
||
delegate location, to: @node | ||
delegate end_location, to: @node | ||
delegate to_s, to: @node | ||
|
||
def initialize(@node) | ||
end | ||
|
||
def name | ||
case var = @node.var | ||
when Crystal::Var, Crystal::InstanceVar, Crystal::ClassVar, Crystal::Global | ||
var.name | ||
else | ||
raise "Unsupported var node type: #{var.class}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters