diff --git a/spec/ameba/formatter/todo_formatter_spec.cr b/spec/ameba/formatter/todo_formatter_spec.cr index cc7dd32c2..448cd10ad 100644 --- a/spec/ameba/formatter/todo_formatter_spec.cr +++ b/spec/ameba/formatter/todo_formatter_spec.cr @@ -13,10 +13,12 @@ module Ameba private def create_todo with_formatter do |formatter| - s = Source.new "a = 1", "source.cr" - s.add_issue DummyRule.new, {1, 2}, "message" - file = formatter.finished([s]) - file ? File.read(file.path) : "" + source = Source.new "a = 1", "source.cr" + source.add_issue DummyRule.new, {1, 2}, "message" + + formatter.finished([source]) + + File.exists?(CONFIG_PATH) ? File.read(CONFIG_PATH) : "" end end @@ -97,8 +99,9 @@ module Ameba s1.add_issue DummyRule.new, {2, 2}, "message1" s2.add_issue DummyRule.new, {2, 2}, "message2" - file = formatter.finished([s1, s2]).should_not be_nil - content = File.read(file.path) + formatter.finished([s1, s2]) + + content = File.read(CONFIG_PATH) content.should contain <<-CONTENT # Problems found: 3 # Run `ameba --only Ameba/DummyRule` for details diff --git a/src/ameba/cli/cmd.cr b/src/ameba/cli/cmd.cr index f87030785..3d6040d10 100644 --- a/src/ameba/cli/cmd.cr +++ b/src/ameba/cli/cmd.cr @@ -5,7 +5,7 @@ require "option_parser" module Ameba::Cli extend self - def run(args = ARGV) + def run(args = ARGV) : Nil opts = parse_args args location_to_explain = opts.location_to_explain autocorrect = opts.autocorrect? @@ -151,7 +151,7 @@ module Ameba::Cli opts end - private def configure_rules(config, opts) + private def configure_rules(config, opts) : Nil case when only = opts.only config.rules.each(&.enabled = false) @@ -162,7 +162,7 @@ module Ameba::Cli config.update_rules(opts.except, enabled: false) end - private def configure_formatter(config, opts) + private def configure_formatter(config, opts) : Nil if name = opts.formatter config.formatter = name end @@ -171,12 +171,12 @@ module Ameba::Cli opts.without_affected_code? end - private def configure_describe_opts(rule_name, opts) + private def configure_describe_opts(rule_name, opts) : Nil opts.describe_rule = rule_name.presence opts.formatter = :silent end - private def configure_explain_opts(loc, opts) + private def configure_explain_opts(loc, opts) : Nil location_to_explain = parse_explain_location(loc) opts.location_to_explain = location_to_explain opts.globs = [location_to_explain[:file]] diff --git a/src/ameba/formatter/base_formatter.cr b/src/ameba/formatter/base_formatter.cr index 43364e07d..dc7b65287 100644 --- a/src/ameba/formatter/base_formatter.cr +++ b/src/ameba/formatter/base_formatter.cr @@ -15,22 +15,22 @@ module Ameba::Formatter # Callback that indicates when inspecting is started. # A list of sources to inspect is passed as an argument. - def started(sources); end + def started(sources) : Nil; end # Callback that indicates when source inspection is started. # A corresponding source is passed as an argument. # # WARNING: This method needs to be MT safe - def source_started(source : Source); end + def source_started(source : Source) : Nil; end # Callback that indicates when source inspection is finished. # A corresponding source is passed as an argument. # # WARNING: This method needs to be MT safe - def source_finished(source : Source); end + def source_finished(source : Source) : Nil; end # Callback that indicates when inspection is finished. # A list of inspected sources is passed as an argument. - def finished(sources); end + def finished(sources) : Nil; end end end diff --git a/src/ameba/formatter/disabled_formatter.cr b/src/ameba/formatter/disabled_formatter.cr index ecab4aa74..ef14da542 100644 --- a/src/ameba/formatter/disabled_formatter.cr +++ b/src/ameba/formatter/disabled_formatter.cr @@ -1,7 +1,7 @@ module Ameba::Formatter # A formatter that shows all disabled lines by inline directives. class DisabledFormatter < BaseFormatter - def finished(sources) + def finished(sources) : Nil output << "Disabled rules using inline directives:\n\n" sources.each do |source| diff --git a/src/ameba/formatter/dot_formatter.cr b/src/ameba/formatter/dot_formatter.cr index 22eafc527..600de0a10 100644 --- a/src/ameba/formatter/dot_formatter.cr +++ b/src/ameba/formatter/dot_formatter.cr @@ -10,7 +10,7 @@ module Ameba::Formatter @mutex = Mutex.new # Reports a message when inspection is started. - def started(sources) + def started(sources) : Nil @started_at = Time.monotonic output.puts started_message(sources.size) @@ -18,13 +18,13 @@ module Ameba::Formatter end # Reports a result of the inspection of a corresponding source. - def source_finished(source : Source) + def source_finished(source : Source) : Nil sym = source.valid? ? ".".colorize(:green) : "F".colorize(:red) @mutex.synchronize { output << sym } end # Reports a message when inspection is finished. - def finished(sources) + def finished(sources) : Nil output.flush output << "\n\n" diff --git a/src/ameba/formatter/explain_formatter.cr b/src/ameba/formatter/explain_formatter.cr index e963d98f4..0ee208504 100644 --- a/src/ameba/formatter/explain_formatter.cr +++ b/src/ameba/formatter/explain_formatter.cr @@ -30,7 +30,7 @@ module Ameba::Formatter end # Reports the explanations at the *@location*. - def finished(sources) + def finished(sources) : Nil source = sources.find(&.path.==(@location.filename)) return unless source @@ -40,7 +40,7 @@ module Ameba::Formatter explain(source, issue) end - private def explain(source, issue) + private def explain(source, issue) : Nil return unless location = issue.location output << '\n' diff --git a/src/ameba/formatter/flycheck_formatter.cr b/src/ameba/formatter/flycheck_formatter.cr index 491567e4a..5de8030f5 100644 --- a/src/ameba/formatter/flycheck_formatter.cr +++ b/src/ameba/formatter/flycheck_formatter.cr @@ -2,7 +2,7 @@ module Ameba::Formatter class FlycheckFormatter < BaseFormatter @mutex = Mutex.new - def source_finished(source : Source) + def source_finished(source : Source) : Nil source.issues.each do |issue| next if issue.disabled? next if issue.correctable? && config[:autocorrect]? diff --git a/src/ameba/formatter/json_formatter.cr b/src/ameba/formatter/json_formatter.cr index 42e310ee3..a65d5fb3c 100644 --- a/src/ameba/formatter/json_formatter.cr +++ b/src/ameba/formatter/json_formatter.cr @@ -66,11 +66,11 @@ module Ameba::Formatter @result = AsJSON::Result.new @mutex = Mutex.new - def started(sources) + def started(sources) : Nil @result.summary.target_sources_count = sources.size end - def source_finished(source : Source) + def source_finished(source : Source) : Nil json_source = AsJSON::Source.new source.path source.issues.each do |issue| @@ -92,7 +92,7 @@ module Ameba::Formatter end end - def finished(sources) + def finished(sources) : Nil @result.to_json @output end end diff --git a/src/ameba/formatter/todo_formatter.cr b/src/ameba/formatter/todo_formatter.cr index ce8d58080..2744963ad 100644 --- a/src/ameba/formatter/todo_formatter.cr +++ b/src/ameba/formatter/todo_formatter.cr @@ -8,7 +8,7 @@ module Ameba::Formatter def initialize(@output = STDOUT, @config_path = Config::DEFAULT_PATH) end - def finished(sources) + def finished(sources) : Nil super issues = sources.flat_map(&.issues) @@ -22,12 +22,12 @@ module Ameba::Formatter return end - generate_todo_config(issues).tap do |file| - @output.puts "Created #{file.path}" - end + generate_todo_config(issues) + + @output.puts "Created #{@config_path}" end - private def generate_todo_config(issues) + private def generate_todo_config(issues) : Nil File.open(@config_path, mode: "w") do |file| file << header @@ -41,7 +41,6 @@ module Ameba::Formatter file << "\n# Run `ameba --only #{rule.name}` for details" file << rule_todo end - file end end diff --git a/src/ameba/presenter/rule_collection_presenter.cr b/src/ameba/presenter/rule_collection_presenter.cr index e833df11d..1b5b6795c 100644 --- a/src/ameba/presenter/rule_collection_presenter.cr +++ b/src/ameba/presenter/rule_collection_presenter.cr @@ -1,6 +1,6 @@ module Ameba::Presenter class RuleCollectionPresenter < BasePresenter - def run(rules) + def run(rules) : Nil rules = rules.to_h do |rule| name = rule.name.split('/') name = "%s/%s" % { diff --git a/src/ameba/presenter/rule_presenter.cr b/src/ameba/presenter/rule_presenter.cr index a790ac4b7..9c7da467a 100644 --- a/src/ameba/presenter/rule_presenter.cr +++ b/src/ameba/presenter/rule_presenter.cr @@ -1,6 +1,6 @@ module Ameba::Presenter class RulePresenter < BasePresenter - def run(rule) + def run(rule) : Nil output.puts output_title "Rule info" output_paragraph "%s of a %s severity [enabled: %s]" % { diff --git a/src/ameba/runner.cr b/src/ameba/runner.cr index 1923e0a01..03f11b590 100644 --- a/src/ameba/runner.cr +++ b/src/ameba/runner.cr @@ -107,7 +107,7 @@ module Ameba @formatter.finished @sources end - private def run_source(source) + private def run_source(source) : Nil @formatter.source_started source # This variable is a 2D array used to track corrected issues after each