mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	Merge pull request #436 from crystal-ameba/cleanup-properties-macro
Make `RuleConfig#properties` accept only `Call` nodes
This commit is contained in:
		
						commit
						9bb6c9ac75
					
				
					 4 changed files with 18 additions and 17 deletions
				
			
		|  | @ -6,7 +6,7 @@ module Ameba | ||||||
|   # Dummy Rule which does nothing. |   # Dummy Rule which does nothing. | ||||||
|   class DummyRule < Rule::Base |   class DummyRule < Rule::Base | ||||||
|     properties do |     properties do | ||||||
|       description : String = "Dummy rule that does nothing." |       description "Dummy rule that does nothing." | ||||||
|       dummy true |       dummy true | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  | @ -92,7 +92,7 @@ module Ameba | ||||||
| 
 | 
 | ||||||
|   class PerfRule < Rule::Performance::Base |   class PerfRule < Rule::Performance::Base | ||||||
|     properties do |     properties do | ||||||
|       description : String = "Sample performance rule" |       description "Sample performance rule" | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     def test(source) |     def test(source) | ||||||
|  |  | ||||||
|  | @ -244,20 +244,20 @@ class Ameba::Config | ||||||
|     # Define rule properties |     # Define rule properties | ||||||
|     macro properties(&block) |     macro properties(&block) | ||||||
|       {% definitions = [] of NamedTuple %} |       {% definitions = [] of NamedTuple %} | ||||||
|       {% if block.body.is_a? Assign %} |       {% if (prop = block.body).is_a? Call %} | ||||||
|         {% definitions << {var: block.body.target, value: block.body.value} %} |         {% if (named_args = prop.named_args) && (type = named_args.select(&.name.== "as".id).first) %} | ||||||
|       {% elsif block.body.is_a? Call %} |           {% definitions << {var: prop.name, value: prop.args.first, type: type.value} %} | ||||||
|         {% definitions << {var: block.body.name, value: block.body.args.first} %} |         {% else %} | ||||||
|       {% elsif block.body.is_a? TypeDeclaration %} |           {% definitions << {var: prop.name, value: prop.args.first} %} | ||||||
|         {% definitions << {var: block.body.var, value: block.body.value, type: block.body.type} %} |         {% end %} | ||||||
|       {% elsif block.body.is_a? Expressions %} |       {% elsif block.body.is_a? Expressions %} | ||||||
|         {% for prop in block.body.expressions %} |         {% for prop in block.body.expressions %} | ||||||
|           {% if prop.is_a? Assign %} |           {% if prop.is_a? Call %} | ||||||
|             {% definitions << {var: prop.target, value: prop.value} %} |             {% if (named_args = prop.named_args) && (type = named_args.select(&.name.== "as".id).first) %} | ||||||
|           {% elsif prop.is_a? Call %} |               {% definitions << {var: prop.name, value: prop.args.first, type: type.value} %} | ||||||
|  |             {% else %} | ||||||
|               {% definitions << {var: prop.name, value: prop.args.first} %} |               {% definitions << {var: prop.name, value: prop.args.first} %} | ||||||
|           {% elsif prop.is_a? TypeDeclaration %} |             {% end %} | ||||||
|             {% definitions << {var: prop.var, value: prop.value, type: prop.type} %} |  | ||||||
|           {% end %} |           {% end %} | ||||||
|         {% end %} |         {% end %} | ||||||
|       {% end %} |       {% end %} | ||||||
|  |  | ||||||
|  | @ -15,7 +15,8 @@ module Ameba::Rule::Lint | ||||||
|   class Typos < Base |   class Typos < Base | ||||||
|     properties do |     properties do | ||||||
|       description "Reports typos found in source files" |       description "Reports typos found in source files" | ||||||
|       bin_path : String? = nil | 
 | ||||||
|  |       bin_path nil, as: String? | ||||||
|       fail_on_error false |       fail_on_error false | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -39,8 +39,8 @@ module Ameba::Rule::Style | ||||||
|       exclude_operators true |       exclude_operators true | ||||||
|       exclude_setters false |       exclude_setters false | ||||||
| 
 | 
 | ||||||
|       max_line_length : Int32? = nil # 100 |       max_line_length nil, as: Int32? | ||||||
|       max_length : Int32? = 50 |       max_length 50, as: Int32? | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     MSG          = "Use short block notation instead: `%s`" |     MSG          = "Use short block notation instead: `%s`" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue