mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	Exclude reporting type declarations passed as call arguments
This commit is contained in:
		
							parent
							
								
									28fafea19f
								
							
						
					
					
						commit
						a79e711fae
					
				
					 2 changed files with 20 additions and 5 deletions
				
			
		|  | @ -388,19 +388,29 @@ module Ameba::Rule::Lint | ||||||
|           CRYSTAL |           CRYSTAL | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       it "doesn't report if this is a record declaration" do |       it "doesn't report record declaration" do | ||||||
|         expect_no_issues subject, <<-CRYSTAL |         expect_no_issues subject, <<-CRYSTAL | ||||||
|  |           record Foo, foo : String | ||||||
|           record Foo, foo = "foo" |           record Foo, foo = "foo" | ||||||
|           CRYSTAL |           CRYSTAL | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       it "doesn't report if this is a record declaration (generics)" do |       it "doesn't report record declarations (generics)" do | ||||||
|         expect_no_issues subject, <<-CRYSTAL |         expect_no_issues subject, <<-CRYSTAL | ||||||
|           record Foo(T), foo : T |           record Foo(T), foo : T | ||||||
|  |           record Foo(T), foo = T.new | ||||||
|           CRYSTAL |           CRYSTAL | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       it "doesn't report if this is an accessor declaration" do |       it "doesn't report type declaration as a call argument" do | ||||||
|  |         expect_no_issues subject, <<-CRYSTAL | ||||||
|  |           foo Foo(T), foo : T | ||||||
|  |           foo Foo, foo : Nil | ||||||
|  |           foo foo : String, bar : Int32? | ||||||
|  |           CRYSTAL | ||||||
|  |       end | ||||||
|  | 
 | ||||||
|  |       it "doesn't report accessor declarations" do | ||||||
|         accessor_macros = %w[setter class_setter] |         accessor_macros = %w[setter class_setter] | ||||||
|         %w[getter class_getter property class_property].each do |name| |         %w[getter class_getter property class_property].each do |name| | ||||||
|           accessor_macros << name |           accessor_macros << name | ||||||
|  |  | ||||||
|  | @ -43,8 +43,13 @@ module Ameba::Rule::Lint | ||||||
| 
 | 
 | ||||||
|       scope.variables.each do |var| |       scope.variables.each do |var| | ||||||
|         next if var.ignored? || var.used_in_macro? || var.captured_by_block? |         next if var.ignored? || var.used_in_macro? || var.captured_by_block? | ||||||
|         next if exclude_type_declarations? && scope.assigns_type_dec?(var.name) |         if scope.assigns_type_dec?(var.name) | ||||||
| 
 |           next if exclude_type_declarations? | ||||||
|  |           # exclude type declarations within calls | ||||||
|  |           if node.is_a?(Crystal::Expressions) | ||||||
|  |             next if node.expressions.first?.is_a?(Crystal::Call) | ||||||
|  |           end | ||||||
|  |         end | ||||||
|         var.assignments.each do |assign| |         var.assignments.each do |assign| | ||||||
|           next if assign.referenced? |           next if assign.referenced? | ||||||
|           issue_for assign.target_node, MSG % var.name |           issue_for assign.target_node, MSG % var.name | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue