fun-refactor

19 languages · one index · byte-exact edits

Refactoring that tells you
what it could not prove.

Rename a symbol across Go, TypeScript, Rust, Python and a Helm chart at once. Each reference it finds carries the evidence that found it. The tool rewrites the references it can justify and hands you the rest as a list.

Every reference carries its resolution tier

A textual rename covers every language and proves nothing. A compiler-backed one proves everything and covers one language. This tool resolves what the syntax settles, labels each answer with the rule that produced it, and rewrites the two strongest tiers.

It rewrites exact and import-qualified. It hands you field-based and name-only to check yourself. It guesses nothing.

helm/helm @ a8ab76e
fr refs pkg/action/action.go:725:6
5 reference(s) to determineReleaseSSApplyMethod
  pkg/action/action_test.go:2280:54  [exact]
  pkg/action/action_test.go:2281:54  [exact]
  pkg/action/install.go:676:23       [exact]
  pkg/action/rollback.go:192:23      [exact]
  pkg/action/upgrade.go:334:23       [exact]

It reads the configuration too

A Helm chart pairs a values file with the templates that read it, a dataflow no compiler sees. Rename a values key and the templates that use it move with it. {{ .Release.Name }} stays as written, because it spells the same word and means a different thing.

alpine chart
fr rename testcharts/alpine/values.yaml:1:1 appName
-  name: "{{.Release.Name}}-{{.Values.Name}}"
+  name: "{{.Release.Name}}-{{.Values.appName}}"
-    values: {{.Values.Name}}
+    values: {{.Values.appName}}

Name → appName: 3 site(s) across 2 file(s)

Not changed — review these yourself:
  textual-occurrence (1):
    alpine-pod.yaml:3:17  'Name' appears in a string or comment; left unchanged

Measured on real code

Every figure below comes from a run over helm/helm and grafana/grafana.

16,525 files of Grafana parsed in 10.9 seconds, across 13 languages
337 duplicated blocks in helm, holding 64,530 redundant tokens, found in 3.6s
47 genuinely dead internal Go symbols in helm, down from 238 false positives

Languages

  • Rust
  • Go
  • Java
  • TypeScript
  • TSX
  • Python
  • Zig
  • Bash
  • HTML
  • CSS
  • SCSS
  • Sass
  • Terraform
  • JSON
  • YAML
  • Helm
  • XML
  • Markdown
  • Lean

Run fr capabilities for the live capability × language matrix and the reason attached to every unsupported combination.

Get it

git clone https://github.com/e6qu/fun-refactor
cargo install --path fun-refactor

cd ~/code/your-project
fr parse --stats
fr unused --internal
fr duplicates

Three questions, in order: what can it read, what is dead, and what is written twice.