From 1884a0b03130e99890f75105da858d1e3226d2db Mon Sep 17 00:00:00 2001 From: Christopher Voltz Date: Fri, 2 Aug 2019 14:09:57 -0500 Subject: [PATCH] Fix YAML configuration file 'formats' processing Fixes: Ignores .rubycritic.yml file #303 https://github.com/whitesmith/rubycritic/issues/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 --- README.md | 3 ++- lib/rubycritic/cli/options.rb | 2 +- lib/rubycritic/cli/options/file.rb | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e3c6637b..3adcf2ed 100644 --- a/README.md +++ b/README.md @@ -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/' diff --git a/lib/rubycritic/cli/options.rb b/lib/rubycritic/cli/options.rb index 061508c1..8b5008a0 100644 --- a/lib/rubycritic/cli/options.rb +++ b/lib/rubycritic/cli/options.rb @@ -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 diff --git a/lib/rubycritic/cli/options/file.rb b/lib/rubycritic/cli/options/file.rb index ea103357..35f7a32f 100644 --- a/lib/rubycritic/cli/options/file.rb +++ b/lib/rubycritic/cli/options/file.rb @@ -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