Add a make lint-diff convention check and a pre-commit step in CLAUDE.md - #6178
Add a make lint-diff convention check and a pre-commit step in CLAUDE.md#6178SanderMuller wants to merge 1 commit into
make lint-diff convention check and a pre-commit step in CLAUDE.md#6178Conversation
…DE.md `make lint-diff` (build/lint-diff.php) scans the lines a branch adds for the conventions that recur on review and prints each with its file and line: instanceof of a Type that has a method alternative (StringType -> isString(), EnumCaseObjectType -> getEnumCaseObject()), get_class() type dispatch, and a new inline @PHPStan-Ignore. Structural classes with no method alternative (NeverType, TemplateType, UnionType, MixedType) are not flagged, because instanceof is idiomatic for those. It is advisory (exit 0; --strict to fail); a reviewed exception is acknowledged with phpstan-lint-ok on the line. CLAUDE.md gains a "run make lint-diff and resolve every finding" step so the check is part of the workflow, plus a note that make phpstan is not the whole static-analysis gate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
I doňt understant the need for this when we have make phpstan, and custom PHPStan rules. |
|
Also we can write more custom rules. |
Good idea to replace some of this with custom rules, looking into that |
|
You're right, and it goes further than I first realised: PHPStan already has this exact rule. It also reframes the #6116 case that motivated me. The only thing worth keeping out of all this is a doc line, not a rule: a note in CLAUDE.md that you fix a rule error you just introduced rather than baselining or ignoring it. That is the actual lesson. Happy to skip even that if you'd rather. Thanks for the pushback. |
This adds
make lint-diffand a short verification step in CLAUDE.md that uses it, so the conventions that keep coming up on review get caught before pushing rather than after CI.build/lint-diff.phpscans the lines a branch adds (against 2.2.x) and prints each candidate with its file and line:instanceofof aTypethat has a method alternative on theTypeinterface (instanceof StringTypeto->isString(),instanceof EnumCaseObjectTypeto->getEnumCaseObject()). Structural classes with no such method (NeverType,TemplateType,UnionType,MixedType) are deliberately not flagged, sinceinstanceofis idiomatic for those. Curating to the method-having classes keeps it precise: measured against the last 60 commits on 2.2.x it fires on 1.get_class(), which is brittle for type dispatch.@phpstan-ignore(fix the root cause; the baseline is for pre-existing errors).It is advisory: it prints candidates and exits 0, so it never blocks legitimate structural
instanceof.--strictexits non-zero for anyone who wants it in a gate. A reviewed exception is acknowledged withphpstan-lint-okon the line, and test-data fixtures are skipped.CLAUDE.md gains one workflow step (run
make lint-diffand resolve every finding) plus a note thatmake phpstanis not the whole static-analysis gate: the Mutation Testing job runs a stricter analysis that catches things it does not, for example an incomplete#[RequiresPhp('^8.1')]version constraint.build/lint-diff.phpismake phpstan-clean.