From 9e7d62464b8dc8925d931b6515453d8ccda34d0a Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 17 Nov 2024 18:53:35 +0100 Subject: [PATCH 1/4] Use `Mutex` instead of `Thread::Mutex` --- src/ameba/formatter/dot_formatter.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ameba/formatter/dot_formatter.cr b/src/ameba/formatter/dot_formatter.cr index 97982622f..22eafc527 100644 --- a/src/ameba/formatter/dot_formatter.cr +++ b/src/ameba/formatter/dot_formatter.cr @@ -7,7 +7,7 @@ module Ameba::Formatter include Util @started_at : Time::Span? - @mutex = Thread::Mutex.new + @mutex = Mutex.new # Reports a message when inspection is started. def started(sources) From 74456d65604d1b89511c364fec3eee95cb635d71 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 17 Nov 2024 18:55:04 +0100 Subject: [PATCH 2/4] Add a note regarding MT-safety in formatter methods --- src/ameba/formatter/base_formatter.cr | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ameba/formatter/base_formatter.cr b/src/ameba/formatter/base_formatter.cr index a6ceafdf0..43364e07d 100644 --- a/src/ameba/formatter/base_formatter.cr +++ b/src/ameba/formatter/base_formatter.cr @@ -19,10 +19,14 @@ module Ameba::Formatter # 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 # 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 # Callback that indicates when inspection is finished. From a21199671f970e736165b4e46461bfec7290ee21 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 17 Nov 2024 18:55:39 +0100 Subject: [PATCH 3/4] Add ivar declaration to make it more visible --- src/ameba/formatter/todo_formatter.cr | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ameba/formatter/todo_formatter.cr b/src/ameba/formatter/todo_formatter.cr index 00a2d28f1..ce8d58080 100644 --- a/src/ameba/formatter/todo_formatter.cr +++ b/src/ameba/formatter/todo_formatter.cr @@ -3,7 +3,9 @@ module Ameba::Formatter # Basically, it takes all issues reported and disables corresponding rules # or excludes failed sources from these rules. class TODOFormatter < DotFormatter - def initialize(@output = STDOUT, @config_path : Path = Config::DEFAULT_PATH) + @config_path : Path + + def initialize(@output = STDOUT, @config_path = Config::DEFAULT_PATH) end def finished(sources) From 37a4c14f33ed05735199bb0ced320e6e3bf0675d Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 17 Nov 2024 18:56:38 +0100 Subject: [PATCH 4/4] Remove redundant `nil` assignment --- src/ameba/config.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ameba/config.cr b/src/ameba/config.cr index 6f80fba21..8c45a7839 100644 --- a/src/ameba/config.cr +++ b/src/ameba/config.cr @@ -87,7 +87,7 @@ class Ameba::Config property? autocorrect = false # Returns a filename if reading source file from STDIN. - property stdin_filename : String? = nil + property stdin_filename : String? @rule_groups : Hash(String, Array(Rule::Base))