deadcode: support references in Slim templates
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 42/100
Línea de trabajo
Start by reading the issue’s description of Deadcode::Index#index_file and its existing ERB handling, then trace how allowed extensions select files for analysis. The proposed path is to compile Slim templates to Ruby and reuse the reference indexing pipeline; the issue’s experiment gives examples to investigate and flags line mapping, dependency handling, and wrapper suppression. Done means references in Slim keep used methods or constants alive while unused definitions remain candidates, with tests covering supported cases and errors.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Problem
References in Slim templates are currently outside the supported template analysis path. This can cause definitions used only from those templates to be reported as dead code candidates.
I reproduced this with Ruby 3.4.3, Spoom 1.8.13, and Slim 5.2.2:
- The default extensions are
.rb,.erb, and.gemspec. Deadcode::Index#index_filehandles.erbspecially and treats other files as Ruby.- Adding
.slimthrough--allowed-extensionstherefore does not provide Slim parsing support.
Minimal reproduction
In an otherwise empty directory, use this Gemfile:
source "https://rubygems.org"
gem "spoom", "1.8.13"
gem "slim", "5.2.2"
Create presenter.rb:
class ReportPresenter
def display_label
"Report"
end
def unused_label
"Unused"
end
end
Create view.html.slim:
= ReportPresenter.new.display_label
Run:
bundle install
bundle exec spoom deadcode --no-color --show-files
bundle exec spoom deadcode --no-color --show-files --allowed-extensions .rb .erb .gemspec .slim
The default invocation collects only presenter.rb and reports both methods as dead candidates. With .slim explicitly enabled, both files are collected, but the CLI reports:
Error: Error parsing view.html.slim: Error while parsing view.html.slim:
- unexpected '=', ignoring it (at 1:0)
It continues analysis and still reports both methods:
Candidates:
ReportPresenter::display_label presenter.rb:2:2-4:5
ReportPresenter::unused_label presenter.rb:6:2-8:5
Found 2 dead candidates
Expected: display_label should be kept alive by the Slim reference, while unused_label should remain a candidate.
As controls, I ran the same method call from a Ruby file and from an ERB template in separate runs. Each reported only unused_label. All four runs exited with status 1, because the deliberately unused method remains in every case.
Rails verification
I also reproduced this in a small Rails 8.1.4.1 application with slim-rails 4.0.1, using the same Spoom, Slim, and Ruby versions.
The helper was:
module ReportsHelper
def display_label
"Slim reference works"
end
def unused_label
"Unused"
end
end
The Slim view was:
h1
= display_label
The ERB control was <h1><%= display_label %></h1>. Both routes returned HTTP 200 and rendered <h1>Slim reference works</h1> through the Rails application using Rack::MockRequest.
I then analyzed app/helpers and one view at a time so that the ERB reference could not mask the missing Slim reference:
bundle exec spoom deadcode app/helpers app/views/reports/erb.html.erb --no-color --show-files --show-plugins
bundle exec spoom deadcode app/helpers app/views/reports/slim.html.slim --no-color --show-files --show-plugins
bundle exec spoom deadcode app/helpers app/views/reports/slim.html.slim --no-color --show-files --show-plugins --allowed-extensions .rb .erb .gemspec .slim
| View analyzed | Result |
|---|---|
| ERB | Only unused_label reported |
| Slim, default extensions | View not collected; both methods reported |
| Slim, explicit extension | View collected but parse error at 2:2; both methods reported |
Spoom::Deadcode::Plugins::Rails was loaded in all three runs. This application was created for reproduction; these are not results from an existing production project.
Proposed direction
Would you be open to Slim support that follows the existing ERB approach: compile the template to Ruby, wrap it as needed for parsing, and reuse the existing reference indexing pipeline?
I would start with Slim, focusing on references to constants and methods. Haml could be considered separately afterward.
Compilation experiment
In a separate experiment, without modifying Spoom, I generated Ruby using Slim::Engine.new.call(template), wrapped it in a synthetic method, and passed it to Index#index_ruby.
With Slim 5.2.2 and its default options, the existing indexing pipeline found the expected constant/method references in six examples covering output, a silent-code loop, interpolation, a dynamic attribute, a splat attribute, and a nested conditional. A seventh example confirmed that a Slim comment did not introduce those references. The used method was kept alive in the six positive cases and the unused control remained a candidate in all seven.
Reference line numbers matched the template lines in these examples after subtracting the single wrapper line. This is limited evidence for the approach, not a guarantee for all Slim constructs or compiler versions. Column mapping, embedded engines, custom Slim options, and broader version compatibility still need investigation. The experiment also does not implement file dispatch, dependency/error handling, or suppression of the synthetic wrapper definition.
Questions
- Is compiling Slim to Ruby and reusing the ERB-style indexing path a direction you would accept?
- Would a Slim-only first contribution, enabled explicitly through
--allowed-extensions, be an appropriate scope? - Would you prefer Slim to be an optional dependency loaded only when needed? If a Slim file is selected but the gem is unavailable, should analysis fail or report the skipped file and continue? Skipping it could affect the dead code candidates because its references would be missing.
I would be happy to investigate and contribute tests for output expressions, control flow, attributes, interpolation, and invalid templates once the direction is agreed upon.
- Lenguaje dominante
- Ruby
- Estrellas
- 274
- Forks
- 30
- Merge medio
- 3 h 4 min
- PR fusionados (30 d)
- 8
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Shopify/spoom
-
`spoom srb bump DIRECTORY` bumps files outside DIRECTORYPosiblemente ocupada @RaphaelFakhri la tomó hace 34 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
srb sigs translate: type parameter shadows a type name used in the same signaturePosiblemente ocupada @Hashim1999164 la tomó hace 97 días. Abiertobug
Dificultad 4/5 3-5 días Aptitud para principiantes 56/100
Los mantenedores suelen responder en 1 día
-
`srb sigs translate` removes comments during translationPosiblemente ocupada @KaanOzkan la tomó hace 223 días. Abierto
Shopify/spoom#900 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
Shopify/spoom#488 · 3 comentarios · 3 reacciones ·
Los mantenedores suelen responder en 1 día
Todos los issues de Shopify/spoom
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
TarteelAI/quranic-universal-library#1111 ·
Los mantenedores suelen responder en 1 día
-
Generated cask uses deprecated `postflight` stanza; Homebrew 7 warns on every commandPosiblemente ocupada @k4kratik la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
sachincool/cruft#4 ·
-
load_reserved() and store_conditional() call memory_model_acquire() before the memory accessAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
riscv/riscv-unified-db#2859 ·
Los mantenedores suelen responder en 2 días
-
agent-driven deployment documentation future releases nice to have
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
changesets
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
openstreetmap/openstreetmap-website#7629 · 1 comentario ·
Los mantenedores suelen responder en 1 día