crap4ruby 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +13 -4
- data/lib/crap4ruby/cli.rb +4 -1
- data/lib/crap4ruby/report.rb +17 -0
- data/lib/crap4ruby/version.rb +1 -1
- data/sig/crap4ruby.rbs +2 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 365b5fb5f2ef4c7c0f38cb53afe0cc689dc11d2abdd18129927bfaedbf305430
|
|
4
|
+
data.tar.gz: 06d039700eef30031089877bbf03823e4fbad79d882ac083a4f91cfba3e1f0fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aded83410c9291f84556aa261d6c9a942b2a414d01b42cb1ce4a301304f9ccd1a2538d375ae6e479720d62202f4943e9de537858060838082e2f90d74e95328e
|
|
7
|
+
data.tar.gz: 53cbeb8c9ef702dd75c63e2459ce508a9f069993f80290cd5ed2894499a6f4054be8815331c9c0643db2539613c24f1e749997588035a0896b53f61140a27c86
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,16 @@ Version numbers follow [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [0.2.3] - 2026-11-06
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Add `--verbose` to show the complete method table. The `-v` option continues to print the version.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Limit normal terminal output to CRAP scores strictly above 30 and unknown scores. An explicit `--threshold` overrides the display limit and retains its enforcement behavior. Snapshots retain all analyzed methods.
|
|
17
|
+
|
|
8
18
|
## [0.2.2] - 2026-10-29
|
|
9
19
|
|
|
10
20
|
### Added
|
|
@@ -58,7 +68,8 @@ Version numbers follow [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.
|
|
|
58
68
|
|
|
59
69
|
- Split CLI execution, AST discovery, and coverage loading into smaller methods without changing their behavior or scoring rules.
|
|
60
70
|
|
|
61
|
-
[Unreleased]: https://github.com/svyatov/crap4ruby/compare/v0.2.
|
|
71
|
+
[Unreleased]: https://github.com/svyatov/crap4ruby/compare/v0.2.3...HEAD
|
|
72
|
+
[0.2.3]: https://github.com/svyatov/crap4ruby/compare/v0.2.2...v0.2.3
|
|
62
73
|
[0.2.2]: https://github.com/svyatov/crap4ruby/compare/v0.2.1...v0.2.2
|
|
63
74
|
[0.2.1]: https://github.com/svyatov/crap4ruby/compare/v0.2.0...v0.2.1
|
|
64
75
|
[0.2.0]: https://github.com/svyatov/crap4ruby/compare/v0.1.1...v0.2.0
|
data/README.md
CHANGED
|
@@ -30,12 +30,19 @@ In an existing project, select the source you want to measure:
|
|
|
30
30
|
crap4ruby --no-coverage
|
|
31
31
|
crap4ruby
|
|
32
32
|
crap4ruby --threshold 30
|
|
33
|
+
crap4ruby --verbose
|
|
33
34
|
crap4ruby app/models/user.rb
|
|
34
35
|
crap4ruby app/models lib/billing
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
The first command reports complexity alone. The other commands require `coverage/.resultset.json` from your project's test run.
|
|
38
39
|
|
|
40
|
+
Default output shows methods with CRAP scores strictly above 30, plus methods with unknown scores.
|
|
41
|
+
An explicit `--threshold NUMBER` sets both the display limit and the enforced limit.
|
|
42
|
+
The default display limit does not enforce a threshold or change the exit status.
|
|
43
|
+
Use `--verbose` to show every analyzed method. Snapshots always contain every analyzed method.
|
|
44
|
+
With `--no-coverage`, every CRAP score is unknown, so every method remains visible.
|
|
45
|
+
|
|
39
46
|
To use Bundler, add `gem "crap4ruby", require: false` to your project's `Gemfile` and run `bundle install`.
|
|
40
47
|
Run the tool with `bundle exec crap4ruby`.
|
|
41
48
|
|
|
@@ -46,7 +53,7 @@ Run these commands from this checkout with Ruby 3.3 or newer:
|
|
|
46
53
|
```sh
|
|
47
54
|
bundle install
|
|
48
55
|
gem build crap4ruby.gemspec
|
|
49
|
-
gem install ./crap4ruby-0.2.
|
|
56
|
+
gem install ./crap4ruby-0.2.3.gem
|
|
50
57
|
```
|
|
51
58
|
|
|
52
59
|
To use Bundler in the measured project, add this checkout to that project's `Gemfile`:
|
|
@@ -97,8 +104,9 @@ crap4ruby does not configure SimpleCov, delete reports, install dependencies, or
|
|
|
97
104
|
| `--coverage-command COMMAND` | Run a shell command that refreshes the selected report. |
|
|
98
105
|
| `--no-coverage` | Report complexity with unknown coverage and CRAP. |
|
|
99
106
|
| `--no-save` | Print results without creating or replacing `.metrics/crap.edn`. |
|
|
107
|
+
| `--verbose` | Show every analyzed method, including scores at or below the display limit. |
|
|
100
108
|
| `--jobs N` | Set a positive worker count; `1` forces serial analysis. The default selects workers automatically. |
|
|
101
|
-
| `--threshold NUMBER` |
|
|
109
|
+
| `--threshold NUMBER` | Set the display limit and check this finite, nonnegative limit; exit 2 for a measured violation, or 1 if an unknown score could exceed it. |
|
|
102
110
|
| `-h`, `--help` | Print usage. |
|
|
103
111
|
| `-v`, `--version` | Print the gem version. |
|
|
104
112
|
|
|
@@ -171,7 +179,7 @@ Reports are accepted as supplied; generate fresh coverage after changing source
|
|
|
171
179
|
## Snapshot
|
|
172
180
|
|
|
173
181
|
The table lists the highest scores first, followed by entries with unknown scores.
|
|
174
|
-
The atomically replaced `.metrics/crap.edn` contains the same
|
|
182
|
+
The atomically replaced `.metrics/crap.edn` contains every analyzed method in the same order, with coverage expressed as a percentage:
|
|
175
183
|
|
|
176
184
|
```clojure
|
|
177
185
|
{:entries [
|
|
@@ -184,7 +192,8 @@ Instance method names are `charge`; singleton method names are `self.charge`.
|
|
|
184
192
|
`--no-coverage` writes `nil` for both `:coverage` and `:crap`.
|
|
185
193
|
|
|
186
194
|
The shape matches crapper's snapshot. This gem does not add Ruby support to crapper or its consumers.
|
|
187
|
-
A
|
|
195
|
+
A run restricted by source paths or `--changed` writes only its selected methods. Display filtering leaves the snapshot complete.
|
|
196
|
+
Reopened classes and repeated definitions can produce repeated namespace/name pairs.
|
|
188
197
|
|
|
189
198
|
## Limits
|
|
190
199
|
|
data/lib/crap4ruby/cli.rb
CHANGED
|
@@ -38,7 +38,8 @@ module Crap4Ruby
|
|
|
38
38
|
path = Report.write(entries, root: root)
|
|
39
39
|
@stderr.puts("Wrote #{path}")
|
|
40
40
|
end
|
|
41
|
-
@stdout.write(Report.
|
|
41
|
+
@stdout.write(Report.terminal(entries,
|
|
42
|
+
threshold: options.fetch(:threshold, 30), verbose: options[:verbose] == true))
|
|
42
43
|
threshold_status(entries, options[:threshold])
|
|
43
44
|
rescue Error, OptionParser::ParseError, SystemCallError => error
|
|
44
45
|
@stderr.puts("crap4ruby: #{error.message}")
|
|
@@ -57,6 +58,7 @@ module Crap4Ruby
|
|
|
57
58
|
options = {root: Dir.pwd, source_roots: [], changed: false, coverage: "coverage/.resultset.json"}
|
|
58
59
|
parser = OptionParser.new do |cli|
|
|
59
60
|
cli.banner = "Usage: crap4ruby [options] [file-or-directory-or-filter ...]"
|
|
61
|
+
cli.separator "Default output: CRAP > 30 and unknown scores; --threshold sets the display limit."
|
|
60
62
|
cli.on("--root PATH", "Project root (default: current directory)") do |path|
|
|
61
63
|
# @type var path: String
|
|
62
64
|
options[:root] = path
|
|
@@ -72,6 +74,7 @@ module Crap4Ruby
|
|
|
72
74
|
end
|
|
73
75
|
cli.on("--no-coverage", "Complexity only; coverage and CRAP are N/A") { options[:no_coverage] = true }
|
|
74
76
|
cli.on("--no-save", "Print results without writing .metrics/crap.edn") { options[:no_save] = true }
|
|
77
|
+
cli.on("--verbose", "Show all analyzed methods") { options[:verbose] = true }
|
|
75
78
|
cli.on("--jobs N", Integer, "Worker processes (default: automatic; 1 disables workers)") do |jobs|
|
|
76
79
|
# @type var jobs: Integer
|
|
77
80
|
raise OptionParser::InvalidArgument, "jobs must be positive" if jobs < 1
|
data/lib/crap4ruby/report.rb
CHANGED
|
@@ -15,6 +15,23 @@ module Crap4Ruby
|
|
|
15
15
|
entries.sort_by { |entry| [entry.crap ? 0 : 1, -(entry.crap || 0), entry.namespace, entry.name, entry.path] }
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
# Formats methods above the display limit and methods with unknown scores.
|
|
19
|
+
# Verbose output includes every entry, preserving the complete table format.
|
|
20
|
+
#
|
|
21
|
+
# @param entries [Array<Entry>] results in display order
|
|
22
|
+
# @param threshold [Integer, Float, Rational] exclusive display limit
|
|
23
|
+
# @param verbose [Boolean] whether to show all entries
|
|
24
|
+
# @return [String] terminal table or empty-result message, ending with a newline
|
|
25
|
+
def self.terminal(entries, threshold: 30, verbose: false)
|
|
26
|
+
return table(entries) if verbose
|
|
27
|
+
return "No methods found.\n" if entries.empty?
|
|
28
|
+
|
|
29
|
+
visible = entries.select { |entry| !entry.crap || entry.crap > threshold }
|
|
30
|
+
return "No methods exceed CRAP #{threshold.to_f.to_s.delete_suffix(".0")}.\n" if visible.empty?
|
|
31
|
+
|
|
32
|
+
table(visible)
|
|
33
|
+
end
|
|
34
|
+
|
|
18
35
|
# Formats a terminal table, preserving entry order and displaying unknown values as N/A.
|
|
19
36
|
#
|
|
20
37
|
# @param entries [Array<Entry>] results in display order
|
data/lib/crap4ruby/version.rb
CHANGED
data/sig/crap4ruby.rbs
CHANGED
|
@@ -99,6 +99,7 @@ module Crap4Ruby
|
|
|
99
99
|
|
|
100
100
|
module Report
|
|
101
101
|
def self.sorted: (Array[Entry] entries) -> Array[Entry]
|
|
102
|
+
def self.terminal: (Array[Entry] entries, ?threshold: Integer | score, ?verbose: bool) -> String
|
|
102
103
|
def self.table: (Array[Entry] entries) -> String
|
|
103
104
|
def self.label: (String value) -> String
|
|
104
105
|
def self.edn: (Array[Entry] entries) -> String
|
|
@@ -114,7 +115,7 @@ module Crap4Ruby
|
|
|
114
115
|
class CLI
|
|
115
116
|
type options = { root: String, source_roots: Array[String], changed: bool, coverage: String,
|
|
116
117
|
?help: bool, ?version: bool, ?no_coverage: bool, ?no_save: bool, ?existing: bool, ?command: String,
|
|
117
|
-
?threshold: Rational, ?jobs: Integer }
|
|
118
|
+
?threshold: Rational, ?jobs: Integer, ?verbose: bool }
|
|
118
119
|
@stdout: _Output
|
|
119
120
|
@stderr: _Output
|
|
120
121
|
def initialize: (?stdout: _Output, ?stderr: _Output) -> void
|