From 9b8cddf1c6cd650135bd9e4e70a125e3bdae1fb7 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Sat, 2 Mar 2024 16:49:16 -0500 Subject: [PATCH] Configurable coverage path (#481) * Support configurable coverage_path * Correct reek configuration This was not working as expected because of a poor merge effort * Exclude options from methods length cop * Add empty last line to comply --------- Co-authored-by: TATSUNO Yasuhiro --- .reek.yml | 2 ++ .rubocop.yml | 4 +++ CHANGELOG.md | 2 ++ README.md | 28 ++++++++++--------- .../command_line_interface/options.feature | 1 + lib/rubycritic/analysers/coverage.rb | 3 ++ lib/rubycritic/cli/options/argv.rb | 6 +++- lib/rubycritic/cli/options/file.rb | 5 ++++ lib/rubycritic/configuration.rb | 3 +- 9 files changed, 39 insertions(+), 15 deletions(-) diff --git a/.reek.yml b/.reek.yml index e35fae5a..fe8393dd 100644 --- a/.reek.yml +++ b/.reek.yml @@ -68,6 +68,7 @@ detectors: - RubyCritic::Configuration#format - RubyCritic::Configuration#mode - RubyCritic::Configuration#no_browser + - RubyCritic::Configuration#coverage_path - RubyCritic::Configuration#open_with - RubyCritic::Configuration#paths - RubyCritic::Configuration#source_control_system @@ -183,4 +184,5 @@ detectors: - RubyCritic::Config#self.respond_to_missing? TooManyMethods: exclude: + - RubyCritic::Cli::Options::File - RubyCritic::SourceControlSystem::Git::Churn diff --git a/.rubocop.yml b/.rubocop.yml index 916bc579..52bc57d5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -16,6 +16,10 @@ AllCops: Metrics/BlockLength: Enabled: false +Metrics/MethodLength: + Exclude: + - "lib/rubycritic/configuration.rb" + Layout/LineLength: Max: 120 diff --git a/CHANGELOG.md b/CHANGELOG.md index bf11ba10..d4f11600 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # main [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v4.9.0...main) * [CHANGE] Fix some typos (by [@jbampton][]) +* [FEATURE] Add coverage_path configuration option (by [@exoego][]) # v4.9.0 / 2023-10-18 [(commits)](https://github.com/whitesmith/rubycritic/compare/v4.8.1...v4.9.0) @@ -444,3 +445,4 @@ [@96RadhikaJadhav]: https://github.com/96RadhikaJadhav [@Fito]: https://github.com/Fito [@fbuys]: https://github.com/fbuys +[@exoego]: https://github.com/exoego diff --git a/README.md b/README.md index 09452a5d..c268f6ca 100644 --- a/README.md +++ b/README.md @@ -107,19 +107,20 @@ For a full list of the command-line options run: $ rubycritic --help ``` -| Command flag | Description | -|-------------------------------------|-----------------------------------------------------------------| -| `-v` / `--version` | Displays the current version and exits | -| `-p` / `--path` | Set path where report will be saved (tmp/rubycritic by default) | -| `-f` / `--format` | Report smells in the given format(s)1 | -| `--custom-format path:classname` | Load and instantiate custom formatter(s)2 | -| `-s` / `--minimum-score` | Set a minimum score (FLOAT: ex: 96.28), default: 0 | -| `-m` / `--mode-ci` | Use CI mode3 | -| `-b` / `--branch` | Set branch to compare | -| `-t` / `--maximum-decrease` | Threshold for score difference between two branches4 | -| `--deduplicate-symlinks` | De-duplicate symlinks based on their final target | -| `--suppress-ratings` | Suppress letter ratings | -| `--no-browser` | Do not open html report with browser | +| Command flag | Description | +|----------------------------------|-----------------------------------------------------------------| +| `-v` / `--version` | Displays the current version and exits | +| `-p` / `--path` | Set path where report will be saved (tmp/rubycritic by default) | +| `--coverage-path` | Set path where SimpleCov will be saved (./coverage by default) | +| `-f` / `--format` | Report smells in the given format(s)1 | +| `--custom-format path:classname` | Load and instantiate custom formatter(s)2 | +| `-s` / `--minimum-score` | Set a minimum score (FLOAT: ex: 96.28), default: 0 | +| `-m` / `--mode-ci` | Use CI mode3 | +| `-b` / `--branch` | Set branch to compare | +| `-t` / `--maximum-decrease` | Threshold for score difference between two branches4 | +| `--deduplicate-symlinks` | De-duplicate symlinks based on their final target | +| `--suppress-ratings` | Suppress letter ratings | +| `--no-browser` | Do not open html report with browser | 1. Available output formats: - `html` (default; will open in a browser) @@ -140,6 +141,7 @@ mode_ci: branch: 'production' # default is main branch: 'production' # default is main path: '/tmp/mycustompath' # Set path where report will be saved (tmp/rubycritic by default) +coverage_path: '/tmp/coverage' # Set path where SimpleCov coverage will be saved (./coverage by default) threshold_score: 10 # default is 0 deduplicate_symlinks: true # default is false suppress_ratings: true # default is false diff --git a/features/command_line_interface/options.feature b/features/command_line_interface/options.feature index fefbbc05..ddfcbd3e 100644 --- a/features/command_line_interface/options.feature +++ b/features/command_line_interface/options.feature @@ -47,6 +47,7 @@ Feature: RubyCritic can be controlled using command-line options --deduplicate-symlinks De-duplicate symlinks based on their final target --suppress-ratings Suppress letter ratings --no-browser Do not open html report with browser + --coverage-path [PATH] SimpleCov coverage will be saved (./coverage by default) -v, --version Show gem's version -h, --help Show this message diff --git a/lib/rubycritic/analysers/coverage.rb b/lib/rubycritic/analysers/coverage.rb index feaa8e8d..fec0e564 100644 --- a/lib/rubycritic/analysers/coverage.rb +++ b/lib/rubycritic/analysers/coverage.rb @@ -48,6 +48,9 @@ def find_source_file(analysed_module) # The path to the cache file def resultset_path + if (cp = Config.coverage_path) + SimpleCov.coverage_dir(cp) + end File.join(SimpleCov.coverage_path, RESULTSET_FILENAME) end diff --git a/lib/rubycritic/cli/options/argv.rb b/lib/rubycritic/cli/options/argv.rb index f045404d..b1a18b1f 100644 --- a/lib/rubycritic/cli/options/argv.rb +++ b/lib/rubycritic/cli/options/argv.rb @@ -95,6 +95,10 @@ def parse self.no_browser = true end + opts.on('--coverage-path [PATH]', 'SimpleCov coverage will be saved (./coverage by default)') do |path| + @coverage_path = path + end + opts.on_tail('-v', '--version', "Show gem's version") do self.mode = :version end @@ -129,7 +133,7 @@ def to_h attr_accessor :mode, :root, :formats, :formatters, :deduplicate_symlinks, :suppress_ratings, :minimum_score, :churn_after, :no_browser, - :parser, :base_branch, :feature_branch, :threshold_score + :parser, :base_branch, :feature_branch, :threshold_score, :coverage_path def paths @argv unless @argv.empty? diff --git a/lib/rubycritic/cli/options/file.rb b/lib/rubycritic/cli/options/file.rb index a446eb84..1e1c4413 100644 --- a/lib/rubycritic/cli/options/file.rb +++ b/lib/rubycritic/cli/options/file.rb @@ -22,6 +22,7 @@ def to_h { mode: mode, root: root, + coverage_path: coverage_path, formats: formats, deduplicate_symlinks: deduplicate_symlinks, paths: paths, @@ -59,6 +60,10 @@ def root options['path'] end + def coverage_path + options['coverage_path'] + end + def threshold_score options['threshold_score'] end diff --git a/lib/rubycritic/configuration.rb b/lib/rubycritic/configuration.rb index 8f740648..07dbf6b7 100644 --- a/lib/rubycritic/configuration.rb +++ b/lib/rubycritic/configuration.rb @@ -6,7 +6,7 @@ module RubyCritic class Configuration attr_reader :root attr_accessor :source_control_system, :mode, :formats, :formatters, :deduplicate_symlinks, - :suppress_ratings, :open_with, :no_browser, :base_branch, + :suppress_ratings, :open_with, :no_browser, :base_branch, :coverage_path, :feature_branch, :base_branch_score, :feature_branch_score, :base_root_directory, :feature_root_directory, :compare_root_directory, :threshold_score, :base_branch_collection, @@ -19,6 +19,7 @@ def set(options) self.suppress_ratings = options[:suppress_ratings] self.open_with = options[:open_with] self.no_browser = options[:no_browser] + self.coverage_path = options[:coverage_path] self.threshold_score = options[:threshold_score].to_i setup_analysis_targets(options) setup_version_control(options)