Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
fbuys committed Oct 31, 2023
1 parent 15478a9 commit d123127
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Feature: Directory directives
Then the exit status indicates an error
And stderr reports:
"""
Error: We found some problems with your configuration file:
Error: Invalid configuration file config.reek, error is
[/directories/dummy_directory/IteratorsNested/enabled] is not allowed.
"""

Expand Down
2 changes: 1 addition & 1 deletion features/configuration_files/masking_smells.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feature: Masking smells using config files
When I run reek -c corrupt.reek smelly.rb
And stderr reports:
"""
Error: Invalid configuration file at .reek.yml.
Error: Invalid configuration file corrupt.reek, error is unrecognized configuration data
"""
And the exit status indicates an error
And it reports nothing
Expand Down
2 changes: 1 addition & 1 deletion features/configuration_files/schema_validation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ Feature: Validate schema
Then the exit status indicates an error
And stderr reports:
"""
Error: We found some problems with your configuration file:
Error: Invalid configuration file config.reek, error is
[/detectors/DoesNotExist/enabled] is not allowed.
"""
2 changes: 1 addition & 1 deletion lib/reek/configuration/configuration_file_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def load_from_file(path)

begin
configuration = YAML.load_file(path) || {}
SchemaValidator.new(configuration).validate
rescue StandardError => error
raise Errors::ConfigFileError, "Invalid configuration file #{path}, error is #{error}"
end

SchemaValidator.new(configuration).validate
ConfigurationConverter.new(configuration).convert
end

Expand Down
5 changes: 0 additions & 5 deletions lib/reek/configuration/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class Schema
optional(:enabled).filled(:bool)
optional(:exclude).array(:string)
end
optional(:DataClump).filled(:hash) do
optional(:enabled).filled(:bool)
optional(:exclude).array(:string)
end
optional(:DataClump).filled(:hash) do
optional(:enabled).filled(:bool)
optional(:exclude).array(:string)
Expand Down Expand Up @@ -168,7 +164,6 @@ class Schema
def self.schema(directories = [])
Dry::Schema.Params do
config.validate_keys = true
# config.messages.load_paths << "lib/reek/configuration/schema_errors.yml"

optional(:detectors).filled(ALL_DETECTORS_SCHEMA)
optional(:directories).filled(:hash) do
Expand Down
7 changes: 3 additions & 4 deletions lib/reek/configuration/schema_validator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require_relative '../cli/silencer'
require_relative '../errors/config_file_error'
require_relative 'schema'

Expand All @@ -17,12 +16,12 @@ def initialize(configuration)
end

def validate
result = CLI::Silencer.without_warnings { @validator.call(@configuration) }
result = @validator.call(@configuration)
return if result.success?

raise Errors::ConfigFileError, error_message(result.errors)
rescue NoMethodError
raise Errors::ConfigFileError, "Invalid configuration file at #{Reek::DEFAULT_CONFIGURATION_FILE_NAME}."
raise Errors::ConfigFileError, 'unrecognized configuration data'
end

private
Expand All @@ -32,7 +31,7 @@ def error_message(errors)
messages = errors.map do |error|
"[/#{error.path.join('/')}] #{error.text}."
end.join("\n")
"We found some problems with your configuration file:\n#{messages}"
"\n#{messages}"
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/reek/configuration/configuration_file_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@
end
end

it 'raises an error for unrecogized configuration data' do
path = CONFIGURATION_DIR.join('corrupt.reek')
expect { described_class.load_from_file(path) }.
to raise_error(Reek::Errors::ConfigFileError, /Invalid configuration file #{path}/)
end

context 'with exclude, accept and reject settings' do
context 'when configuring top level detectors' do
let(:configuration) do
Expand Down
2 changes: 1 addition & 1 deletion spec/reek/configuration/schema_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
let(:configuration) { 'Not a valid configuration file' }

it 'raises an error' do
message = "Invalid configuration file at #{Reek::DEFAULT_CONFIGURATION_FILE_NAME}."
message = 'unrecognized configuration data'
expect { validator.validate }.to raise_error(Reek::Errors::ConfigFileError, message)
end
end
Expand Down

0 comments on commit d123127

Please sign in to comment.