Skip to content

Add ShipMonk custom sniffs ported from monorepo#17

Draft
janedbal wants to merge 2 commits into
masterfrom
add-generic-custom-sniffs
Draft

Add ShipMonk custom sniffs ported from monorepo#17
janedbal wants to merge 2 commits into
masterfrom
add-generic-custom-sniffs

Conversation

@janedbal

Copy link
Copy Markdown
Member

Ports 8 generic custom sniffs from the monorepo CodingStyle ruleset into this OSS standard, with tests, backported to PHP 7.4 (CI matrix 7.4–8.5).

Sniffs added

Sniff Auto-fix
Arrays.DoubleArrowSpacing
ControlStructures.EmptyConditionBody ❌ (needs a human-written "why empty" comment)
ControlStructures.SwitchStatementToMatchExpr ❌ (unsafe AST rewrite)
Whitespaces.CatchSpacing
Whitespaces.DisallowOneLineDocComment
Whitespaces.MultilineConditionSpacing
Whitespaces.MultilineTernary
Whitespaces.OpenParenthesisSpacing

Each sniff has pass/fail fixtures (and .fixed fixtures for fixable ones). PHPUnit is now wired into composer check so the suite actually runs in CI (it didn't before).

Dropped vs. the original request

  • GeneralSpacing — dropped: fully superseded by the already-enabled SlevomatCodingStandard.Whitespaces.DuplicateSpaces (+ Squiz.WhiteSpace.OperatorSpacing), which also auto-fix.

Supporting changes

  • Production namespace root ShipMonk\CodingStandardShipMonkCodingStandard so PHPCS emits clean ShipMonkCodingStandard.* sniff codes (no existing production classes, non-breaking; the --standard=ShipMonkCodingStandard ref is unchanged).
  • require: added squizlabs/php_codesniffer and ext-tokenizer (sniffs use their symbols directly).
  • PHPStan: bootstrap PHP_CodeSniffer (autoload.php + Tokens.php), add a token-stream stub (build/phpstan/php-codesniffer.stub), and disable reportPossiblyNonexistentGeneralArrayOffset + internalTag (both incompatible with the token-stream / slevomat-@internal-helper idiom — the monorepo does the same).

Noise check on ShipMonk OSS packages (real code, fixtures excluded)

Ran the 8 sniffs in isolation across all 19 shipmonk/* packages. Excluding test fixtures (which legitimately contain one-line docblocks etc.), real-code hits total 13:

Sniff Real hits Fixable
SwitchStatementToMatchExpr 9
DisallowOneLineDocComment 3
MultilineConditionSpacing 1
all others 0

Open question

SwitchStatementToMatchExpr is the only sniff with real, non-auto-fixable churn (9 hits on legitimate token-dispatch switches in cda / name-collision-detector / static-reflection). Keep it (mandate match) or drop it? — left in for now, easy to remove.

Co-Authored-By: Claude Code

janedbal added 2 commits June 18, 2026 16:17
Adds 8 generic custom sniffs under the ShipMonkCodingStandard standard,
ported from the monorepo CodingStyle ruleset and backported to PHP 7.4:

- Arrays.DoubleArrowSpacing (fixable)
- ControlStructures.EmptyConditionBody
- ControlStructures.SwitchStatementToMatchExpr
- Whitespaces.CatchSpacing (fixable)
- Whitespaces.DisallowOneLineDocComment (fixable)
- Whitespaces.MultilineConditionSpacing (fixable)
- Whitespaces.MultilineTernary (fixable)
- Whitespaces.OpenParenthesisSpacing (fixable)

Each sniff has tests (pass/fail fixtures, plus .fixed fixtures for the
fixable ones). PHPUnit is now wired into `composer check` so the suite
runs in CI.

Supporting changes:
- production namespace root ShipMonk\CodingStandard -> ShipMonkCodingStandard
  so PHPCS emits clean ShipMonkCodingStandard.* sniff codes
- require squizlabs/php_codesniffer and ext-tokenizer explicitly
- PHPStan: bootstrap PHP_CodeSniffer, add a token-stream stub, and relax
  reportPossiblyNonexistentGeneralArrayOffset / internalTag for sniff code

Co-Authored-By: Claude Code
name-collision-detector parses files with the runtime PHP, so PHP 8.0+
syntax (e.g. match) in tests/Data fixtures fails to parse on PHP 7.4 CI.
Fixtures are not real code, so exclude tests/Data from collision scanning
via collision-detector.json.

Co-Authored-By: Claude Code
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.

1 participant