Skip to content

Commit

Permalink
Fix YAML configuration file 'formats' processing
Browse files Browse the repository at this point in the history
Fixes: Ignores .rubycritic.yml file whitesmith#303
whitesmith#303.

Update the documentation to indicate that the key in the
.rubycritic.yml configuration file which controls the output
format is 'formats' rather than 'format'.

Fix a bug in RubyCritic::Cli::Options#to_h which prevents a
setting in the YAML configuration file from being used when the
setting is an Array (as is the case for the output formats).

Modify RubyCritic::CLI::Options::File#formats to return an array
of symbols instead of an array of strings, to be consistent with
how RubyCritic::CLI::Options::Argv#parse returns the array. Also
modify it so it can accept a single output format or a list of
formats. The documentation indicates that either is acceptable
but the code assumed the input was always an array.

Signed-off-by: Christopher Voltz <[email protected]>
  • Loading branch information
cvoltz committed Aug 2, 2019
1 parent d3026f1 commit 1884a0b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ threshold_score: 10 # default is 0
deduplicate_symlinks: true # default is false
suppress_ratings: true # default is false
no_browser: true # default is false
format: console # Available values are: html, json, console, lint. Default value is html.
formats: # Available values are: html, json, console, lint. Default value is html.
- console
minimum_score: 95 # default is 0
paths: # Files to analyse.
- 'app/controllers/'
Expand Down
2 changes: 1 addition & 1 deletion lib/rubycritic/cli/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def to_h
argv_hash = argv_options.to_h

file_hash.merge(argv_hash) do |_, file_option, argv_option|
argv_option.nil? ? file_option : argv_option
Array(argv_option).empty? ? file_option : argv_option
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubycritic/cli/options/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def no_browser
end

def formats
formats = options['formats'] || []
formats = Array(options['formats'])
formats.select do |format|
%w[html json console lint].include?(format)
end
end.map(&:to_sym)
end

def minimum_score
Expand Down

0 comments on commit 1884a0b

Please sign in to comment.