Needs work
Project:
Drupal core
Version:
main
Component:
other
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
24 Mar 2026 at 11:01 UTC
Updated:
31 Mar 2026 at 07:31 UTC
Jump to comment: Most recent
https://github.com/shipmonk-rnd/dead-code-detector looks like an interesting package, it has Symfony support already and perhaps we could provide any additional Drupal support that would be needed.
Install the package
See what it reports when run against core
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
longwaveComment #4
longwaveIt doesn't understand things like attribute objects or hook classes, but otherwise it's catching a bunch of stuff. To pick some random examples:
These are all correct as far as I can see.
Same.
Same.
This one is wrong, because it considers the hook implementation methods as dead code.
Marking NR to discuss what to do next here; should we try to fix some of these, maybe in bulk by scoping this somehow? Tests are probably easier to reason about first, in other code we might need to consider subclasses and BC.
Should we add these to the baseline to try and prevent more creeping in when we refactor things? We would need to solve any false positives first, however.
Comment #5
mondrakeMaybe we could first try Rector dead code ruleset - https://getrector.com/find-rule?activeRectorSetGroup=core&rectorSet=core...
Comment #6
longwave@mondrake I think those are complementary, so we could try that in a separate issue - the Rector rules look to detect dead/useless code within methods, while this package detects entire dead methods and member variables.
Comment #7
smustgrave commentedCame here after reviewing #3581404: Remove unused properties from kernel tests and definitely seems like an interesting library.
From what I can tell they do releases every 1-2 months
Low issue queue
I like the part that it has some twig interaction. Always wished we had some kind of twig linting and know that's not the same but least they would get scanned.
Comment #8
borisson_I think this is the way forward, yes. I agree this would be good to do.
Comment #9
smustgrave commentedSeems like this got a number of +1 moving to NW to fix up the pipeline. @longwave feel free to ping me when ready.
Comment #10
longwaveWe need to figure out the false positives and remove them first ideally, otherwise it will start failing on new MRs that have similar false positives. This might take a while.
In the meantime we can break out more child issues if we can figure out a reasonable way to scope them.
Comment #11
quietone commentedI used shipmonk/dead-code-detector a few days ago to cleanup the new Admin theme, #3582178: Remove dead code in Admin. Other than the false positives it was straightforward to make an MR to make the fixes. If that MR proves to not introduce errors, then I support adding this tool.
I have a bias against increasing the size of the baseline, so I would prefer to fix these first before adding the rule to core.
Comment #12
quietone commentedThe number of instances of each identifier discovers
edit: paste the correct code and output.
Comment #13
quietone commentedI'd fix them by identifier. And then in each group by the same distinctions usually used for coding standards. That is separate tests from non-tests. And sub-divide those as needed, so maybe tests in core/tests and tests in modules or themes.
Comment #14
borisson_So that means 3 issues for the simplest ones, deadConstant, deadEnumCase, deadProperty.neverWritten? Those should be reviewable still I think. The neverRead is probably way too big to be easy to review.
Are those numbers after #3581407: Remove unused properties from unit tests and #3581404: Remove unused properties from kernel tests?