Skip to content

Commit

Permalink
ISSUE-1734 Add missing configuration warning
Browse files Browse the repository at this point in the history
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: troessner#1734
  • Loading branch information
fbuys committed Oct 12, 2023
1 parent b1fa495 commit 00070af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions lib/reek/configuration/configuration_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 4 additions & 2 deletions lib/reek/configuration/default_directive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 00070af

Please sign in to comment.