Skip to content

Add ShipMonk custom sniffs ported from monorepo#17

Merged
janedbal merged 5 commits into
masterfrom
add-generic-custom-sniffs
Jun 22, 2026
Merged

Add ShipMonk custom sniffs ported from monorepo#17
janedbal merged 5 commits into
masterfrom
add-generic-custom-sniffs

Conversation

@janedbal

@janedbal janedbal commented Jun 18, 2026

Copy link
Copy Markdown
Member

Ports 7 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)
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 runs in CI.

Intentionally excluded

  • GeneralSpacing — superseded by the already-enabled SlevomatCodingStandard.Whitespaces.DuplicateSpaces (+ Squiz.WhiteSpace.OperatorSpacing).
  • SwitchStatementToMatchExpr — kept internal (monorepo) only. It bans switch outright, but match can't replace statement/control-flow switches (multiple statements, fall-through, continue/break levels); across the OSS libs it only flagged such legitimate switches with no safe auto-fix.

Supporting changes

  • Production namespace root ShipMonk\CodingStandardShipMonkCodingStandard for clean ShipMonkCodingStandard.* sniff codes (non-breaking; the --standard=ShipMonkCodingStandard ref is unchanged).
  • require: added squizlabs/php_codesniffer and ext-tokenizer.
  • PHPStan: bootstrap PHP_CodeSniffer, add a token-stream stub, and relax reportPossiblyNonexistentGeneralArrayOffset / internalTag for sniff code (the monorepo does the same).

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
@janedbal
janedbal marked this pull request as ready for review June 19, 2026 07:55
janedbal added 3 commits June 22, 2026 09:30
For a multiline catch whose closing brace of the preceding try sits at
column 1 (e.g. a top-level try/catch in a script), the indentation token
read for the catch line is actually the line break, so `$catchIndent`
became "\n". The closing-indent check then reported a false positive on
valid code and the fixer inserted a blank line before the `)`.

Strip the leading newline from `$catchIndent` and handle the empty-indent
(column 1) case explicitly. Adds top-level fixtures and locks the fixer
output of the multiline cases with `.fixed` files (previously only the
error count was asserted).

Co-Authored-By: Claude Code
It bans `switch` outright, but `match` cannot replace statement/control-flow
switches (multiple statements per case, fall-through, `continue`/`break` with
levels). On the ShipMonk OSS libraries it only ever flagged such legitimate
switches, with no safe auto-fix. Keep it out of the shared standard.

Co-Authored-By: Claude Code
Completes the previous commit, which deleted the sniff files but left the
ruleset reference, breaking phpcs with "Referenced sniff does not exist".

Co-Authored-By: Claude Code
@janedbal
janedbal merged commit 33d809c into master Jun 22, 2026
7 checks passed
@janedbal
janedbal deleted the add-generic-custom-sniffs branch June 22, 2026 15:15
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