From 88c1bad43193b3a3c5fccbff89a281d22a58a5b1 Mon Sep 17 00:00:00 2001 From: rishijain Date: Wed, 25 Oct 2023 19:30:14 +0700 Subject: [PATCH] added support for wildcard entries to rubycritic yml --- .reek.yml | 5 +++++ .rubocop.yml | 8 ++++++++ CHANGELOG.md | 2 ++ lib/rubycritic/configuration.rb | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/.reek.yml b/.reek.yml index e35fae5a..171090bf 100644 --- a/.reek.yml +++ b/.reek.yml @@ -92,9 +92,11 @@ detectors: DuplicateMethodCall: exclude: - RubyCritic::Analyser::Churn#run + - RubyCritic::Configuration#set - Parser::AST::Node#module_name TooManyStatements: exclude: + - RubyCritic::Configuration#find_directories - RubyCritic::RakeTask#initialize - RubyCritic::Analyser::Complexity#run - RubyCritic::Analyser::Coverage#synchronize_resultset @@ -118,6 +120,7 @@ detectors: - RubyCritic::ViewHelpers#smell_location_path - RubyCritic::Generator::HtmlReport#create_directories_and_files - RubyCritic::SourceLocator#deduplicate_symlinks + - RubyCritic::Configuration#setup_paths_for_targets NestedIterators: exclude: - Parser::AST::Node#recursive_children @@ -125,8 +128,10 @@ detectors: - RubyCritic::Cli::Options::Argv#parse - RubyCritic::Generator::HtmlReport#create_directories_and_files - RubyCritic::AnalysedModulesCollection#initialize + - RubyCritic::Configuration#find_directories UtilityFunction: exclude: + - RubyCritic::Configuration#find_directories - RubyCritic::Analyser::Coverage#resultset_path - RubyCritic::Analyser::Coverage#resultset_writelock - RubyCritic::Analyser::FlaySmells#cost diff --git a/.rubocop.yml b/.rubocop.yml index 916bc579..a56cccdb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -85,3 +85,11 @@ Lint/StructNewOverride: Metrics/AbcSize: Exclude: - 'lib/rubycritic/configuration.rb' + +Metrics/MethodLength: + Exclude: + - 'lib/rubycritic/configuration.rb' + +Style/RedundantAssignment: + Exclude: + - 'lib/rubycritic/configuration.rb' diff --git a/CHANGELOG.md b/CHANGELOG.md index af624507..1ba3f461 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # main [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v4.9.0...main) +* [CHANGE] Add support for wildcard entries to the paths option in rubycritic.yml (by [@rishiain][]) + # v4.9.0 / 2023-10-18 [(commits)](https://github.com/whitesmith/rubycritic/compare/v4.8.1...v4.9.0) * [CHANGE] Bump aruba, cucumber, fakefs, flog, mdl, minitest, and rubocop dependencies (by [@faisal][]) diff --git a/lib/rubycritic/configuration.rb b/lib/rubycritic/configuration.rb index 8f740648..8a291200 100644 --- a/lib/rubycritic/configuration.rb +++ b/lib/rubycritic/configuration.rb @@ -20,11 +20,16 @@ def set(options) self.open_with = options[:open_with] self.no_browser = options[:no_browser] self.threshold_score = options[:threshold_score].to_i + setup_paths_for_targets(options) if options[:paths] setup_analysis_targets(options) setup_version_control(options) setup_formats(options) end + def setup_paths_for_targets(options) + options[:paths] = find_directories(options[:paths]) + end + def setup_analysis_targets(options) self.paths = options[:paths] || ['.'] self.ruby_extensions = options[:ruby_extensions] || %w[.rb .rake .thor] @@ -50,6 +55,20 @@ def source_control_present? source_control_system && !source_control_system.is_a?(SourceControlSystem::Double) end + + private + + def find_directories(paths) + expanded_paths = paths.flat_map do |path| + if path.include?('**') + search_pattern = File.join(path) + Dir.glob(search_pattern).select { |tmp_path| File.directory?(tmp_path) && !tmp_path.start_with?('tmp') } + else + path + end + end + expanded_paths + end end module Config