mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	Add UselessAssign#exclude_type_declarations
				
					
				
			This commit is contained in:
		
							parent
							
								
									aeffa6ad00
								
							
						
					
					
						commit
						5a24f1eba5
					
				
					 2 changed files with 25 additions and 0 deletions
				
			
		|  | @ -3,6 +3,7 @@ require "../../../spec_helper" | ||||||
| module Ameba::Rule::Lint | module Ameba::Rule::Lint | ||||||
|   describe UselessAssign do |   describe UselessAssign do | ||||||
|     subject = UselessAssign.new |     subject = UselessAssign.new | ||||||
|  |       .tap(&.exclude_type_declarations = false) | ||||||
| 
 | 
 | ||||||
|     it "does not report used assignments" do |     it "does not report used assignments" do | ||||||
|       expect_no_issues subject, <<-CRYSTAL |       expect_no_issues subject, <<-CRYSTAL | ||||||
|  | @ -1007,6 +1008,27 @@ module Ameba::Rule::Lint | ||||||
|       end |       end | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  |     context "#properties" do | ||||||
|  |       context "#exclude_type_declarations" do | ||||||
|  |         it "doesn't report type declarations if enabled" do | ||||||
|  |           rule = UselessAssign.new | ||||||
|  |           rule.exclude_type_declarations = true | ||||||
|  | 
 | ||||||
|  |           expect_no_issues rule, <<-CRYSTAL | ||||||
|  |             a : String? | ||||||
|  | 
 | ||||||
|  |             class Foo | ||||||
|  |               b : String? | ||||||
|  |             end | ||||||
|  | 
 | ||||||
|  |             def foo | ||||||
|  |               c : String? | ||||||
|  |             end | ||||||
|  |             CRYSTAL | ||||||
|  |         end | ||||||
|  |       end | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|     context "uninitialized" do |     context "uninitialized" do | ||||||
|       it "reports if uninitialized assignment is not referenced at a top level" do |       it "reports if uninitialized assignment is not referenced at a top level" do | ||||||
|         expect_issue subject, <<-CRYSTAL |         expect_issue subject, <<-CRYSTAL | ||||||
|  |  | ||||||
|  | @ -24,10 +24,12 @@ module Ameba::Rule::Lint | ||||||
|   # ``` |   # ``` | ||||||
|   # Lint/UselessAssign: |   # Lint/UselessAssign: | ||||||
|   #   Enabled: true |   #   Enabled: true | ||||||
|  |   #   ExcludeTypeDeclarations: false | ||||||
|   # ``` |   # ``` | ||||||
|   class UselessAssign < Base |   class UselessAssign < Base | ||||||
|     properties do |     properties do | ||||||
|       description "Disallows useless variable assignments" |       description "Disallows useless variable assignments" | ||||||
|  |       exclude_type_declarations false | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     MSG = "Useless assignment to variable `%s`" |     MSG = "Useless assignment to variable `%s`" | ||||||
|  | @ -39,6 +41,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.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) | ||||||
| 
 | 
 | ||||||
|         var.assignments.each do |assign| |         var.assignments.each do |assign| | ||||||
|           next if assign.referenced? |           next if assign.referenced? | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue