backburn 0.1.0-aarch64-linux

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ad2e4597cd998793f4b0a9903901754c403cceaff332a56fb1762e4901dc89b9
4
+ data.tar.gz: d0130013752c37482609a060674c5affcb66c369e42ef67e73e74f9281ee0cdd
5
+ SHA512:
6
+ metadata.gz: b8a7568be0620eec8a0a7c2dbe3993af7e84e656399fe73c4d79b9b8f31baff36e29629ce3a872ce53bd285f76233a7288c3277c04be4a5fbab4ed5db46a76ce
7
+ data.tar.gz: 0f3fb1d9151025029f6fc611107cb6d19c53651ce9b9a0b03f5e9adecc6fae5ebb66a69904256f933f30541f92fbec8e94417f94ef1dda2d78ae08077218e8e3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sophie Déziel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,520 @@
1
+ # Backburn
2
+
3
+ Backburn finds Ruby code that no production path can reach. It parses your codebase with [Prism](https://github.com/ruby/prism), builds a name-resolved reference graph, marks everything reachable from your entry points ("roots": controller actions, jobs, migrations, and so on), and reports whatever stays unmarked. Because it walks reachability instead of counting references, it also catches **dead chains** (code called only by other dead code, at any depth) and **dead cycles** (methods that only call each other), which reference counters miss. Tests are read but never keep code alive; code that only tests use is tagged `[tests]`.
4
+
5
+ The algorithm is Trémaux's maze rule: walk every passage from the entrance and chalk it, and whatever stays unchalked is never visited. The name comes from firefighting. A backburn clears dead fuel in small, controlled strips, and Backburn's removal batches let you delete dead code one safe commit at a time.
6
+
7
+ Backburn only reports. It never deletes or edits your code.
8
+
9
+ ## Quick start
10
+
11
+ ```sh
12
+ gem install backburn
13
+ ```
14
+
15
+ On Linux (x86_64 or aarch64, glibc or musl) and macOS (Apple silicon or Intel), RubyGems installs a gem with a precompiled binary, so no compiler is needed. Anywhere else, it installs the source gem, which compiles Backburn during the install and only needs a C compiler and `make`. To build from a checkout instead, see [Building from source](#building-from-source).
16
+
17
+ In the root of a Rails app:
18
+
19
+ ```sh
20
+ backburn init # picks presets from Gemfile.lock (and Gemfile, for thor)
21
+ backburn # same as `backburn scan`: what can no production path reach?
22
+ backburn batches # in what independent pieces can I delete it?
23
+ backburn explain Order#legacy_total # why is this live, or why is it dead?
24
+ ```
25
+
26
+ `init` writes two files that you should commit:
27
+
28
+ - `.backburn.yml` lists the presets that match your app and points to your project roots file. `init` detects Rails, GraphQL-ruby, Sidekiq, Phlex, Pundit, Devise and fast-mcp from `Gemfile.lock`. It adds `thor` only when your `Gemfile` declares it, because almost every Rails app has Thor in its lockfile through Rails itself:
29
+
30
+ ```yaml
31
+ # backburn configuration. Command-line options win over this file.
32
+ presets: [rails, sidekiq, pundit]
33
+ roots: [.backburn.roots] # project-specific patterns, committed
34
+ inflect: true
35
+ # exclude: [db/migrate/**, script/**]
36
+ # tests: [spec/**]
37
+ # baseline: .backburn-baseline.json
38
+ ```
39
+
40
+ - `.backburn.roots` is an empty roots file for your project's own entry points, with a comment header explaining the grammar.
41
+
42
+ `init` refuses to overwrite either file unless you pass `--force`. After `init`, the report header lists presets and roots files separately:
43
+
44
+ ```
45
+ backburn 0.1.0 · 10 files · 43 definitions · 1 ms · presets: rails, sidekiq · roots: .backburn.roots
46
+ ```
47
+
48
+ ### What it looks like
49
+
50
+ The examples below are real output from the fixture in this repo (`./backburn --roots rails.roots --color never test/fixture`):
51
+
52
+ ```
53
+ backburn 0.1.0 · 10 files · 43 definitions · 1 ms · roots: rails.roots
54
+ 14 dead · 11 unreferenced · 1 dead-chain · 2 dead-cycle · 1 used only by tests
55
+
56
+ Unreferenced (11)
57
+ app/controllers/orders_controller.rb:15 method OrdersController#unused_helper
58
+ app/helpers/orders_helper.rb:6 method OrdersHelper#unused_money
59
+ app/models/order.rb:3 constant Order::STATUSES
60
+ app/models/order.rb:13 method Order#legacy_total
61
+ app/models/order.rb:29 method Order#tested_only [tests]
62
+ app/models/order.rb:37 method Order#dynamic_target
63
+ lib/legacy_report.rb:1 class LegacyReport
64
+ lib/legacy_report.rb:2 method LegacyReport#run
65
+ lib/registry.rb:9 method Registry.handle_tsv
66
+ lib/visitor.rb:15 method Visitor#leftover
67
+ lib/workers/cleanup_worker.rb:14 method Trimmer#unused_trim
68
+
69
+ Dead chain: only dead code reaches it (1)
70
+ app/models/order.rb:17 method Order#old_rounding ← Order#legacy_total
71
+
72
+ Dead cycle: reached only from code that calls itself (2)
73
+ app/models/order.rb:21 method Order#ping ← Order#pong
74
+ app/models/order.rb:25 method Order#pong ← Order#ping
75
+ ```
76
+
77
+ `backburn batches` groups the same findings into pieces you can delete independently (output shortened):
78
+
79
+ ```
80
+ backburn 0.1.0 · 10 files · 43 definitions · 1 ms · roots: rails.roots
81
+ 11 removal batches · 29 lines in all · 10 have no test references
82
+
83
+ Batch 1 · 2 definitions · 6 lines · 1 file · no test references
84
+ app/models/order.rb:13-15 method Order#legacy_total
85
+ app/models/order.rb:17-19 method Order#old_rounding (reached only from this batch)
86
+
87
+ Batch 2 · 2 definitions · 6 lines · 1 file · no test references
88
+ app/models/order.rb:21-23 method Order#ping (reached only from this batch)
89
+ app/models/order.rb:25-27 method Order#pong (reached only from this batch)
90
+
91
+ Batch 3 · 2 definitions · 5 lines · 1 file · no test references
92
+ lib/legacy_report.rb:1-5 class LegacyReport
93
+ lib/legacy_report.rb:2-4 method LegacyReport#run
94
+ ...
95
+ Batch 11 · 1 definition · 3 lines · 1 file · tests: test/order_test.rb
96
+ app/models/order.rb:29-31 method Order#tested_only [tests]
97
+ ```
98
+
99
+ `backburn explain` answers the follow-up question. For live code it prints one path from a root:
100
+
101
+ ```
102
+ $ backburn explain Order#price_of --roots rails.roots test/fixture
103
+ Order#price_of is live (app/models/order.rb:36)
104
+ root OrdersController#show public < ActionController::Base (rails.roots:10)
105
+ calls Order#total app/controllers/orders_controller.rb:4
106
+ calls Order#price_of app/models/order.rb:10
107
+ ```
108
+
109
+ For dead code it prints the reason, the dead callers, and the batch it belongs to:
110
+
111
+ ```
112
+ $ backburn explain Order#old_rounding --roots rails.roots test/fixture
113
+ Order#old_rounding is dead: dead-chain (only dead code reaches it)
114
+ defined app/models/order.rb:17-19 public method
115
+ called by Order#legacy_total app/models/order.rb:14 (dead)
116
+ batch 1 2 definitions, 6 lines: Order#legacy_total, Order#old_rounding
117
+ ```
118
+
119
+ `explain` accepts `Order#total` (instance method), `Order.find` (class method), `Admin::Report` (class, module or constant), or `app/models/order.rb:17` (`file:line`). With `--format json` it prints one object, or an array when the name matches several definitions.
120
+
121
+ ## Commands
122
+
123
+ ```
124
+ backburn [COMMAND] [OPTIONS] [PATH]
125
+ ```
126
+
127
+ `PATH` is the project root and defaults to the current directory. With no command, Backburn runs `scan`.
128
+
129
+ | Command | Answers | Own options |
130
+ | --- | --- | --- |
131
+ | `scan` | What code can no production path reach? | `--only unreferenced,dead-chain,dead-cycle`, `--test-refs include\|exclude\|only`, `--write-baseline`, `--baseline FILE`, `--fail-on none\|any\|new` |
132
+ | `batches` | In what independent pieces can I delete it? | `--max-lines N`, `--untested` |
133
+ | `explain NAME` | Why is this live, or why is it dead? | `--all-paths` |
134
+ | `roots` | Which entry points matched, and which patterns matched nothing? | `--unused` |
135
+ | `gems` | Which Gemfile gems does the app still need? | `--gem-src DIR` |
136
+ | `init` | Write `.backburn.yml` and `.backburn.roots` for this project | `--force` |
137
+
138
+ Global options:
139
+
140
+ | Option | Effect |
141
+ | --- | --- |
142
+ | `--preset NAME` | built-in roots: `rails`, `graphql`, `sidekiq`, `phlex`, `pundit`, `devise`, `fast-mcp`, `thor`, `rails-framework` (repeatable) |
143
+ | `--roots FILE` | an extra roots file, read after presets (repeatable) |
144
+ | `--public-api` | every public, documented method, class and constant is a root |
145
+ | `--inflect` | `:line_items` also reaches `LineItem` and `LineItems` |
146
+ | `--exclude GLOB` | skip matching paths (repeatable; default `vendor/**`, `node_modules/**`, `tmp/**`, `log/**`, `coverage/**`) |
147
+ | `--tests GLOB` | what counts as a test file (repeatable, replaces the default) |
148
+ | `--format FMT` | `text`, `tsv`, `json`, `sarif` |
149
+ | `--output FILE` | write the report to a file |
150
+ | `--color WHEN` | `auto`, `always`, `never` |
151
+ | `--config FILE` | read another config (default `.backburn.yml`); `--no-config` ignores it |
152
+ | `-q`, `--quiet` | no header or summary line in text output |
153
+
154
+ Command-line options win over `.backburn.yml`, which wins over built-in defaults. All four formats carry the same facts. Every definition has a stable id such as `method:Order#legacy_total`, which survives line moves. See [docs/cli-and-outputs.md](docs/cli-and-outputs.md) for TSV columns, the JSON schema, SARIF details and the config file format.
155
+
156
+ ## What it reads
157
+
158
+ Backburn reads the following files under `PATH`:
159
+
160
+ - `*.rb`, `*.rake` and `Rakefile`.
161
+ - Extensionless scripts whose `#!` line mentions `ruby` or `rails`.
162
+ - Views:
163
+ - ERB (`*.erb`, and `*.tt` generator templates) is converted to Ruby with line numbers kept.
164
+ - HAML (`*.haml`) and Slim (`*.slim`) are converted line by line. That covers `-` and `=` code lines, attribute values and `#{}` interpolation, and skips comments.
165
+ - When a view template has Ruby that Backburn could only partly read, the text report ends with a dim note saying so.
166
+ - Old generator templates that are ERB inside a `.rb` file. These are retried as ERB and never count as tests.
167
+ - whenever's `runner "Foo.bar"` strings, which are read as Ruby.
168
+ - RSpec matchers `be_foo` and `have_foo`, which count as test references to `foo?` and `has_foo?`.
169
+
170
+ Test files (`test/`, `spec/`, `*_test.rb`, `*_spec.rb` by default) are read the same way, but they only tag candidates `[tests]`.
171
+
172
+ ## Roots
173
+
174
+ A **root** is an entry point, meaning code that something outside your Ruby source calls: the router calls controller actions, Sidekiq calls `perform`, Rails runs migrations. Everything a root reaches is live. Everything else is a candidate. Backburn has no framework knowledge in its C code. All of it lives in roots files.
175
+
176
+ The following are always roots, without any configuration: code that runs at load time, methods that call `super` (whoever calls the parent reaches them), operators, and Ruby's own hooks (`initialize`, `method_missing`, `to_s`, `call`, `each`, `included`, `inherited`, and so on).
177
+
178
+ ### Presets
179
+
180
+ Presets are roots files compiled into the binary (sources in `presets/`). Combine them freely:
181
+
182
+ ```sh
183
+ backburn --preset rails --preset sidekiq --preset graphql
184
+ ```
185
+
186
+ | Preset | Covers |
187
+ | --- | --- |
188
+ | `rails` | controllers, mailers, mailboxes (`< ActionMailbox::Base`), jobs, migrations, `config/`, `lib/tasks/` and `.rake` files (also nested, as in `engines/*/config/`), errors, Action Cable, protocols Rails calls on your objects (`to_partial_path`, `table_name_prefix`/`_suffix`, `as_json`, ...), `bin/`, `script/` |
189
+ | `graphql` | GraphQL-ruby schema classes, types, mutations, resolvers, dataloader sources |
190
+ | `sidekiq` | workers marked by `Sidekiq::Job`, `Sidekiq::Worker`, `Shoryuken::Worker` |
191
+ | `phlex` | Phlex and ViewComponent components |
192
+ | `pundit` | Pundit policies and scopes |
193
+ | `devise` | Devise controllers and the hooks Devise calls on yours (`after_sign_in_path_for`, `configure_permitted_parameters`, ...) |
194
+ | `fast-mcp` | MCP tools and resources, which fast-mcp registers through `descendants` instead of by name |
195
+ | `thor` | every public method of a `Thor` or `Thor::Group` subclass |
196
+ | `rails-framework` | the Rails repository itself (generators, Thor commands); use with `--public-api` |
197
+
198
+ `rails.roots` at the repo root is the spec's original all-in-one file (Rails plus Sidekiq, GraphQL, Phlex and Pundit) and stays frozen as a reference. Conventions evolve in `presets/`. On the test fixture, `--roots rails.roots` and `--preset rails --preset sidekiq --preset graphql --preset phlex --preset pundit` give the same result.
199
+
200
+ The `rails` preset deliberately does not root `< ActiveRecord::Base`. That would keep every model method alive and hide the dead ones Backburn exists to find.
201
+
202
+ ### Roots-file grammar
203
+
204
+ One pattern per line. Blank lines and lines starting with `#` are ignored. Patterns use shell globs (`fnmatch` without `FNM_PATHNAME`), so `*` also matches `::` and `/`.
205
+
206
+ | Line | Matches |
207
+ | --- | --- |
208
+ | `Pattern` | a qualified name: `Class#instance_method`, `Class.class_method`, `Namespace::Class` |
209
+ | `public Pattern` | the same, public methods only |
210
+ | `< Superclass` | every class or module that is a kind of `Superclass` (inherits from it or mixes it in), the class itself and everything in it |
211
+ | `public < Superclass` | the same, public methods only |
212
+ | `path:glob` | everything defined in files whose path (relative to the project root) matches |
213
+
214
+ Examples:
215
+
216
+ ```
217
+ public < ActionController::Base # every public action
218
+ *Job # classes named like jobs
219
+ < Sidekiq::Job # include Sidekiq::Job counts as "a kind of"
220
+ ApplicationHelper#javascript_inline_importmap_tag # a helper a gem calls for you
221
+ path:db/migrate/*
222
+ ```
223
+
224
+ Put your project's own entry points in `.backburn.roots` (listed under `roots:` in `.backburn.yml`). For example, `samples/rubygems.roots` holds the single extra pattern rubygems.org needs.
225
+
226
+ To tune roots, run `backburn roots`. It prints each rule with how many definitions it matched. A rule that matches thousands of definitions is too broad, and `backburn roots --unused` lists the ones that matched nothing (stale or irrelevant):
227
+
228
+ ```
229
+ $ backburn roots --roots rails.roots test/fixture
230
+ backburn 0.1.0 · 10 files · 43 definitions · 1 ms · roots: rails.roots
231
+ 66 rules · 61 matched nothing
232
+
233
+ 4 public < ActionController::Base rails.roots:10
234
+ 0 public < ActionController::API rails.roots:11 (matched nothing)
235
+ 2 public *Controller#* rails.roots:12
236
+ ...
237
+ ```
238
+
239
+ ### Gems and libraries: `--public-api`
240
+
241
+ For a gem, the entry points are its public API, not a framework's conventions. `--public-api` makes every public method, class, module and constant a root, unless its line carries `:nodoc:`. What remains is dead private and `:nodoc:` code. For the Rails repository itself, combine it with the `rails-framework` preset.
242
+
243
+ ### Associations: `--inflect`
244
+
245
+ `has_many :line_items` names a class only through a symbol. With `--inflect`, every plain symbol also references its camelized singular and plural constants (`:line_items` reaches `LineItems` and `LineItem`). This can only make more code live, never less. `init` turns it on.
246
+
247
+ ## Reading the report
248
+
249
+ Every candidate has exactly one reason:
250
+
251
+ | Reason | Meaning | What to do |
252
+ | --- | --- | --- |
253
+ | `unreferenced` | nothing anywhere names it | the simplest deletion |
254
+ | `dead-chain` | something calls it, but only dead code (the `←` names the dead callers) | delete it together with its callers |
255
+ | `dead-cycle` | reached only from a group that calls itself (`ping` calls `pong`, `pong` calls `ping`) | delete the whole group |
256
+
257
+ **`[tests]`** is a flag, not a reason. Tests name this code, but tests never keep code alive. Deleting it means deleting or updating those tests too. Use `scan --test-refs exclude` to hide such candidates, or `--test-refs only` to list just those.
258
+
259
+ **Dynamic dispatch that may hide callers.** When a call's target is computed (`send(name)`, `public_send(...)`, `constantize` on a variable), Backburn cannot follow it, so it lists the site. Check these before deleting anything nearby:
260
+
261
+ ```
262
+ Dynamic dispatch that may hide callers (2)
263
+ lib/dispatcher.rb:3 public_send(<computed>)
264
+ lib/dispatcher.rb:4 constantize(<computed>)
265
+ ```
266
+
267
+ Interpolated names with enough fixed text, such as `send("format_#{kind}")`, are matched as patterns (`format_*`) instead of being listed.
268
+
269
+ **Uncertain.** A fully computed `send(name)` on self (no receiver, or `self.`) may call any method of the class it is written in, so Backburn doesn't call those methods dead. It lists them, and any dead code only they reach, in their own section:
270
+
271
+ ```
272
+ Uncertain: a computed send may reach these (2)
273
+ lib/dispatcher.rb:6 method Dispatcher#start ← send(<computed>) lib/dispatcher.rb:3
274
+ lib/exporter.rb:6 method Exporter#csv ← public_send(<computed>) lib/exporter.rb:3
275
+ ```
276
+
277
+ `public_send`, `try` and `public_method` only reach public methods. A send in an instance method only reaches instance methods, and one in `def self.x` only reaches class methods. A send inside dead code makes nothing uncertain. Uncertain code is never a candidate: it stays out of batches, baselines and `--fail-on`. Before deleting one, check which names the send can receive; `backburn explain NAME` shows the path through the send.
278
+
279
+ **Batches.** `backburn batches` joins dead definitions connected by references or containment (a dead class and its methods, reopenings of the same class). No live code reaches a batch and no reference crosses between batches, so you can delete any one batch on its own and the rest stay valid. Batches are ordered untested first, then largest. Each batch is a natural size for one pull request. `--untested` shows only batches no test names, and `--max-lines N` caps their size.
280
+
281
+ ## Gems
282
+
283
+ `backburn gems` checks which gems in your Gemfile the app still uses. When there is a `Gemfile.lock`, it runs `bundle exec ruby -e …` once to find each gem's source and indexes that source with Prism. With `--gem-src DIR` it reads gem sources from `DIR`. Without either, it falls back to the app alone and guesses each gem's constants from its name, and the report header says so.
284
+
285
+ Each gem gets a verdict:
286
+
287
+ | Verdict | Evidence |
288
+ | --- | --- |
289
+ | `used` | the app requires it, names a constant the gem owns, calls a method the gem adds to a core class, names it in a config file (`database.yml`, `.rubocop.yml`, `Procfile`, ...), or has a `config/<gem>.rb` |
290
+ | `auto` | it ships a Railtie or Engine, so Rails loads it without any call from the app |
291
+ | `tool` | it ships executables (run from the shell or CI, not from Ruby) |
292
+ | `unused` | none of the above |
293
+
294
+ `needed by` lists the gems that depend on it according to `Gemfile.lock`, which tells you whether removing it from the Gemfile would actually remove it from the bundle.
295
+
296
+ Treat the verdicts as hints, not proof. The matching is by name, and a test-only or CLI gem may be used in ways Backburn cannot see. An excerpt from a real Rails app:
297
+
298
+ ```
299
+ backburn 0.1.0 gems · 37 declared · read the source of 36
300
+
301
+ unused (6)
302
+ tzinfo-data default
303
+ bindex default needed by web-console
304
+ mini_racer default
305
+ ...
306
+ tool (3)
307
+ debug development,test ships executables
308
+ rubocop development,test ships executables needed by rubocop-rails, rubocop-rspec
309
+ ...
310
+ auto (3)
311
+ sprockets-rails default railtie: loads itself into Rails
312
+ ...
313
+ used (25)
314
+ mysql2 default named in config/database.yml
315
+ puma default configured in config/puma.rb
316
+ redis default constant Redis; named in config/cable.yml needed by mock_redis
317
+ sidekiq default require sidekiq/web (config/routes.rb); constant Sidekiq; named in Procfile
318
+ ...
319
+ ```
320
+
321
+ ## CI
322
+
323
+ Backburn exits like a linter:
324
+
325
+ | Code | Meaning |
326
+ | --- | --- |
327
+ | `0` | ran; nothing to report under `--fail-on` |
328
+ | `1` | ran; found dead code that `--fail-on` counts |
329
+ | `2` | usage error: unknown option, unknown preset, unreadable config or roots file, unknown `explain` name |
330
+ | `3` | some Ruby files could not be parsed; the report still prints and lists them |
331
+
332
+ `--fail-on` decides what counts:
333
+
334
+ - `none`: always exit 0. This is the default when there is no baseline.
335
+ - `any`: any candidate fails.
336
+ - `new`: only candidates missing from the baseline fail. This is the default when a baseline exists.
337
+
338
+ **Baselines** let you adopt Backburn on an existing codebase. You accept today's dead code, and CI blocks only new dead code:
339
+
340
+ ```sh
341
+ backburn scan --write-baseline # writes .backburn-baseline.json (sorted ids, commit)
342
+ ```
343
+
344
+ Commit the file. Backburn picks up `.backburn-baseline.json` at the project root automatically whenever it exists. `baseline:` in `.backburn.yml` and `--baseline FILE` only change the path. With a baseline present, plain `backburn scan` exits 1 on new dead code and marks it `new` in the text report:
345
+
346
+ ```
347
+ lib/fresh.rb:1 class Fresh new
348
+ lib/fresh.rb:2 method Fresh#nobody new
349
+ ```
350
+
351
+ When baseline entries are no longer dead, `scan` prints a hint to rerun `--write-baseline` and shrink the file. The baseline stores ids, not line numbers, so moving code does not change it.
352
+
353
+ GitHub Actions, with dead code shown as annotations on pull requests:
354
+
355
+ ```yaml
356
+ - run: gem install backburn
357
+ - run: backburn scan --format sarif --output backburn.sarif --fail-on new
358
+ - uses: github/codeql-action/upload-sarif@v3
359
+ if: always()
360
+ with:
361
+ sarif_file: backburn.sarif
362
+ ```
363
+
364
+ The SARIF output defines one rule per reason (`backburn/unreferenced`, `backburn/dead-chain`, `backburn/dead-cycle`) at level `note`, with the stable id as a fingerprint. GitHub uses the fingerprint to track a finding across commits.
365
+
366
+ ## Limits
367
+
368
+ Backburn resolves every call by name and errs on the side of keeping code alive. Its findings are precise, but it misses some dead code. Know these limits before you delete anything:
369
+
370
+ - **Name-based matching.** A call `x.content` reaches every method named `content` in the codebase. One live `content` call keeps every `content` alive, so chains stop at the first common name. Generated methods (associations, scopes, `enum`, `define_method`) have no `def`, but their names still keep same-named hand-written methods alive.
371
+ - **Metaprogramming it can't follow.** Fully computed `send`/`public_send`/`constantize`, code assembled in strings outside `class_eval`, and methods another gem calls by convention without `super` all look dead. The first kind is listed under dynamic dispatch; when it is a send on self, the methods it may reach are listed as uncertain instead of dead. A send on another object, or one that reaches a superclass, subclass or mixin, still leaves its targets looking dead. The other kinds need a roots pattern.
372
+ - **"Not wired yet" looks like dead.** Code merged yesterday for a feature that isn't connected yet is indistinguishable from abandoned code. Check `git log` before deleting.
373
+ - **Broad roots hide dead code.** A rule like `< Avo::*` or `path:config/*` makes everything it matches live.
374
+ - **No type inference, no runtime tracing.** Cross-check with production coverage (Coverband, `Coverage.setup(oneshot_lines: true)`) before large deletions.
375
+
376
+ It never deletes anything. See [Known limits and next steps](docs/technical-spec.md#known-limits-and-next-steps) in the technical spec for the full table.
377
+
378
+ ## Field notes
379
+
380
+ Backburn was run on 69 Ruby repositories (4,642 files, about 12,000 definitions). The first pass reported 238 candidates. Hand-checking them showed these main sources of false positives:
381
+
382
+ - HAML and Slim views that weren't read
383
+ - Devise hooks
384
+ - fast-mcp tools registered through `descendants`
385
+ - ActionMailbox
386
+ - entry points named only outside Ruby, such as `rails runner Repo.sync` in a crontab
387
+
388
+ After the fixes above, 167 candidates remain, and hand checks found most of them really dead or used only by tests. The crontab kind still needs a line in `.backburn.roots`.
389
+
390
+ ## Status
391
+
392
+ **Acceptance.** On the spec's three real codebases, the binary reproduces the spec's file, definition, candidate and batch counts exactly. On Rails, the uncertain bucket moved 2 candidates (and 2 batches) out of the earlier 65 and 46:
393
+
394
+ | Codebase | Commit | Candidates | Batches | Time |
395
+ | --- | --- | --- | --- | --- |
396
+ | rubygems.org | `6f51e32` | 35 | 25 | about 0.15 s |
397
+ | Tentacles | `0ddf4da` | 32 | 21 | about 0.07 s |
398
+ | Rails | `443726c` | 63, plus 2 uncertain | 44 | about 0.38 s |
399
+
400
+ **Not implemented yet.** [docs/cli-and-outputs.md](docs/cli-and-outputs.md) describes a local `.backburn/` directory with a parse cache and `.backburn/last.json` for `explain` to reuse. Neither exists yet. Every run parses the project from scratch, which takes well under a second even on Rails.
401
+
402
+ ## Legacy flags
403
+
404
+ The original flags still work for one release and print a deprecation warning on stderr:
405
+
406
+ | Old | New |
407
+ | --- | --- |
408
+ | `backburn --tsv DIR` | `backburn scan --format tsv DIR` |
409
+ | `backburn --batches DIR` | `backburn batches DIR` |
410
+ | `ruby gem_usage.rb DIR` | `backburn gems DIR` |
411
+
412
+ `gem_usage.rb` is now a shim that warns and runs `./backburn gems` from the same directory.
413
+
414
+ `--tsv` keeps the old column layout (`file`, `line`, `kind`, `name`, `reason`, `only_in_tests`) and old reason names (`never_referenced`, `only_dead_callers`, `dead_cycle`). `--format tsv` uses the new columns and reason names.
415
+
416
+ ## Building from source
417
+
418
+ For contributors, or to run Backburn from a checkout. Requirements:
419
+
420
+ - a C compiler (`cc`, clang or gcc) and `make`
421
+ - `git`, to fetch Prism
422
+ - Ruby, **at build time only**: Prism generates part of its C source from Ruby templates. The `backburn` binary itself needs no Ruby.
423
+
424
+ ```sh
425
+ make # fetches the pinned Prism commit into vendor/prism, builds libprism.a, then backburn
426
+ make test # runs the checks in test/ (test/run.sh)
427
+ ```
428
+
429
+ The first `make` clones Prism at the commit pinned in the `Makefile` (`PRISM_COMMIT`) and builds its static library. It then compiles `src/` into `build/` (object files plus the generated `build/presets.h` and `build/version.h`) and links `./backburn`. Prism's C API changed in 2026, so stick to that commit unless you also update the sources. The result is one self-contained executable with the presets compiled in. Copy it anywhere on your `PATH`. `make clean` removes the build output.
430
+
431
+ `make test` runs `test/run.sh`, which has 11 checks:
432
+
433
+ - 9 checks against `test/fixture/`:
434
+ - the legacy `--tsv` output matches the spec's `expected.tsv`
435
+ - `scan --format tsv` output
436
+ - the five presets give `rails.roots`' result
437
+ - `batches --format tsv` output
438
+ - `explain` text
439
+ - JSON and SARIF are valid (parsed with Ruby)
440
+ - `--fail-on any` exits 1
441
+ - an unknown option exits 2
442
+ - 3 regression cases in `test/cases/`:
443
+ - `self_superclass`: `class Admin::Thing < ::Thing`
444
+ - `haml_slim`: HAML and Slim views
445
+ - `uncertain_send`: `send(name)` on self makes methods uncertain, not dead (scan, `explain` and JSON)
446
+
447
+ ### The source gem
448
+
449
+ `gem install` can't count on git or a network, so the gem carries Prism's C sources, already generated at `PRISM_COMMIT`, in `ext/backburn/prism/`. When that directory exists, `make` builds Prism from it and needs neither git nor Ruby. Otherwise it fetches Prism into `vendor/prism` as above.
450
+
451
+ ```sh
452
+ rake vendor:prism # copies Prism's generated sources at PRISM_COMMIT into ext/backburn/prism (ignored by git)
453
+ rake build # runs vendor:prism, then builds pkg/backburn-VERSION.gem
454
+ ```
455
+
456
+ On `gem install`, `ext/backburn/extconf.rb` writes a Makefile that runs this repo's `make` inside the installed gem and moves the binary to `libexec/backburn`, where the `backburn` command runs it. A C compiler and `make` are all it needs.
457
+
458
+ ### Platform gems
459
+
460
+ A platform gem carries a prebuilt binary, so most machines need no compiler. RubyGems picks the gem that matches the machine and falls back to the source gem.
461
+
462
+ ```sh
463
+ rake native # builds, runs make test, then packages pkg/backburn-VERSION-PLATFORM.gem for this machine
464
+ rake native PLATFORM="x86_64-linux x86_64-linux-musl" # one binary, one gem per listed platform
465
+ ```
466
+
467
+ | Platform | Built on | Binary |
468
+ | --- | --- | --- |
469
+ | `x86_64-linux`, `x86_64-linux-musl` | Alpine, x86_64 | static (musl), so it runs on any glibc or musl Linux |
470
+ | `aarch64-linux`, `aarch64-linux-musl` | Alpine, Arm64 | static (musl) |
471
+ | `arm64-darwin` | macOS, Apple silicon | macOS 11 and later, ad-hoc signed by the linker |
472
+ | `x86_64-darwin` | macOS, Intel | macOS 11 and later |
473
+
474
+ `.github/workflows/gems.yml` builds the source gem and all six platform gems on every pull request. It then installs each one on a clean runner or container (the Linux platform gems in images with no compiler) and runs `test/smoke.sh`: `backburn --version`, `backburn scan test/fixture` and the whole of `test/run.sh` against the installed command. Windows isn't supported.
475
+
476
+ ### Releasing
477
+
478
+ 1. Bump `VERSION` in `lib/backburn/version.rb` and merge it.
479
+ 2. Tag that commit `v` plus the version, for example `git tag v0.2.0 && git push origin v0.2.0`.
480
+
481
+ The tag starts `.github/workflows/release.yml`, which:
482
+
483
+ - checks that the tag matches the version
484
+ - builds and smoke-tests every gem with `gems.yml`
485
+ - pushes the platform gems, then the source gem, to rubygems.org
486
+
487
+ It publishes with [trusted publishing](https://guides.rubygems.org/trusted-publishing/), so no API key is stored in GitHub.
488
+
489
+ ## Repository layout
490
+
491
+ | Path | What |
492
+ | --- | --- |
493
+ | `src/main.c` | entry point |
494
+ | `src/core/` | `util`, `intern` (string interner), `model` (definition tables), `json` |
495
+ | `src/index/` | `walk` (file walk, globs), `indexer` (Prism visitor), `erb`, `haml` (HAML/Slim to Ruby) |
496
+ | `src/analysis/` | `graph` (name indexes, pattern expansion, class and mixin resolution), `roots`, `mark` (marking, classification), `batches`, `analysis` (pipeline, stable ids) |
497
+ | `src/cli/` | `options`, `cli` (argument parsing), `config` (the YAML subset) |
498
+ | `src/output/` | `report` (text, TSV, JSON, SARIF), `baseline` |
499
+ | `src/commands/` | `scan`, `explain`, `roots`, `gems`, `gemfile`, `init`, `commands.h` |
500
+ | `presets/*.roots` | the built-in presets, compiled into the binary |
501
+ | `test/` | `run.sh` (what `make test` runs), `fixture/` (one rule per file, plus expected outputs), `cases/` (regression cases), `smoke.sh` (installs a gem and checks the installed command) |
502
+ | `.github/workflows/` | `gems.yml` (builds and smoke-tests every gem), `release.yml` (publishes them on a `v*` tag) |
503
+ | `docs/` | `technical-spec.md` (algorithm, rules, known limits), `cli-and-outputs.md` (CLI, formats, config, exit codes) |
504
+ | `exe/backburn` | the gem's executable: a Ruby wrapper that runs the native binary installed as `libexec/backburn` |
505
+ | `lib/backburn/version.rb` | the version, the only place it is set |
506
+ | `ext/backburn/` | `extconf.rb`, which builds the binary on `gem install`, and `prism/`, Prism's generated sources vendored by `rake vendor:prism` (not committed) |
507
+
508
+ Other top-level files:
509
+
510
+ - `backburn.gemspec` packages Backburn as a gem. It reads its version from `lib/backburn/version.rb`.
511
+ - `Makefile` builds `src/` into `build/`. It builds Prism from `ext/backburn/prism` when that exists, and otherwise fetches it into `vendor/prism` (not committed). It also has the `test` and `clean` targets.
512
+ - `Rakefile` has `vendor:prism`, `build`, which builds the source gem into `pkg/`, and `native`, which builds a platform gem.
513
+ - `scripts/embed-presets.sh` generates `build/presets.h` from `presets/*.roots`, and `scripts/version-h.sh` generates `build/version.h` from `lib/backburn/version.rb`.
514
+ - `rails.roots` is the spec's original roots file.
515
+ - `samples/` holds example project roots files.
516
+ - `gem_usage.rb` is a deprecated shim for `backburn gems`.
517
+
518
+ ## License
519
+
520
+ Released under the [MIT License](LICENSE).