Skip to content

[WIP] Allow users to include other configuration files. #1426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ In case you have to have one or more configuration files in the directory (e.g.
toying around with different, mutually exclusive settings) you need to tell Reek
explicitly which file to use via `reek -c config.reek`.

### Including other configuration files

TODO

### Source code comments

In case you need to suppress a smell warning and you can't or don't want to
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Feature: Include other configuration files
In order to give users more flexibility when it comes to configuration files
we want to make it possible to include other configuration files into the main
configuration file.

Scenario: Include other configuration files
Given a file named "smelly.rb" with:
"""
class Smelly # IrresponsibleModule
# UncommunicativeMethodName
def x(y) # UncommunicativeParameterName and UnusedParameter
z = 10 # UncommunicativeVariableName
end
end
"""
And a file named ".reek.yml" with:
"""
---
detectors:
IrresponsibleModule:
enabled: false
include:
- second_config.yml
- third_config.yml
"""
And a file named "second_config.yml" with:
"""
---
detectors:
UncommunicativeMethodName:
enabled: false
"""
And a file named "third_config.yml" with:
"""
---
detectors:
UncommunicativeVariableName:
enabled: false
"""

When I run reek smelly.rb
Then it reports:
"""
smelly.rb -- 2 warnings:
[3]:UncommunicativeParameterName: Smelly#x has the parameter name 'y'
[3]:UnusedParameters: Smelly#x has unused parameter 'y'
"""

Scenario: Included file has additional include directives

Scenario: Other configuration file overwrites configuration in the main configuration

Scenario: Other configuration file does not exist

Scenario: Other configuration file contains a syntax error
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can handle the error cases in specs instead?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed ;)

1 change: 1 addition & 0 deletions lib/reek.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ module Reek
DETECTORS_KEY = 'detectors'
EXCLUDE_PATHS_KEY = 'exclude_paths'
DIRECTORIES_KEY = 'directories'
INCLUDE_KEY = 'include'
end
2 changes: 2 additions & 0 deletions lib/reek/configuration/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def load_values(values)
directory_directives.add value
elsif key == DETECTORS_KEY
default_directive.add value
elsif key == INCLUDE_KEY
# TODO: Magic happens here.
end
end
end
Expand Down
7 changes: 6 additions & 1 deletion lib/reek/configuration/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,13 @@ mapping:
=:
type: map
mapping: *all_detectors

"exclude_paths":
type: seq
sequence:
- type: str

"include":
type: seq
sequence:
- type: str