Skip to content

Commit 9b8cddf

Browse files
etagwerkerexoego
andauthored
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 <[email protected]>
1 parent 7c83ab1 commit 9b8cddf

File tree

9 files changed

+39
-15
lines changed

9 files changed

+39
-15
lines changed

.reek.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ detectors:
6868
- RubyCritic::Configuration#format
6969
- RubyCritic::Configuration#mode
7070
- RubyCritic::Configuration#no_browser
71+
- RubyCritic::Configuration#coverage_path
7172
- RubyCritic::Configuration#open_with
7273
- RubyCritic::Configuration#paths
7374
- RubyCritic::Configuration#source_control_system
@@ -183,4 +184,5 @@ detectors:
183184
- RubyCritic::Config#self.respond_to_missing?
184185
TooManyMethods:
185186
exclude:
187+
- RubyCritic::Cli::Options::File
186188
- RubyCritic::SourceControlSystem::Git::Churn

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ AllCops:
1616
Metrics/BlockLength:
1717
Enabled: false
1818

19+
Metrics/MethodLength:
20+
Exclude:
21+
- "lib/rubycritic/configuration.rb"
22+
1923
Layout/LineLength:
2024
Max: 120
2125

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# main [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v4.9.0...main)
22

33
* [CHANGE] Fix some typos (by [@jbampton][])
4+
* [FEATURE] Add coverage_path configuration option (by [@exoego][])
45

56
# v4.9.0 / 2023-10-18 [(commits)](https://github.com/whitesmith/rubycritic/compare/v4.8.1...v4.9.0)
67

@@ -444,3 +445,4 @@
444445
[@96RadhikaJadhav]: https://github.com/96RadhikaJadhav
445446
[@Fito]: https://github.com/Fito
446447
[@fbuys]: https://github.com/fbuys
448+
[@exoego]: https://github.com/exoego

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,20 @@ For a full list of the command-line options run:
107107
$ rubycritic --help
108108
```
109109

110-
| Command flag | Description |
111-
|-------------------------------------|-----------------------------------------------------------------|
112-
| `-v` / `--version` | Displays the current version and exits |
113-
| `-p` / `--path` | Set path where report will be saved (tmp/rubycritic by default) |
114-
| `-f` / `--format` | Report smells in the given format(s)<sup>1</sup> |
115-
| `--custom-format path:classname` | Load and instantiate custom formatter(s)<sup>2</sup> |
116-
| `-s` / `--minimum-score` | Set a minimum score (FLOAT: ex: 96.28), default: 0 |
117-
| `-m` / `--mode-ci` | Use CI mode<sup>3</sup> |
118-
| `-b` / `--branch` | Set branch to compare |
119-
| `-t` / `--maximum-decrease` | Threshold for score difference between two branches<sup>4</sup> |
120-
| `--deduplicate-symlinks` | De-duplicate symlinks based on their final target |
121-
| `--suppress-ratings` | Suppress letter ratings |
122-
| `--no-browser` | Do not open html report with browser |
110+
| Command flag | Description |
111+
|----------------------------------|-----------------------------------------------------------------|
112+
| `-v` / `--version` | Displays the current version and exits |
113+
| `-p` / `--path` | Set path where report will be saved (tmp/rubycritic by default) |
114+
| `--coverage-path` | Set path where SimpleCov will be saved (./coverage by default) |
115+
| `-f` / `--format` | Report smells in the given format(s)<sup>1</sup> |
116+
| `--custom-format path:classname` | Load and instantiate custom formatter(s)<sup>2</sup> |
117+
| `-s` / `--minimum-score` | Set a minimum score (FLOAT: ex: 96.28), default: 0 |
118+
| `-m` / `--mode-ci` | Use CI mode<sup>3</sup> |
119+
| `-b` / `--branch` | Set branch to compare |
120+
| `-t` / `--maximum-decrease` | Threshold for score difference between two branches<sup>4</sup> |
121+
| `--deduplicate-symlinks` | De-duplicate symlinks based on their final target |
122+
| `--suppress-ratings` | Suppress letter ratings |
123+
| `--no-browser` | Do not open html report with browser |
123124

124125
1. Available output formats:
125126
- `html` (default; will open in a browser)
@@ -140,6 +141,7 @@ mode_ci:
140141
branch: 'production' # default is main
141142
branch: 'production' # default is main
142143
path: '/tmp/mycustompath' # Set path where report will be saved (tmp/rubycritic by default)
144+
coverage_path: '/tmp/coverage' # Set path where SimpleCov coverage will be saved (./coverage by default)
143145
threshold_score: 10 # default is 0
144146
deduplicate_symlinks: true # default is false
145147
suppress_ratings: true # default is false

features/command_line_interface/options.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Feature: RubyCritic can be controlled using command-line options
4747
--deduplicate-symlinks De-duplicate symlinks based on their final target
4848
--suppress-ratings Suppress letter ratings
4949
--no-browser Do not open html report with browser
50+
--coverage-path [PATH] SimpleCov coverage will be saved (./coverage by default)
5051
-v, --version Show gem's version
5152
-h, --help Show this message
5253

lib/rubycritic/analysers/coverage.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def find_source_file(analysed_module)
4848

4949
# The path to the cache file
5050
def resultset_path
51+
if (cp = Config.coverage_path)
52+
SimpleCov.coverage_dir(cp)
53+
end
5154
File.join(SimpleCov.coverage_path, RESULTSET_FILENAME)
5255
end
5356

lib/rubycritic/cli/options/argv.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def parse
9595
self.no_browser = true
9696
end
9797

98+
opts.on('--coverage-path [PATH]', 'SimpleCov coverage will be saved (./coverage by default)') do |path|
99+
@coverage_path = path
100+
end
101+
98102
opts.on_tail('-v', '--version', "Show gem's version") do
99103
self.mode = :version
100104
end
@@ -129,7 +133,7 @@ def to_h
129133

130134
attr_accessor :mode, :root, :formats, :formatters, :deduplicate_symlinks,
131135
:suppress_ratings, :minimum_score, :churn_after, :no_browser,
132-
:parser, :base_branch, :feature_branch, :threshold_score
136+
:parser, :base_branch, :feature_branch, :threshold_score, :coverage_path
133137

134138
def paths
135139
@argv unless @argv.empty?

lib/rubycritic/cli/options/file.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def to_h
2222
{
2323
mode: mode,
2424
root: root,
25+
coverage_path: coverage_path,
2526
formats: formats,
2627
deduplicate_symlinks: deduplicate_symlinks,
2728
paths: paths,
@@ -59,6 +60,10 @@ def root
5960
options['path']
6061
end
6162

63+
def coverage_path
64+
options['coverage_path']
65+
end
66+
6267
def threshold_score
6368
options['threshold_score']
6469
end

lib/rubycritic/configuration.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module RubyCritic
66
class Configuration
77
attr_reader :root
88
attr_accessor :source_control_system, :mode, :formats, :formatters, :deduplicate_symlinks,
9-
:suppress_ratings, :open_with, :no_browser, :base_branch,
9+
:suppress_ratings, :open_with, :no_browser, :base_branch, :coverage_path,
1010
:feature_branch, :base_branch_score, :feature_branch_score,
1111
:base_root_directory, :feature_root_directory,
1212
:compare_root_directory, :threshold_score, :base_branch_collection,
@@ -19,6 +19,7 @@ def set(options)
1919
self.suppress_ratings = options[:suppress_ratings]
2020
self.open_with = options[:open_with]
2121
self.no_browser = options[:no_browser]
22+
self.coverage_path = options[:coverage_path]
2223
self.threshold_score = options[:threshold_score].to_i
2324
setup_analysis_targets(options)
2425
setup_version_control(options)

0 commit comments

Comments
 (0)