Automattic / Automattic/VIP-Coding-Standards
Flag incorrect use of filter (instead of action) before AlwaysReturnSniff
- Dominant language
- PHP
- Stars
- 261
- Forks
- 44
- Avg merge
- 19m
- Merged PRs (30d)
- 1
Description
## What problem would the enhancement address for VIP?
Code that uses a filter instead of an action are being flagged with `WordPressVIPMinimum.Filters.AlwaysReturn.missingReturnStatement` when the correct developer remediation for the problematic code should be to change it to `add_action`
## Describe the solution you'd like
Flag use of `add_filter` on hooks that are most definitely only supposed to use `add_action`
Even better, use GitHub "suggestions" to show the correct change.
## What code should be reported as a violation?
`add_filter( 'rss2_item', 'attached_images' );`
## What code should *not* be reported as a violation?
`add_filter( 'the_content', 'my_filter_content' );`
## Additional context
If this raises a flag, then the `WordPressVIPMinimum.Filters.AlwaysReturn.missingReturnStatement` sniff should NOT.
Contributor guide
Research direction
Start by examining the WordPressVIPMinimum.Filters.AlwaysReturn.missingReturnStatement sniff and how it handles add_filter calls. Compare the supplied rss2_item and the_content examples, then define the hook list and interaction needed so action-only hooks are flagged while the missing-return violation is not; done means those two examples produce the requested outcomes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- devtools, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100