mirror of
				https://gitea.invidious.io/iv-org/shard-ameba.git
				synced 2024-08-15 00:53:29 +00:00 
			
		
		
		
	* Avoid using `tap` with structs * Remove extraneous blank lines * Readability
This commit is contained in:
		
							parent
							
								
									928a260d51
								
							
						
					
					
						commit
						6898aa8976
					
				
					 5 changed files with 13 additions and 14 deletions
				
			
		| 
						 | 
					@ -20,7 +20,6 @@ require "./ameba/formatter/*"
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# Ameba.run config
 | 
					# Ameba.run config
 | 
				
			||||||
# ```
 | 
					# ```
 | 
				
			||||||
#
 | 
					 | 
				
			||||||
module Ameba
 | 
					module Ameba
 | 
				
			||||||
  extend self
 | 
					  extend self
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,7 +34,6 @@ module Ameba
 | 
				
			||||||
  # Ameba.run
 | 
					  # Ameba.run
 | 
				
			||||||
  # Ameba.run config
 | 
					  # Ameba.run config
 | 
				
			||||||
  # ```
 | 
					  # ```
 | 
				
			||||||
  #
 | 
					 | 
				
			||||||
  def run(config = Config.load)
 | 
					  def run(config = Config.load)
 | 
				
			||||||
    Runner.new(config).run
 | 
					    Runner.new(config).run
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -97,7 +97,6 @@ module Ameba::AST::Util
 | 
				
			||||||
  # ```
 | 
					  # ```
 | 
				
			||||||
  #
 | 
					  #
 | 
				
			||||||
  # That's because not all branches return(i.e. `else` is missing).
 | 
					  # That's because not all branches return(i.e. `else` is missing).
 | 
				
			||||||
  #
 | 
					 | 
				
			||||||
  def flow_expression?(node, in_loop = false)
 | 
					  def flow_expression?(node, in_loop = false)
 | 
				
			||||||
    return true if flow_command? node, in_loop
 | 
					    return true if flow_command? node, in_loop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -121,10 +121,16 @@ module Ameba::Cli
 | 
				
			||||||
  private def configure_rules(config, opts)
 | 
					  private def configure_rules(config, opts)
 | 
				
			||||||
    case
 | 
					    case
 | 
				
			||||||
    when only = opts.only
 | 
					    when only = opts.only
 | 
				
			||||||
      config.rules.map! &.tap(&.enabled = false)
 | 
					      config.rules.map! do |rule|
 | 
				
			||||||
 | 
					        rule.enabled = false
 | 
				
			||||||
 | 
					        rule
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
      config.update_rules(only, enabled: true)
 | 
					      config.update_rules(only, enabled: true)
 | 
				
			||||||
    when opts.all?
 | 
					    when opts.all?
 | 
				
			||||||
      config.rules.map! &.tap(&.enabled = true)
 | 
					      config.rules.map! do |rule|
 | 
				
			||||||
 | 
					        rule.enabled = true
 | 
				
			||||||
 | 
					        rule
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    config.update_rules(opts.except, enabled: false)
 | 
					    config.update_rules(opts.except, enabled: false)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -75,7 +75,6 @@ class Ameba::Config
 | 
				
			||||||
  # ```
 | 
					  # ```
 | 
				
			||||||
  # config = Ameba::Config.load
 | 
					  # config = Ameba::Config.load
 | 
				
			||||||
  # ```
 | 
					  # ```
 | 
				
			||||||
  #
 | 
					 | 
				
			||||||
  def self.load(path = PATH, colors = true)
 | 
					  def self.load(path = PATH, colors = true)
 | 
				
			||||||
    Colorize.enabled = colors
 | 
					    Colorize.enabled = colors
 | 
				
			||||||
    content = File.exists?(path) ? File.read path : "{}"
 | 
					    content = File.exists?(path) ? File.read path : "{}"
 | 
				
			||||||
| 
						 | 
					@ -97,7 +96,6 @@ class Ameba::Config
 | 
				
			||||||
  # config.excluded = ["spec"]
 | 
					  # config.excluded = ["spec"]
 | 
				
			||||||
  # config.sources # => list of sources pointing to files found by the wildcards
 | 
					  # config.sources # => list of sources pointing to files found by the wildcards
 | 
				
			||||||
  # ```
 | 
					  # ```
 | 
				
			||||||
  #
 | 
					 | 
				
			||||||
  def sources
 | 
					  def sources
 | 
				
			||||||
    (find_files_by_globs(globs) - find_files_by_globs(excluded))
 | 
					    (find_files_by_globs(globs) - find_files_by_globs(excluded))
 | 
				
			||||||
      .map { |path| Source.new File.read(path), path }
 | 
					      .map { |path| Source.new File.read(path), path }
 | 
				
			||||||
| 
						 | 
					@ -122,7 +120,6 @@ class Ameba::Config
 | 
				
			||||||
  # config = Ameba::Config.load
 | 
					  # config = Ameba::Config.load
 | 
				
			||||||
  # config.formatter = :progress
 | 
					  # config.formatter = :progress
 | 
				
			||||||
  # ```
 | 
					  # ```
 | 
				
			||||||
  #
 | 
					 | 
				
			||||||
  def formatter=(name : String | Symbol)
 | 
					  def formatter=(name : String | Symbol)
 | 
				
			||||||
    if f = AVAILABLE_FORMATTERS[name]?
 | 
					    if f = AVAILABLE_FORMATTERS[name]?
 | 
				
			||||||
      @formatter = f.new
 | 
					      @formatter = f.new
 | 
				
			||||||
| 
						 | 
					@ -137,7 +134,6 @@ class Ameba::Config
 | 
				
			||||||
  # config = Ameba::Config.load
 | 
					  # config = Ameba::Config.load
 | 
				
			||||||
  # config.update_rule "MyRuleName", enabled: false
 | 
					  # config.update_rule "MyRuleName", enabled: false
 | 
				
			||||||
  # ```
 | 
					  # ```
 | 
				
			||||||
  #
 | 
					 | 
				
			||||||
  def update_rule(name, enabled = true, excluded = nil)
 | 
					  def update_rule(name, enabled = true, excluded = nil)
 | 
				
			||||||
    index = @rules.index { |rule| rule.name == name }
 | 
					    index = @rules.index { |rule| rule.name == name }
 | 
				
			||||||
    raise ArgumentError.new("Rule `#{name}` does not exist") unless index
 | 
					    raise ArgumentError.new("Rule `#{name}` does not exist") unless index
 | 
				
			||||||
| 
						 | 
					@ -160,7 +156,6 @@ class Ameba::Config
 | 
				
			||||||
  # ```
 | 
					  # ```
 | 
				
			||||||
  # config.update_rules %w(Group1 Group2), enabled: true
 | 
					  # config.update_rules %w(Group1 Group2), enabled: true
 | 
				
			||||||
  # ```
 | 
					  # ```
 | 
				
			||||||
  #
 | 
					 | 
				
			||||||
  def update_rules(names, **args)
 | 
					  def update_rules(names, **args)
 | 
				
			||||||
    names.try &.each do |name|
 | 
					    names.try &.each do |name|
 | 
				
			||||||
      if group = @rule_groups[name]?
 | 
					      if group = @rule_groups[name]?
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,7 +26,6 @@ module Ameba::Rule
 | 
				
			||||||
  # Enforces rules to implement an abstract `#test` method which
 | 
					  # Enforces rules to implement an abstract `#test` method which
 | 
				
			||||||
  # is designed to test the source passed in. If source has issues
 | 
					  # is designed to test the source passed in. If source has issues
 | 
				
			||||||
  # that are tested by this rule, it should add an issue.
 | 
					  # that are tested by this rule, it should add an issue.
 | 
				
			||||||
  #
 | 
					 | 
				
			||||||
  abstract struct Base
 | 
					  abstract struct Base
 | 
				
			||||||
    include Config::RuleConfig
 | 
					    include Config::RuleConfig
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -51,7 +50,7 @@ module Ameba::Rule
 | 
				
			||||||
    # source.valid?
 | 
					    # source.valid?
 | 
				
			||||||
    # ```
 | 
					    # ```
 | 
				
			||||||
    def catch(source : Source)
 | 
					    def catch(source : Source)
 | 
				
			||||||
      source.tap { |s| test s }
 | 
					      source.tap { test source }
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Returns a name of this rule, which is basically a class name.
 | 
					    # Returns a name of this rule, which is basically a class name.
 | 
				
			||||||
| 
						 | 
					@ -151,8 +150,11 @@ module Ameba::Rule
 | 
				
			||||||
    # ```
 | 
					    # ```
 | 
				
			||||||
    def self.parsed_doc
 | 
					    def self.parsed_doc
 | 
				
			||||||
      source = File.read(path_to_source_file)
 | 
					      source = File.read(path_to_source_file)
 | 
				
			||||||
      nodes = Crystal::Parser.new(source).tap(&.wants_doc = true).parse
 | 
					      nodes = Crystal::Parser.new(source)
 | 
				
			||||||
 | 
					        .tap(&.wants_doc = true)
 | 
				
			||||||
 | 
					        .parse
 | 
				
			||||||
      type_name = rule_name.split('/').last?
 | 
					      type_name = rule_name.split('/').last?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      DocFinder.new(nodes, type_name).doc
 | 
					      DocFinder.new(nodes, type_name).doc
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -185,7 +187,6 @@ module Ameba::Rule
 | 
				
			||||||
  # ```
 | 
					  # ```
 | 
				
			||||||
  # Ameba::Rule.rules # => [Rule1, Rule2, ....]
 | 
					  # Ameba::Rule.rules # => [Rule1, Rule2, ....]
 | 
				
			||||||
  # ```
 | 
					  # ```
 | 
				
			||||||
  #
 | 
					 | 
				
			||||||
  def self.rules
 | 
					  def self.rules
 | 
				
			||||||
    Base.subclasses
 | 
					    Base.subclasses
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue