Skip to content
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

Add --exclude-smell CLI option #1751

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/Command-Line-Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ You can select several smells by repeating the `--smell` option like so:
reek --smell UtilityFunction --smell UncommunicativeMethodName
```

## Telling Reek Which Smells to Exclude

You can tell Reek to exclude specific smells by using the `--exclude-smell`
option and passing in the smell name.

For example, to exclude checking for [Utility Function](Utility-Function.md), you would use:

```bash
reek --exclude-smell UtilityFunction
```

You can select several smells to exclude by repeating the `--exclude-smell` option like so:

```bash
reek --exclude-smell UtilityFunction --exclude-smell IrresponsibleModule
```

## Output options

### Output smell's line number
Expand Down
12 changes: 12 additions & 0 deletions features/command_line_interface/exclude_smells.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Exclude smells
In order to exclude specific code smells
As a developer
I want to be able to selectively exclude smell detectors

Scenario: --exclude-smell selects smells to exclude
Given the smelly file 'smelly.rb'
When I run reek --no-line-numbers --exclude-smell UncommunicativeMethodName --exclude-smell UncommunicativeVariableName smelly.rb
Then the exit status is 0
And it reports:
"""
"""
3 changes: 3 additions & 0 deletions features/command_line_interface/options.feature
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Feature: Reek can be controlled using command-line options
--smell SMELL Only look for a specific smell.
Call it like this: reek --smell MissingSafeMethod source.rb
Check out https://github.com/troessner/reek/blob/v6.1.4/docs/Code-Smells.md for a list of smells
--exclude-smell SMELL Exclude a specific smell.
Call it like this: reek --exclude-smell MissingSafeMethod source.rb
Check out https://github.com/troessner/reek/blob/v6.1.4/docs/Code-Smells.md for a list of smells
--stdin-filename FILE When passing code in via pipe, assume this filename when checking file or directory rules in the config.

Generate a todo list:
Expand Down
24 changes: 20 additions & 4 deletions lib/reek/cli/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module CLI
# See {file:docs/Command-Line-Options.md} for details.
#
# @quality :reek:TooManyInstanceVariables { max_instance_variables: 13 }
# @quality :reek:TooManyMethods { max_methods: 18 }
# @quality :reek:TooManyMethods { max_methods: 20 }
# @quality :reek:Attribute { enabled: false }
#
class Options
Expand Down Expand Up @@ -101,26 +101,42 @@ def set_banner
BANNER
end

# @quality :reek:TooManyStatements { max_statements: 7 }
def set_configuration_options
# @quality :reek:TooManyStatements { max_statements: 10 }
def set_configuration_options # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
parser.separator 'Configuration:'
parser.on('-c', '--config FILE', 'Read configuration options from FILE') do |file|
self.config_file = Pathname.new(file)
end
parser.on('--smell SMELL',
'Only look for a specific smell.',
'Call it like this: reek --smell MissingSafeMethod source.rb',
"Check out #{DocumentationLink.build('Code Smells')} " \
"Check out #{code_smell_documentation_link} " \
'for a list of smells') do |smell|
smells_to_detect << smell
end
parser.on('--exclude-smell SMELL',
'Exclude a specific smell.',
'Call it like this: reek --exclude-smell MissingSafeMethod source.rb',
"Check out #{code_smell_documentation_link} " \
'for a list of smells') do |smell|
smells_to_detect.append(*smell_detectors) if smells_to_detect.empty?
smells_to_detect.delete(smell)
end
parser.on('--stdin-filename FILE',
'When passing code in via pipe, assume this filename when ' \
'checking file or directory rules in the config.') do |file|
self.stdin_filename = file
end
end

def code_smell_documentation_link
@code_smell_documentation_link ||= DocumentationLink.build('Code Smells')
end

def smell_detectors
@smell_detectors ||= Reek::SmellDetectors.constants.map(&:to_s)
end

def set_generate_todo_list_options
parser.separator "\nGenerate a todo list:"
parser.on('-t', '--todo', 'Generate a todo list') do
Expand Down