moult 0.1.0
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 +7 -0
- data/CHANGELOG.md +44 -0
- data/LICENSE.txt +201 -0
- data/NOTICE +4 -0
- data/README.md +331 -0
- data/exe/moult +6 -0
- data/lib/moult/abc.rb +133 -0
- data/lib/moult/boundaries/packwerk.rb +114 -0
- data/lib/moult/boundaries/severity.rb +87 -0
- data/lib/moult/boundaries.rb +77 -0
- data/lib/moult/boundaries_report.rb +106 -0
- data/lib/moult/churn.rb +52 -0
- data/lib/moult/cli/boundaries_command.rb +83 -0
- data/lib/moult/cli/coverage_command.rb +101 -0
- data/lib/moult/cli/dead_code_command.rb +112 -0
- data/lib/moult/cli/duplication_command.rb +92 -0
- data/lib/moult/cli/flags_command.rb +95 -0
- data/lib/moult/cli/gate_command.rb +113 -0
- data/lib/moult/cli/health_command.rb +117 -0
- data/lib/moult/cli/hotspots_command.rb +104 -0
- data/lib/moult/cli.rb +102 -0
- data/lib/moult/clones.rb +91 -0
- data/lib/moult/cloud_upload.rb +29 -0
- data/lib/moult/confidence/rules.rb +128 -0
- data/lib/moult/confidence.rb +106 -0
- data/lib/moult/coverage/resolver.rb +56 -0
- data/lib/moult/coverage.rb +176 -0
- data/lib/moult/coverage_report.rb +98 -0
- data/lib/moult/dead_code.rb +119 -0
- data/lib/moult/dead_code_report.rb +65 -0
- data/lib/moult/diff.rb +177 -0
- data/lib/moult/discovery.rb +38 -0
- data/lib/moult/duplication/confidence.rb +92 -0
- data/lib/moult/duplication.rb +112 -0
- data/lib/moult/duplication_report.rb +89 -0
- data/lib/moult/flag_scanner.rb +150 -0
- data/lib/moult/flags/classification.rb +79 -0
- data/lib/moult/flags/snapshot.rb +162 -0
- data/lib/moult/flags/staleness.rb +145 -0
- data/lib/moult/flags.rb +131 -0
- data/lib/moult/flags_report.rb +136 -0
- data/lib/moult/formatters/boundaries_json.rb +20 -0
- data/lib/moult/formatters/boundaries_table.rb +53 -0
- data/lib/moult/formatters/coverage_json.rb +19 -0
- data/lib/moult/formatters/coverage_table.rb +60 -0
- data/lib/moult/formatters/dead_code_json.rb +20 -0
- data/lib/moult/formatters/dead_code_table.rb +66 -0
- data/lib/moult/formatters/duplication_json.rb +20 -0
- data/lib/moult/formatters/duplication_table.rb +55 -0
- data/lib/moult/formatters/flags_json.rb +20 -0
- data/lib/moult/formatters/flags_table.rb +76 -0
- data/lib/moult/formatters/gate_github.rb +52 -0
- data/lib/moult/formatters/gate_json.rb +20 -0
- data/lib/moult/formatters/gate_message.rb +19 -0
- data/lib/moult/formatters/gate_sarif.rb +78 -0
- data/lib/moult/formatters/gate_table.rb +71 -0
- data/lib/moult/formatters/health_json.rb +20 -0
- data/lib/moult/formatters/health_table.rb +80 -0
- data/lib/moult/formatters/json.rb +23 -0
- data/lib/moult/formatters/table.rb +70 -0
- data/lib/moult/formatters/text_table.rb +39 -0
- data/lib/moult/gate/config.rb +55 -0
- data/lib/moult/gate/evaluation.rb +172 -0
- data/lib/moult/gate/policy.rb +103 -0
- data/lib/moult/gate.rb +199 -0
- data/lib/moult/gate_report.rb +97 -0
- data/lib/moult/git.rb +83 -0
- data/lib/moult/health/score.rb +291 -0
- data/lib/moult/health.rb +320 -0
- data/lib/moult/health_report.rb +97 -0
- data/lib/moult/index.rb +228 -0
- data/lib/moult/parser.rb +101 -0
- data/lib/moult/rails_conventions.rb +124 -0
- data/lib/moult/report.rb +114 -0
- data/lib/moult/scoring.rb +82 -0
- data/lib/moult/span.rb +17 -0
- data/lib/moult/symbol_id.rb +30 -0
- data/lib/moult/symbol_scanner.rb +100 -0
- data/lib/moult/version.rb +5 -0
- data/lib/moult.rb +84 -0
- data/schema/boundaries.schema.json +125 -0
- data/schema/common.schema.json +76 -0
- data/schema/coverage.schema.json +83 -0
- data/schema/deadcode.schema.json +106 -0
- data/schema/duplication.schema.json +128 -0
- data/schema/flags.schema.json +157 -0
- data/schema/gate.schema.json +165 -0
- data/schema/health.schema.json +157 -0
- data/schema/hotspots.schema.json +106 -0
- metadata +185 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 26e4c98c7cb6b20201d221d79e1fd186ca2a263b927bdd920c20e79cc93f1d25
|
|
4
|
+
data.tar.gz: 8a8be94ede4c3f6e76b2e70cdcefc054756d58567d84af93e6d27906206f4d5a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e58d63bcc230e5cbd39cc6a61a4f5addc0e979ef0f3f314b014e9376d2adf55b8027762ca04eb14b7e184af5f82e328c803188166062ddc80a46965f4a61defe
|
|
7
|
+
data.tar.gz: 53c7e7b6c1f0055133cd5f135acc6accdc073fcbd7c28e2c2f1b7064eaacfac64b1dcc8a44b547121c3f2b3db5981aa7e7d312c863c0c7cb57348520d93cea7d
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to Moult are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and Moult aims to
|
|
5
|
+
follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
> **Pre-1.0 notice.** Moult is `0.x`: the CLI, the typed JSON contracts, and
|
|
8
|
+
> the confidence model may still change between minor versions. Pin a version
|
|
9
|
+
> if you depend on the output shape. (Moult also depends on `rubydex ~> 0.2`,
|
|
10
|
+
> itself pre-1.0.)
|
|
11
|
+
|
|
12
|
+
## [Unreleased]
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- `Moult::CloudUpload.projection` — the sanitised payload builder for the
|
|
16
|
+
`moult-action` → Moult Cloud upload (allow-lists top-level keys; normalises
|
|
17
|
+
the absolute `analysis.root` path; the gate report is already source-free).
|
|
18
|
+
- `action.yml` — the `moult-action` composite GitHub Action: runs the gate in
|
|
19
|
+
CI and uploads the projected result with keyless GitHub OIDC auth.
|
|
20
|
+
- Open-source release setup: Apache-2.0 license, Trusted Publishing release
|
|
21
|
+
workflow, `SECURITY.md`, `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md`.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
- License changed from MIT to **Apache-2.0** (adds an explicit patent grant;
|
|
25
|
+
the chosen open-core core license).
|
|
26
|
+
|
|
27
|
+
## [0.1.0] - unreleased
|
|
28
|
+
|
|
29
|
+
Initial development version. The static + runtime analysis suite:
|
|
30
|
+
|
|
31
|
+
- `moult hotspots` — complexity (ABC) × git churn ranking.
|
|
32
|
+
- `moult deadcode` — confidence-graded unused-method/constant candidates over a
|
|
33
|
+
rubydex definition graph, with Rails entrypoint awareness; `--coverage` merges
|
|
34
|
+
runtime evidence.
|
|
35
|
+
- `moult coverage` — per-symbol hot/cold/untracked map from a coverage file.
|
|
36
|
+
- `moult duplication` — flay-backed structural-clone groups.
|
|
37
|
+
- `moult boundaries` — packwerk architecture-boundary violations.
|
|
38
|
+
- `moult flags` — OpenFeature feature-flag usage; `--provider` adds local
|
|
39
|
+
staleness candidates.
|
|
40
|
+
- `moult health` — composite, confidence-graded health score.
|
|
41
|
+
- `moult gate` — diff-aware PR risk gate (the only verdict layer).
|
|
42
|
+
|
|
43
|
+
[Unreleased]: https://github.com/moult-rb/moult-rb/compare/v0.1.0...HEAD
|
|
44
|
+
[0.1.0]: https://github.com/moult-rb/moult-rb/releases/tag/v0.1.0
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 The Moult authors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
data/NOTICE
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
# Moult
|
|
2
|
+
|
|
3
|
+
Codebase intelligence for Ruby and Rails. Moult sheds dead code.
|
|
4
|
+
|
|
5
|
+
## moult-action (GitHub Action)
|
|
6
|
+
|
|
7
|
+
Add the gate to your CI and upload results to Moult Cloud:
|
|
8
|
+
|
|
9
|
+
```yaml
|
|
10
|
+
- uses: moult-rb/moult-rb@v1
|
|
11
|
+
with:
|
|
12
|
+
base-sha: ${{ github.event.pull_request.base.sha }}
|
|
13
|
+
moult-cloud-url: https://app.moult.dev
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Your workflow needs `permissions: id-token: write` for OIDC authentication.
|
|
17
|
+
|
|
18
|
+
Three commands today:
|
|
19
|
+
|
|
20
|
+
- **`moult hotspots`** ranks files by a **complexity × churn** score —
|
|
21
|
+
the code that is both hard to understand *and* changed often.
|
|
22
|
+
- **`moult deadcode`** lists **confidence-graded dead-code candidates** —
|
|
23
|
+
unused methods and constants, over a real definition/reference graph, with
|
|
24
|
+
Rails entrypoint awareness so framework-invoked code isn't a false positive.
|
|
25
|
+
Feed it a coverage file with `--coverage` and runtime evidence is merged into
|
|
26
|
+
every finding's confidence (see [Runtime coverage](#runtime-coverage)).
|
|
27
|
+
- **`moult coverage`** resolves a coverage file to a per-symbol
|
|
28
|
+
**hot / cold / untracked** map.
|
|
29
|
+
|
|
30
|
+
Parsing is [Prism](https://github.com/ruby/prism); the definition/reference
|
|
31
|
+
index behind `deadcode` is [rubydex](https://github.com/Shopify/rubydex).
|
|
32
|
+
|
|
33
|
+
> Every finding Moult produces is a confidence-graded signal, never a claim of
|
|
34
|
+
> fact. In Ruby, dead code can almost never be *proven* statically
|
|
35
|
+
> (metaprogramming, `send`, `method_missing`, Zeitwerk, dynamic dispatch), so
|
|
36
|
+
> Moult never asserts that code is certainly dead — it attaches a confidence and
|
|
37
|
+
> the reasons behind it. Runtime coverage is the missing signal: it raises
|
|
38
|
+
> confidence on code that never ran and **rescues** candidates that did. Later
|
|
39
|
+
> phases add duplication analysis behind the same typed JSON contract.
|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
Add to your Gemfile:
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
gem "moult"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or install directly:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
gem install moult
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Requires Ruby 3.3+.
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
moult hotspots [PATH] [options]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`PATH` defaults to the current directory. Inside a git repository Moult
|
|
64
|
+
analyses the files git tracks (respecting `.gitignore`); elsewhere it globs for
|
|
65
|
+
`*.rb`, skipping `vendor/`, `tmp/`, and `node_modules/`.
|
|
66
|
+
|
|
67
|
+
### Example
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
$ moult hotspots
|
|
71
|
+
|
|
72
|
+
Hotspots (complexity x churn): 3 files — churn over last 12 months
|
|
73
|
+
|
|
74
|
+
# SCORE COMPLEXITY CHURN FILE WORST METHOD
|
|
75
|
+
1 95.2 15.9 6 app/services/charge.rb Charge#call (15.9)
|
|
76
|
+
2 59.6 19.9 3 app/models/user.rb User#eligible? (15.9)
|
|
77
|
+
3 3.0 3.0 1 lib/util.rb Util.blank? (3.0)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`app/models/user.rb` is the most *complex* file, but `app/services/charge.rb`
|
|
81
|
+
tops the list because it changes twice as often — complexity alone would have
|
|
82
|
+
missed it.
|
|
83
|
+
|
|
84
|
+
### JSON
|
|
85
|
+
|
|
86
|
+
`--format json` emits the typed contract (see
|
|
87
|
+
[`schema/hotspots.schema.json`](schema/hotspots.schema.json)), suitable for CI
|
|
88
|
+
and tooling:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
moult hotspots --format json
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"schema_version": 1,
|
|
97
|
+
"tool": { "name": "moult", "version": "0.1.0" },
|
|
98
|
+
"analysis": {
|
|
99
|
+
"root": "/path/to/project",
|
|
100
|
+
"git_ref": "c6e23f6f5d1003ea3cbc874aea5f1c55bf80a740",
|
|
101
|
+
"generated_at": "2026-06-29T06:03:22Z",
|
|
102
|
+
"churn": { "window": "last 12 months", "since": null }
|
|
103
|
+
},
|
|
104
|
+
"hotspots": [
|
|
105
|
+
{
|
|
106
|
+
"path": "app/services/charge.rb",
|
|
107
|
+
"score": 95.22,
|
|
108
|
+
"complexity": 15.87,
|
|
109
|
+
"churn": 6,
|
|
110
|
+
"confidence": null,
|
|
111
|
+
"category": null,
|
|
112
|
+
"methods": [
|
|
113
|
+
{
|
|
114
|
+
"symbol_id": "app/services/charge.rb:2:Charge#call",
|
|
115
|
+
"name": "Charge#call",
|
|
116
|
+
"span": { "start_line": 2, "start_column": 2, "end_line": 15, "end_column": 5 },
|
|
117
|
+
"abc": 15.87,
|
|
118
|
+
"confidence": null,
|
|
119
|
+
"category": null
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`confidence` and `category` are reserved for later phases and are always `null`
|
|
128
|
+
today — Moult never asserts that code is dead.
|
|
129
|
+
|
|
130
|
+
### Options
|
|
131
|
+
|
|
132
|
+
| Flag | Default | Description |
|
|
133
|
+
|------|---------|-------------|
|
|
134
|
+
| `--format table\|json` | `table` | Output format. |
|
|
135
|
+
| `--limit N` | `20` | Show the top N hotspots. `0` shows all. |
|
|
136
|
+
| `--since DATE` | `12 months ago` | Churn window start; any value `git log --since` accepts (e.g. `2025-01-01`). |
|
|
137
|
+
| `--quiet` | off | Suppress informational notes on stderr. |
|
|
138
|
+
|
|
139
|
+
Moult is report-only: it exits `0` on success and non-zero only on error. There
|
|
140
|
+
are no failing thresholds.
|
|
141
|
+
|
|
142
|
+
## Dead code
|
|
143
|
+
|
|
144
|
+
```sh
|
|
145
|
+
moult deadcode [PATH] [options]
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Lists methods and constants with no resolvable reference, each as a
|
|
149
|
+
**confidence-graded candidate** — never an assertion that the code is dead. The
|
|
150
|
+
definition/reference graph comes from [rubydex](https://github.com/Shopify/rubydex)
|
|
151
|
+
(the engine behind ruby-lsp); the confidence and its reasons come from Moult.
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
$ moult deadcode
|
|
155
|
+
|
|
156
|
+
Dead-code candidates (confidence-graded — not certainties): 3 findings
|
|
157
|
+
|
|
158
|
+
CONF KIND SYMBOL LOCATION TOP REASON
|
|
159
|
+
0.85 method Report#legacy_to_h lib/report.rb:42 private method with no caller in the codebase
|
|
160
|
+
0.30 method Api#export lib/api.rb:8 public method may be an external API entrypoint
|
|
161
|
+
0.00 method UsersController#index app/controllers/users_controller.rb:5 Rails framework entrypoint: public action in app/controllers/users_controller.rb
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
A private method with no caller scores high; a public method (a likely API
|
|
165
|
+
surface) scores lower; a routed controller action sinks to the bottom — but
|
|
166
|
+
**still appears**. Moult lowers confidence for framework conventions and
|
|
167
|
+
metaprogramming, it never silently hides a candidate.
|
|
168
|
+
|
|
169
|
+
### How confidence is computed
|
|
170
|
+
|
|
171
|
+
Each finding starts from a base score (by kind and visibility) and is adjusted
|
|
172
|
+
by a set of named rules, every one recorded as a `reason`:
|
|
173
|
+
|
|
174
|
+
- **Raises** confidence: a private method with no caller; a `@deprecated` mark.
|
|
175
|
+
- **Lowers** confidence: a public method (API surface); references only from
|
|
176
|
+
tests; a constructor (`initialize`, invoked implicitly by `.new`); a method
|
|
177
|
+
that **overrides or implements an ancestor's method** (reachable via that
|
|
178
|
+
interface — polymorphic dispatch); a file that uses
|
|
179
|
+
`send`/`define_method`/`method_missing`/`const_get`/`eval`.
|
|
180
|
+
- **Lowers strongly**: a Rails entrypoint — controller/mailer actions, helpers,
|
|
181
|
+
job `#perform`, `before_action :symbol`-style callbacks, serializers,
|
|
182
|
+
initializers. Rails awareness is on automatically when a Rails app is detected
|
|
183
|
+
(`--no-rails` to disable).
|
|
184
|
+
|
|
185
|
+
### Dead-code JSON
|
|
186
|
+
|
|
187
|
+
`--format json` emits the typed contract (see
|
|
188
|
+
[`schema/deadcode.schema.json`](schema/deadcode.schema.json)):
|
|
189
|
+
|
|
190
|
+
```json
|
|
191
|
+
{
|
|
192
|
+
"schema_version": 2,
|
|
193
|
+
"tool": { "name": "moult", "version": "0.1.0" },
|
|
194
|
+
"analysis": {
|
|
195
|
+
"root": "/path/to/project",
|
|
196
|
+
"git_ref": "c6e23f6f…",
|
|
197
|
+
"generated_at": "2026-06-29T06:03:22Z",
|
|
198
|
+
"coverage": null,
|
|
199
|
+
"index": { "backend": "rubydex", "backend_version": "0.2.6", "resolved": true, "rails": true, "diagnostics": [] }
|
|
200
|
+
},
|
|
201
|
+
"findings": [
|
|
202
|
+
{
|
|
203
|
+
"symbol_id": "lib/report.rb:42:Report#legacy_to_h",
|
|
204
|
+
"kind": "method",
|
|
205
|
+
"name": "Report#legacy_to_h",
|
|
206
|
+
"span": { "start_line": 42, "start_column": 2, "end_line": 50, "end_column": 5 },
|
|
207
|
+
"confidence": 0.85,
|
|
208
|
+
"category": "dead_code",
|
|
209
|
+
"runtime": null,
|
|
210
|
+
"reasons": [
|
|
211
|
+
{ "rule": "base_score", "delta": 0.75, "detail": "base for method/private" },
|
|
212
|
+
{ "rule": "private_unused", "delta": 0.1, "detail": "private method with no caller in the codebase" }
|
|
213
|
+
]
|
|
214
|
+
}
|
|
215
|
+
]
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
`analysis.coverage` and each finding's `runtime` are `null` until you pass
|
|
220
|
+
`--coverage` (see below). The `symbol_id` is the same `"<path>:<line>:<name>"`
|
|
221
|
+
join key the hotspots contract uses, so the analyses — and the coverage merge —
|
|
222
|
+
line up.
|
|
223
|
+
|
|
224
|
+
### Options
|
|
225
|
+
|
|
226
|
+
| Flag | Default | Description |
|
|
227
|
+
|------|---------|-------------|
|
|
228
|
+
| `--format table\|json` | `table` | Output format. |
|
|
229
|
+
| `--min-confidence N` | `0.0` | Hide findings below this confidence (`0`–`1`). |
|
|
230
|
+
| `--[no-]rails` | on | Apply Rails entrypoint awareness. |
|
|
231
|
+
| `--coverage PATH` | off | Merge a local coverage file as runtime evidence. |
|
|
232
|
+
| `--coverage-format FMT` | `auto` | `auto`, `simplecov`, or `coverage`. |
|
|
233
|
+
| `--quiet` | off | Suppress informational notes on stderr. |
|
|
234
|
+
|
|
235
|
+
Currently in scope: unused **methods** and non-class **constants**. Classes and
|
|
236
|
+
modules are not flagged (this sidesteps Zeitwerk/STI false positives). Route-file
|
|
237
|
+
and view-template resolution are deferred to a later slice.
|
|
238
|
+
|
|
239
|
+
## Runtime coverage
|
|
240
|
+
|
|
241
|
+
Static analysis can never *prove* Ruby dead code — `send`, `method_missing`,
|
|
242
|
+
metaprogramming and Zeitwerk all defeat it. Production coverage is the missing
|
|
243
|
+
signal, and Moult merges it **both ways**:
|
|
244
|
+
|
|
245
|
+
- a candidate whose body **never ran** (runtime-cold) gets its confidence
|
|
246
|
+
*raised* — corroboration that it really is dead;
|
|
247
|
+
- a candidate that **did run** (runtime-hot) is *rescued* — its confidence is
|
|
248
|
+
capped low, because it's the false positive static analysis missed.
|
|
249
|
+
|
|
250
|
+
Point `--coverage` at a local coverage file — either SimpleCov's
|
|
251
|
+
`coverage/.resultset.json` or a JSON dump of stdlib
|
|
252
|
+
[`Coverage.result`](https://docs.ruby-lang.org/en/master/Coverage.html). The
|
|
253
|
+
format is auto-detected.
|
|
254
|
+
|
|
255
|
+
```sh
|
|
256
|
+
moult deadcode --coverage coverage/.resultset.json
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
Dead-code candidates (confidence-graded — not certainties): 3 findings
|
|
261
|
+
|
|
262
|
+
CONF KIND RUNTIME SYMBOL LOCATION TOP REASON
|
|
263
|
+
0.95 method cold Report#legacy_to_h lib/report.rb:42 never executed in the supplied coverage run (runtime-cold corroborates)
|
|
264
|
+
0.10 method hot Api#dispatch lib/api.rb:8 executed at runtime (coverage) despite no static reference; rescued
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
To produce a stdlib dump without SimpleCov, capture coverage around your test run
|
|
268
|
+
and write the result:
|
|
269
|
+
|
|
270
|
+
```ruby
|
|
271
|
+
require "coverage"
|
|
272
|
+
Coverage.start(lines: true)
|
|
273
|
+
# ...load and exercise your app / run your tests...
|
|
274
|
+
File.write("coverage.json", JSON.generate(Coverage.result))
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
Coverage is keyed by line; Moult resolves it to each symbol's definition span,
|
|
278
|
+
counting only the **method body** (the `def` line is counted at load time, not
|
|
279
|
+
per call, so it's excluded). A symbol is **hot** if any executable body line ran,
|
|
280
|
+
**cold** if the file is tracked but none did, and **untracked** when there's no
|
|
281
|
+
signal (the file isn't in the dataset, or it's a constant). Coverage is evidence,
|
|
282
|
+
never proof — runtime-cold raises confidence, it never asserts certain death.
|
|
283
|
+
|
|
284
|
+
### Coverage map
|
|
285
|
+
|
|
286
|
+
`moult coverage` is the standalone view of the same classification — a typed
|
|
287
|
+
hot/cold/untracked map over every definition (see
|
|
288
|
+
[`schema/coverage.schema.json`](schema/coverage.schema.json)):
|
|
289
|
+
|
|
290
|
+
```sh
|
|
291
|
+
moult coverage --coverage coverage/.resultset.json # table
|
|
292
|
+
moult coverage --coverage coverage/.resultset.json --format json
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
```
|
|
296
|
+
Runtime coverage map: 128 hot, 14 cold, 9 untracked
|
|
297
|
+
|
|
298
|
+
RUNTIME KIND SYMBOL LOCATION
|
|
299
|
+
hot method Charge#call app/services/charge.rb:2
|
|
300
|
+
cold method Report#legacy_to_h lib/report.rb:42
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## How the score works
|
|
304
|
+
|
|
305
|
+
- **Complexity** — a flog-style weighted ABC score per method: assignments,
|
|
306
|
+
branches (every method call, including operators), and conditions, with
|
|
307
|
+
metaprogramming calls penalised and a compounding penalty for nesting depth.
|
|
308
|
+
A file's complexity is the sum of its methods'.
|
|
309
|
+
- **Churn** — the number of commits that touched the file within the window
|
|
310
|
+
(default: the last 12 months). Renames are not followed.
|
|
311
|
+
- **Score** — `complexity × churn`, ranked descending.
|
|
312
|
+
|
|
313
|
+
Outside a git repository churn is `0`, so files rank by complexity alone.
|
|
314
|
+
|
|
315
|
+
## Open source & Moult Cloud
|
|
316
|
+
|
|
317
|
+
The `moult` gem — the CLI and every analysis in it — is free and open source
|
|
318
|
+
under [Apache-2.0](LICENSE.txt). **Moult Cloud** is a separate commercial
|
|
319
|
+
product: a hosted GitHub App that turns `moult gate` into an enforced,
|
|
320
|
+
team-visible PR check with history, trends, and dashboards. The gem stands on
|
|
321
|
+
its own; the cloud is optional.
|
|
322
|
+
|
|
323
|
+
## Contributing
|
|
324
|
+
|
|
325
|
+
Contributions welcome — see [CONTRIBUTING](CONTRIBUTING.md), our
|
|
326
|
+
[Code of Conduct](CODE_OF_CONDUCT.md), and [SECURITY](SECURITY.md) for reporting
|
|
327
|
+
vulnerabilities. Changes are tracked in [CHANGELOG.md](CHANGELOG.md).
|
|
328
|
+
|
|
329
|
+
## License
|
|
330
|
+
|
|
331
|
+
[Apache-2.0](LICENSE.txt). © 2026 The Moult authors. See [NOTICE](NOTICE).
|