From 00070afcb0f16068f83dfc893a55269910d5edd4 Mon Sep 17 00:00:00 2001 From: Francois Buys Date: Thu, 12 Oct 2023 15:36:06 +0200 Subject: [PATCH] ISSUE-1734 Add missing configuration warning This PR adds a more descriptive error message when users add a detector without configuration. Before this change a NoMethodError exception was raised with an unclear error message. Now we catch this exception and provide a more helpful error message. A better future option might be add [dry-schema](https://dry-rb.org/gems/dry-schema/1.13/) See: https://github.com/troessner/reek/issues/1734 --- .../configuration/configuration_converter.rb | 17 +++++++++++++++++ lib/reek/configuration/default_directive.rb | 6 ++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/reek/configuration/configuration_converter.rb b/lib/reek/configuration/configuration_converter.rb index 5b7248a8a..8f1d81979 100644 --- a/lib/reek/configuration/configuration_converter.rb +++ b/lib/reek/configuration/configuration_converter.rb @@ -80,6 +80,8 @@ def strings_to_regexes_for_detectors to_regex item end end + rescue NoMethodError + warn_about_missing_configuration(detector) if detectors[detector].nil? end end end @@ -101,10 +103,25 @@ def strings_to_regexes_for_directories to_regex item end end + rescue NoMethodError + warn_about_missing_configuration(detector) if configuration.nil? end end end end + + def warn_about_missing_configuration(detector) + msg = <<~ERROR + ############################### + + Please review the configuration file (e.g. .reek.yml in your project directory). + It looks like the configuration for #{detector} is missing. + You can find the configuration options documentation over here: https://github.com/troessner/reek#configuration-options. + + ############################### + ERROR + warn msg + end end end end diff --git a/lib/reek/configuration/default_directive.rb b/lib/reek/configuration/default_directive.rb index 37b3aa207..db989d161 100644 --- a/lib/reek/configuration/default_directive.rb +++ b/lib/reek/configuration/default_directive.rb @@ -21,8 +21,10 @@ module DefaultDirective # @return [self] def add(detectors_configuration) detectors_configuration.each do |name, configuration| - detector = key_to_smell_detector(name) - self[detector] = (self[detector] || {}).merge configuration + if configuration + detector = key_to_smell_detector(name) + self[detector] = (self[detector] || {}).merge configuration + end end self end