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
|
||||
# ```
|
||||
#
|
||||
module Ameba
|
||||
extend self
|
||||
|
||||
|
@ -35,7 +34,6 @@ module Ameba
|
|||
# Ameba.run
|
||||
# Ameba.run config
|
||||
# ```
|
||||
#
|
||||
def run(config = Config.load)
|
||||
Runner.new(config).run
|
||||
end
|
||||
|
|
|
@ -97,7 +97,6 @@ module Ameba::AST::Util
|
|||
# ```
|
||||
#
|
||||
# That's because not all branches return(i.e. `else` is missing).
|
||||
#
|
||||
def flow_expression?(node, in_loop = false)
|
||||
return true if flow_command? node, in_loop
|
||||
|
||||
|
|
|
@ -121,10 +121,16 @@ module Ameba::Cli
|
|||
private def configure_rules(config, opts)
|
||||
case
|
||||
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)
|
||||
when opts.all?
|
||||
config.rules.map! &.tap(&.enabled = true)
|
||||
config.rules.map! do |rule|
|
||||
rule.enabled = true
|
||||
rule
|
||||
end
|
||||
end
|
||||
config.update_rules(opts.except, enabled: false)
|
||||
end
|
||||
|
|
|
@ -75,7 +75,6 @@ class Ameba::Config
|
|||
# ```
|
||||
# config = Ameba::Config.load
|
||||
# ```
|
||||
#
|
||||
def self.load(path = PATH, colors = true)
|
||||
Colorize.enabled = colors
|
||||
content = File.exists?(path) ? File.read path : "{}"
|
||||
|
@ -97,7 +96,6 @@ class Ameba::Config
|
|||
# config.excluded = ["spec"]
|
||||
# config.sources # => list of sources pointing to files found by the wildcards
|
||||
# ```
|
||||
#
|
||||
def sources
|
||||
(find_files_by_globs(globs) - find_files_by_globs(excluded))
|
||||
.map { |path| Source.new File.read(path), path }
|
||||
|
@ -122,7 +120,6 @@ class Ameba::Config
|
|||
# config = Ameba::Config.load
|
||||
# config.formatter = :progress
|
||||
# ```
|
||||
#
|
||||
def formatter=(name : String | Symbol)
|
||||
if f = AVAILABLE_FORMATTERS[name]?
|
||||
@formatter = f.new
|
||||
|
@ -137,7 +134,6 @@ class Ameba::Config
|
|||
# config = Ameba::Config.load
|
||||
# config.update_rule "MyRuleName", enabled: false
|
||||
# ```
|
||||
#
|
||||
def update_rule(name, enabled = true, excluded = nil)
|
||||
index = @rules.index { |rule| rule.name == name }
|
||||
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
|
||||
# ```
|
||||
#
|
||||
def update_rules(names, **args)
|
||||
names.try &.each do |name|
|
||||
if group = @rule_groups[name]?
|
||||
|
|
|
@ -26,7 +26,6 @@ module Ameba::Rule
|
|||
# Enforces rules to implement an abstract `#test` method which
|
||||
# is designed to test the source passed in. If source has issues
|
||||
# that are tested by this rule, it should add an issue.
|
||||
#
|
||||
abstract struct Base
|
||||
include Config::RuleConfig
|
||||
|
||||
|
@ -51,7 +50,7 @@ module Ameba::Rule
|
|||
# source.valid?
|
||||
# ```
|
||||
def catch(source : Source)
|
||||
source.tap { |s| test s }
|
||||
source.tap { test source }
|
||||
end
|
||||
|
||||
# Returns a name of this rule, which is basically a class name.
|
||||
|
@ -151,8 +150,11 @@ module Ameba::Rule
|
|||
# ```
|
||||
def self.parsed_doc
|
||||
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?
|
||||
|
||||
DocFinder.new(nodes, type_name).doc
|
||||
end
|
||||
|
||||
|
@ -185,7 +187,6 @@ module Ameba::Rule
|
|||
# ```
|
||||
# Ameba::Rule.rules # => [Rule1, Rule2, ....]
|
||||
# ```
|
||||
#
|
||||
def self.rules
|
||||
Base.subclasses
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue