Skip to content

Commit

Permalink
Configurable coverage path (#481)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
etagwerker and exoego authored Mar 2, 2024
1 parent 7c83ab1 commit 9b8cddf
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -183,4 +184,5 @@ detectors:
- RubyCritic::Config#self.respond_to_missing?
TooManyMethods:
exclude:
- RubyCritic::Cli::Options::File
- RubyCritic::SourceControlSystem::Git::Churn
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ AllCops:
Metrics/BlockLength:
Enabled: false

Metrics/MethodLength:
Exclude:
- "lib/rubycritic/configuration.rb"

Layout/LineLength:
Max: 120

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -444,3 +445,4 @@
[@96RadhikaJadhav]: https://github.com/96RadhikaJadhav
[@Fito]: https://github.com/Fito
[@fbuys]: https://github.com/fbuys
[@exoego]: https://github.com/exoego
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)<sup>1</sup> |
| `--custom-format path:classname` | Load and instantiate custom formatter(s)<sup>2</sup> |
| `-s` / `--minimum-score` | Set a minimum score (FLOAT: ex: 96.28), default: 0 |
| `-m` / `--mode-ci` | Use CI mode<sup>3</sup> |
| `-b` / `--branch` | Set branch to compare |
| `-t` / `--maximum-decrease` | Threshold for score difference between two branches<sup>4</sup> |
| `--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)<sup>1</sup> |
| `--custom-format path:classname` | Load and instantiate custom formatter(s)<sup>2</sup> |
| `-s` / `--minimum-score` | Set a minimum score (FLOAT: ex: 96.28), default: 0 |
| `-m` / `--mode-ci` | Use CI mode<sup>3</sup> |
| `-b` / `--branch` | Set branch to compare |
| `-t` / `--maximum-decrease` | Threshold for score difference between two branches<sup>4</sup> |
| `--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)
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions features/command_line_interface/options.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/rubycritic/analysers/coverage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion lib/rubycritic/cli/options/argv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
5 changes: 5 additions & 0 deletions lib/rubycritic/cli/options/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def to_h
{
mode: mode,
root: root,
coverage_path: coverage_path,
formats: formats,
deduplicate_symlinks: deduplicate_symlinks,
paths: paths,
Expand Down Expand Up @@ -59,6 +60,10 @@ def root
options['path']
end

def coverage_path
options['coverage_path']
end

def threshold_score
options['threshold_score']
end
Expand Down
3 changes: 2 additions & 1 deletion lib/rubycritic/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 9b8cddf

Please sign in to comment.