Skip to content

Commit

Permalink
Merge pull request #305 from troessner/add-ultra-verbose-warning-form…
Browse files Browse the repository at this point in the history
…atter

Add ultra verbose warning formatter.
  • Loading branch information
mvz committed Nov 5, 2014
2 parents cd99688 + a9cc0f3 commit 4ebaf12
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions features/command_line_interface/options.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Feature: Reek can be controlled using command-line options
-o, --[no-]color Use colors for the output (this is the default)
-q, --quiet Suppress headings for smell-free source files (this is the default)
-V, --no-quiet, --verbose Show headings for smell-free source files
-U, --ultra-verbose Be as explanatory as possible
-n, --no-line-numbers Suppress line numbers from the output
--line-numbers Show line numbers in the output (this is the default)
-s, --single-line Show IDE-compatible single-line-per-warning
Expand Down
16 changes: 16 additions & 0 deletions features/reports/reports.feature
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,19 @@ Feature: Correctly formatted reports
| args |
| spec/samples/two_smelly_files/ |
| spec/samples/two_smelly_files |

Scenario Outline: -U or --ultra-verbose adds helpful links to smell warnings
When I run reek <option> spec/samples/one_smelly_file/dirty.rb
Then the exit status indicates smells
And it reports:
"""
spec/samples/one_smelly_file/dirty.rb -- 3 warnings:
[1]:D has no descriptive comment (IrresponsibleModule) [https://github.com/troessner/reek/wiki/IrresponsibleModule]
[1]:D has the name 'D' (UncommunicativeModuleName) [https://github.com/troessner/reek/wiki/UncommunicativeModuleName]
[2]:D#a has the name 'a' (UncommunicativeMethodName) [https://github.com/troessner/reek/wiki/UncommunicativeMethodName]
"""

Examples:
| option |
| -U |
| --ultra-verbose |
3 changes: 3 additions & 0 deletions lib/reek/cli/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def set_options
@parser.on('-V', '--no-quiet', '--verbose', 'Show headings for smell-free source files') do |_opt|
@strategy = Report::Strategy::Verbose
end
@parser.on('-U', '--ultra-verbose', 'Be as explanatory as possible') do |_opt|
@warning_formatter = Report::UltraVerboseWarningFormattter
end
@parser.on('-n', '--no-line-numbers', 'Suppress line numbers from the output') do
@warning_formatter = Report::SimpleWarningFormatter
end
Expand Down
14 changes: 14 additions & 0 deletions lib/reek/cli/report/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ def self.header(examiner)
end
end

module UltraVerboseWarningFormattter
BASE_URL_FOR_HELP_LINK = 'https://github.com/troessner/reek/wiki/'

module_function

def format(warning)
"#{WarningFormatterWithLineNumbers.format(warning)} [#{explanatory_link(warning)}]"
end

def explanatory_link(warning)
"#{BASE_URL_FOR_HELP_LINK}#{warning.subclass}"
end
end

module SimpleWarningFormatter
def self.format(warning)
"#{warning.context} #{warning.message} (#{warning.subclass})"
Expand Down
3 changes: 3 additions & 0 deletions spec/samples/one_smelly_file/dirty.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class D
def a; end
end

0 comments on commit 4ebaf12

Please sign in to comment.