From 6898aa8976d4bd9e2172876835d1f0621402326e Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 17 Jan 2021 21:31:53 +0100 Subject: [PATCH] Fix issue #187 (#189) * Avoid using `tap` with structs * Remove extraneous blank lines * Readability --- src/ameba.cr | 2 -- src/ameba/ast/util.cr | 1 - src/ameba/cli/cmd.cr | 10 ++++++++-- src/ameba/config.cr | 5 ----- src/ameba/rule/base.cr | 9 +++++---- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/ameba.cr b/src/ameba.cr index 4649b00c..f16c62e6 100644 --- a/src/ameba.cr +++ b/src/ameba.cr @@ -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 diff --git a/src/ameba/ast/util.cr b/src/ameba/ast/util.cr index 28f55dd0..0690e31b 100644 --- a/src/ameba/ast/util.cr +++ b/src/ameba/ast/util.cr @@ -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 diff --git a/src/ameba/cli/cmd.cr b/src/ameba/cli/cmd.cr index d32543c4..25d01e76 100644 --- a/src/ameba/cli/cmd.cr +++ b/src/ameba/cli/cmd.cr @@ -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 diff --git a/src/ameba/config.cr b/src/ameba/config.cr index c3f7b339..7661f640 100644 --- a/src/ameba/config.cr +++ b/src/ameba/config.cr @@ -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]? diff --git a/src/ameba/rule/base.cr b/src/ameba/rule/base.cr index e499452f..ea31a2ca 100644 --- a/src/ameba/rule/base.cr +++ b/src/ameba/rule/base.cr @@ -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