Skip to content

Support detection of never written properties#291

Merged
janedbal merged 15 commits intomasterfrom
never-written-properties
Mar 2, 2026
Merged

Support detection of never written properties#291
janedbal merged 15 commits intomasterfrom
never-written-properties

Conversation

@janedbal
Copy link
Copy Markdown
Member

@janedbal janedbal commented Jan 29, 2026

Enable via:

parameters:
    shipmonkDeadCode:
        detect:
            deadProperties:
                neverWritten: true

Properties with @api (or in @api classes) should be treated as both
read and written by external code. Without this, @api properties were
falsely reported as "never written".
Demonstrates the shipmonk.deadProperty.neverWritten identifier
alongside the existing neverRead, deadConstant, deadMethod and
deadEnumCase identifiers.
Adds a PropertyWrites test class and corresponding
shouldMarkPropertyAsWritten override in the custom provider,
verifying the extension point suppresses neverWritten errors
independently of other member types.
PropertyAccessCollector only tracked promoted property writes for
`new` expressions. This adds tracking for static calls to __construct
(e.g. parent::__construct()), so promoted properties in parent classes
are correctly marked as written.
Instead of detecting promoted property writes at each call site (new,
parent::__construct, etc.), emit them once inside the constructor
definition via InClassMethodNode. Transitivity handles propagation
from any caller automatically.

This also removes getDerivedUsages from ProvidedUsagesCollector, as
it is no longer needed — provider-marked constructor usages propagate
to promoted property writes through the same transitivity mechanism.
Extract buildTransitiveErrorMessages to produce property-aware
messages ("transitively never read/written") instead of always
saying "transitively also unused".
…e properties

Virtual properties (hooks that don't reference the backing value) without
a set hook cannot be written to, so they should not be tracked for
neverWritten detection. This replaces the previous interface-only check
with proper virtual property detection that also handles closures, arrow
functions, and anonymous classes inside hook bodies correctly.
@janedbal janedbal merged commit c6d4a0f into master Mar 2, 2026
40 checks passed
@janedbal janedbal deleted the never-written-properties branch March 2, 2026 13:14
@ruudk
Copy link
Copy Markdown
Contributor

ruudk commented Mar 2, 2026

🙌 Thanks for this. Will this be tagged soon 🙏 ?

@janedbal
Copy link
Copy Markdown
Member Author

janedbal commented Mar 2, 2026

Expect tag this week :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants