crap4ruby 0.2.2 → 0.2.4
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 +19 -1
- data/README.md +18 -6
- data/lib/crap4ruby/analyzer.rb +1 -1
- 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: dada0d1d790a96c73811f6970d4aca07935dff096805da03f7a1c88b915420de
|
|
4
|
+
data.tar.gz: 8e5c903bd1b45a6f4eea147af46669ab49a81753b90d6760e77b121c462d5983
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4d183c752379bb1e86e2e5ef1be3a9bf40767c2d4af2e1d9ed4e5eacc9afc6f904ce5a10d8f7f5aa92012ced727e7ed11803312e66054bccc6e27d28f82b1f8b
|
|
7
|
+
data.tar.gz: b7006ec2c0f4708a1bde7a0d8632c541cc5cc1ec42df2ebc2d31e8d053075f6d05953237bbcaf4338062619a67a92e87261aa0afd0e501ccff6f08184e702314
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,22 @@ Version numbers follow [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [0.2.4] - 2026-11-13
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Preserve parsing of the newest supported Ruby syntax with Prism 2.x, independently of the Ruby version running crap4ruby.
|
|
13
|
+
|
|
14
|
+
## [0.2.3] - 2026-11-06
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- Add `--verbose` to show the complete method table. The `-v` option continues to print the version.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- 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.
|
|
23
|
+
|
|
8
24
|
## [0.2.2] - 2026-10-29
|
|
9
25
|
|
|
10
26
|
### Added
|
|
@@ -58,7 +74,9 @@ Version numbers follow [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.
|
|
|
58
74
|
|
|
59
75
|
- Split CLI execution, AST discovery, and coverage loading into smaller methods without changing their behavior or scoring rules.
|
|
60
76
|
|
|
61
|
-
[Unreleased]: https://github.com/svyatov/crap4ruby/compare/v0.2.
|
|
77
|
+
[Unreleased]: https://github.com/svyatov/crap4ruby/compare/v0.2.4...HEAD
|
|
78
|
+
[0.2.4]: https://github.com/svyatov/crap4ruby/compare/v0.2.3...v0.2.4
|
|
79
|
+
[0.2.3]: https://github.com/svyatov/crap4ruby/compare/v0.2.2...v0.2.3
|
|
62
80
|
[0.2.2]: https://github.com/svyatov/crap4ruby/compare/v0.2.1...v0.2.2
|
|
63
81
|
[0.2.1]: https://github.com/svyatov/crap4ruby/compare/v0.2.0...v0.2.1
|
|
64
82
|
[0.2.0]: https://github.com/svyatov/crap4ruby/compare/v0.1.1...v0.2.0
|
data/README.md
CHANGED
|
@@ -11,6 +11,8 @@ crap4ruby identifies complex, under-tested Ruby methods using the Change Risk An
|
|
|
11
11
|
|
|
12
12
|
Ruby 3.3 or newer is required.
|
|
13
13
|
|
|
14
|
+
Source parsing uses the newest Ruby syntax supported by the installed Prism version, independently of the Ruby version running crap4ruby.
|
|
15
|
+
|
|
14
16
|
```sh
|
|
15
17
|
gem install crap4ruby
|
|
16
18
|
```
|
|
@@ -30,12 +32,19 @@ In an existing project, select the source you want to measure:
|
|
|
30
32
|
crap4ruby --no-coverage
|
|
31
33
|
crap4ruby
|
|
32
34
|
crap4ruby --threshold 30
|
|
35
|
+
crap4ruby --verbose
|
|
33
36
|
crap4ruby app/models/user.rb
|
|
34
37
|
crap4ruby app/models lib/billing
|
|
35
38
|
```
|
|
36
39
|
|
|
37
40
|
The first command reports complexity alone. The other commands require `coverage/.resultset.json` from your project's test run.
|
|
38
41
|
|
|
42
|
+
Default output shows methods with CRAP scores strictly above 30, plus methods with unknown scores.
|
|
43
|
+
An explicit `--threshold NUMBER` sets both the display limit and the enforced limit.
|
|
44
|
+
The default display limit does not enforce a threshold or change the exit status.
|
|
45
|
+
Use `--verbose` to show every analyzed method. Snapshots always contain every analyzed method.
|
|
46
|
+
With `--no-coverage`, every CRAP score is unknown, so every method remains visible.
|
|
47
|
+
|
|
39
48
|
To use Bundler, add `gem "crap4ruby", require: false` to your project's `Gemfile` and run `bundle install`.
|
|
40
49
|
Run the tool with `bundle exec crap4ruby`.
|
|
41
50
|
|
|
@@ -46,7 +55,7 @@ Run these commands from this checkout with Ruby 3.3 or newer:
|
|
|
46
55
|
```sh
|
|
47
56
|
bundle install
|
|
48
57
|
gem build crap4ruby.gemspec
|
|
49
|
-
gem install ./crap4ruby-0.2.
|
|
58
|
+
gem install ./crap4ruby-0.2.4.gem
|
|
50
59
|
```
|
|
51
60
|
|
|
52
61
|
To use Bundler in the measured project, add this checkout to that project's `Gemfile`:
|
|
@@ -97,8 +106,9 @@ crap4ruby does not configure SimpleCov, delete reports, install dependencies, or
|
|
|
97
106
|
| `--coverage-command COMMAND` | Run a shell command that refreshes the selected report. |
|
|
98
107
|
| `--no-coverage` | Report complexity with unknown coverage and CRAP. |
|
|
99
108
|
| `--no-save` | Print results without creating or replacing `.metrics/crap.edn`. |
|
|
109
|
+
| `--verbose` | Show every analyzed method, including scores at or below the display limit. |
|
|
100
110
|
| `--jobs N` | Set a positive worker count; `1` forces serial analysis. The default selects workers automatically. |
|
|
101
|
-
| `--threshold NUMBER` |
|
|
111
|
+
| `--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
112
|
| `-h`, `--help` | Print usage. |
|
|
103
113
|
| `-v`, `--version` | Print the gem version. |
|
|
104
114
|
|
|
@@ -171,7 +181,7 @@ Reports are accepted as supplied; generate fresh coverage after changing source
|
|
|
171
181
|
## Snapshot
|
|
172
182
|
|
|
173
183
|
The table lists the highest scores first, followed by entries with unknown scores.
|
|
174
|
-
The atomically replaced `.metrics/crap.edn` contains the same
|
|
184
|
+
The atomically replaced `.metrics/crap.edn` contains every analyzed method in the same order, with coverage expressed as a percentage:
|
|
175
185
|
|
|
176
186
|
```clojure
|
|
177
187
|
{:entries [
|
|
@@ -184,7 +194,8 @@ Instance method names are `charge`; singleton method names are `self.charge`.
|
|
|
184
194
|
`--no-coverage` writes `nil` for both `:coverage` and `:crap`.
|
|
185
195
|
|
|
186
196
|
The shape matches crapper's snapshot. This gem does not add Ruby support to crapper or its consumers.
|
|
187
|
-
A
|
|
197
|
+
A run restricted by source paths or `--changed` writes only its selected methods. Display filtering leaves the snapshot complete.
|
|
198
|
+
Reopened classes and repeated definitions can produce repeated namespace/name pairs.
|
|
188
199
|
|
|
189
200
|
## Limits
|
|
190
201
|
|
|
@@ -205,8 +216,9 @@ bundle exec rake
|
|
|
205
216
|
bundle exec ruby -Ilib exe/crap4ruby --help
|
|
206
217
|
```
|
|
207
218
|
|
|
208
|
-
The default task runs
|
|
209
|
-
|
|
219
|
+
The default task runs RuboCop, Steep, tests with SimpleCov, the CRAP limit, YARD validation, and dependency audits.
|
|
220
|
+
It requires 100% typed calls and fails if any library method's CRAP score exceeds 10.
|
|
221
|
+
`bundle exec rake crap` runs the tests and CRAP check. `bundle exec rake test` runs only the tests and coverage collection.
|
|
210
222
|
Each Rake test run discards the previous resultset so stale coverage cannot improve the score.
|
|
211
223
|
Reports are written to `coverage/index.html`, `coverage/.resultset.json`, and `.metrics/crap.edn`.
|
|
212
224
|
|
data/lib/crap4ruby/analyzer.rb
CHANGED
|
@@ -35,7 +35,7 @@ module Crap4Ruby
|
|
|
35
35
|
# @example Analyze a method without loading it
|
|
36
36
|
# Analyzer.new.call("def eligible?(age) = age >= 18", path: "person.rb")
|
|
37
37
|
def call(source, path:)
|
|
38
|
-
result = Prism.parse(source)
|
|
38
|
+
result = Prism.parse(source, version: "latest")
|
|
39
39
|
unless result.success?
|
|
40
40
|
error = result.errors.first
|
|
41
41
|
raise Error, "#{path}:#{error.location.start_line}: #{error.message}"
|
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
|