Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/dependency-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
runs-on: ubuntu-latest

steps:

- name: Trigger the dependency-updates worker
env:
GH_TOKEN: ${{ secrets.DEPENDENCIES_DISPATCH_TOKEN }}
Expand Down
28 changes: 7 additions & 21 deletions .github/workflows/quality-gates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ on:
# ==============================================================================
# CONCURRENCY
# ==============================================================================
# The event name keeps scheduled and manual runs out of the push group, so a
# merge to master cannot cancel one part way through.
# The event name stops a merge to master cancelling a scheduled or manual run.
concurrency:
group: quality-gates-${{ github.event.pull_request.number || github.ref }}-${{ github.event_name }}
cancel-in-progress: true
Expand Down Expand Up @@ -54,29 +53,22 @@ jobs:
persist-credentials: false
fetch-depth: 0

# This repo diverges from the shared setup-php action, which pins
# the coverage driver to pcov: php_codesniffer loads sniffs through
# its own include()-based autoloader, which pcov does not instrument
# (it reports 0%). Xdebug is the only driver that sees them, so it
# is set directly.
# pcov does not instrument sniffs loaded by phpcs's own autoloader.
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
coverage: xdebug
tools: composer

# The suite supports phpcs 3.x and 4.x; the mutation leg pins the
# 4.x major consumers run so the mutant population stays stable
# run-to-run.
# Pinned to the 4.x major consumers run, to keep mutants stable.
- name: Install dependencies
run: >
composer update --prefer-dist --no-interaction --no-progress
--with "squizlabs/php_codesniffer:^4.0.2"

# On a push, origin/master is the pushed commit itself, so the gate
# diffs against the commit master moved from. A push that rewrote
# master instead of moving it forward leaves no such base.
# On a push origin/master is the pushed commit, so diff against the
# previous head.
- name: Scoped mutation gate
env:
BEFORE: ${{ github.event.before }}
Expand Down Expand Up @@ -106,21 +98,15 @@ jobs:
with:
persist-credentials: false

# This repo diverges from the shared setup-php action, which pins
# the coverage driver to pcov: php_codesniffer loads sniffs through
# its own include()-based autoloader, which pcov does not instrument
# (it reports 0%). Xdebug is the only driver that sees them, so it
# is set directly.
# pcov does not instrument sniffs loaded by phpcs's own autoloader.
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
coverage: xdebug
tools: composer

# The suite supports phpcs 3.x and 4.x; the mutation leg pins the
# 4.x major consumers run so the mutant population stays stable
# run-to-run.
# Pinned to the 4.x major consumers run, to keep mutants stable.
- name: Install dependencies
run: >
composer update --prefer-dist --no-interaction --no-progress
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ jobs:
name: Test / PHP ${{ matrix.php }} / phpcs ${{ matrix.phpcs }}
runs-on: ubuntu-latest

# Consumers run the sniffs under phpcs 4.x via qlty, so the suite is
# tested against both the 3.x and 4.x token streams. The resolver pulls
# the slevomat line that matches each phpcs major automatically.
# Consumers run phpcs 4.x via qlty; 3.x stays supported.
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -75,8 +73,7 @@ jobs:
composer update --prefer-dist --no-interaction --no-progress
--with "squizlabs/php_codesniffer:${{ matrix.constraint }}"

# Analysed on the PHP floor only: newer versions ask for attributes,
# such as #[\Override] on a property, that the floor cannot parse.
# Floor only: newer PHP asks for attributes the floor cannot parse.
- name: PHPStan
if: ${{ matrix.php == '8.3' }}
run: composer analyse
Expand Down Expand Up @@ -137,9 +134,8 @@ jobs:
- name: Install Qlty
uses: qltysh/qlty-action/install@v2

# Qlty anchors configuration at a Git worktree's root. The script
# creates an isolated consumer that exercises this checkout just as
# a downstream repository would.
# Qlty anchors config at the worktree root, so the script builds an
# isolated consumer.
- name: Verify Swift policy
run: bash scripts/test-swift-policy.sh

Expand Down
11 changes: 4 additions & 7 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Defensive backstop - `files` in package.json is the primary allowlist, but npm
# still walks the working tree and applies .gitignore-like rules first. Anything
# below is excluded even if it matches a `files` entry.
# Excluded even when matched by `files` in package.json.

# PHP-only distribution (Composer ships this separately as
# sinemacula/coding-standards).
# Shipped via Composer.
src/
SineMacula/
php/
Expand All @@ -12,15 +9,15 @@ composer.lock
vendor/
.php-cs-fixer.cache

# Repo tooling that doesn't belong in the npm tarball.
# Repo tooling.
.github/
.idea/
.qlty/
.qodo/
.editorconfig
source.toml

# Test specs and fixtures - kept in git and CI, never shipped to consumers.
# Tests and fixtures.
js/eslint/__tests__/
js/eslint/rules/__tests__/
tests/
Expand Down
16 changes: 4 additions & 12 deletions .qlty/configs/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@
use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

// qlty's pre-commit `qlty fmt` runs against a sparse worktree of only the
// staged files, so the shared rules file may be absent there. Fall back to an
// empty rule set (a no-op) rather than failing on the require; the full
// `qlty check` and qlty Cloud run against the complete tree and apply the real
// rules.
// qlty's pre-commit fmt runs on a sparse worktree of the staged files, where
// the rules file may be absent.
$rulesFile = dirname(__DIR__, 2) . '/php/.php-cs-fixer.rules.php';
$rules = is_file($rulesFile) ? require $rulesFile : []; // NOSONAR

// This repo's PHP is PHP_CodeSniffer sniff code. The shared rules promote
// docblock @param types to native types, but Sniff::process(File, $stackPtr)
// leaves $stackPtr untyped and PHP fatals if it is narrowed to int, so the
// promotion is disabled here. The rule is unchanged for consumers.
// Sniff::process() leaves $stackPtr untyped, and PHP fatals if it is narrowed.
if ($rules !== []) {
$rules['phpdoc_to_param_type'] = false;
}

// Filter to the directories that exist; in qlty's sparse pre-commit worktree
// the source trees may be absent, and Finder::in() throws on a missing
// directory.
// Finder::in() throws on a directory missing from the sparse worktree.
$dirs = array_values(array_filter([
dirname(__DIR__, 2) . '/src',
dirname(__DIR__, 2) . '/SineMacula/Sniffs',
Expand Down
5 changes: 1 addition & 4 deletions .qlty/configs/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

declare(strict_types = 1);

// Standalone PSR-4 autoloader for the SineMacula\CodingStandards namespace
// (-> src/). The dogfood phpcs config (phpcs.xml) loads this so the in-repo
// sniff base class resolves without the project's vendor/autoload.php, which
// qlty Cloud does not produce (it never runs `composer install`).
// Loads src/ for phpcs.xml, since qlty Cloud never runs `composer install`.

spl_autoload_register(static function (string $class): void {
$prefix = 'SineMacula\CodingStandards\\';
Expand Down
32 changes: 7 additions & 25 deletions .qlty/configs/phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
<ruleset name="SineMacula Project">

<!--
This repository IS the sinemacula/coding-standards package, so the
shared standard is referenced from the working tree by path rather than
by its installed name (it is not present as a vendor package in qlty's
tool sandbox). A standalone autoloader resolves the custom sniffs' base
classes under src/ without the project vendor, which qlty Cloud does not
install.
The standard is this repo, so it is referenced by path. autoload.php
resolves the src/ base classes, as qlty Cloud has no project vendor.
-->
<rule ref="../../SineMacula/ruleset.xml"/>
<autoload>autoload.php</autoload>
Expand All @@ -17,16 +13,9 @@
<file>../../SineMacula/Tests</file>

<!--
Scoped exemptions for this repo's PHP_CodeSniffer extension code. The
shared standard targets application code; these rules are physically
impossible to satisfy in sniff code and ship unchanged to consumers.

- ParameterTypeHint / ScalarTypeHintMissing: PHP_CodeSniffer's
Sniff::process(File $phpcsFile, $stackPtr) interface leaves $stackPtr
untyped, and PHP fatals if an implementation narrows it to int.
- RequireReadonlyPublicProperty: PHP_CodeSniffer assigns sniff
configuration properties from the ruleset at runtime, so they cannot be
readonly.
Unsatisfiable in sniff code: Sniff::process() leaves $stackPtr untyped
and PHP fatals if it is narrowed, and phpcs assigns sniff properties
from the ruleset at runtime.
-->
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<exclude-pattern>*/Sniffs/*</exclude-pattern>
Expand All @@ -38,21 +27,14 @@
<exclude-pattern>*/Sniffs/*</exclude-pattern>
</rule>

<!--
Every PHP file in this repo is tooling (sniffs, the PHPStan rule, the
cs-fixer config factory and their tests) that handles arbitrary token
and configuration values, so the no-mixed rule cannot be satisfied here.
-->
<!-- All PHP here handles arbitrary token and configuration values. -->
<rule ref="SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint">
<exclude-pattern>*/src/*</exclude-pattern>
<exclude-pattern>*/Sniffs/*</exclude-pattern>
<exclude-pattern>*/Tests/*</exclude-pattern>
</rule>

<!--
PHPStan's Rule::processNode(Node $node, Scope $scope) interface mandates
the $scope parameter even for rules that do not consult the scope.
-->
<!-- PHPStan's Rule::processNode() requires $scope even when unused. -->
<rule ref="SlevomatCodingStandard.Functions.UnusedParameter">
<exclude-pattern>*/PHPStan/*</exclude-pattern>
</rule>
Expand Down
52 changes: 18 additions & 34 deletions .qlty/qlty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ exclude_patterns = [
test_patterns = [
"**/test/**",
"**/spec/**",
# Match PHPUnit's PascalCase layout (Tests/, *Test.php); the defaults below
# are lowercase-only, so without these qlty treats tests as source.
# The defaults are lowercase-only; match PHPUnit's Tests/ and *Test.php.
"**/Tests/**",
"**/*Test.php",
"**/*.test.*",
Expand Down Expand Up @@ -89,69 +88,54 @@ name = "editorconfig-checker"
name = "markdownlint"
mode = "comment"

# Dogfood this repo's own standards on its own code: phpcs and php-cs-fixer use
# the in-tree configs under .qlty/configs, not a released tag. slevomat comes
# from composer.json; the base class loads via .qlty/configs/autoload.php (qlty
# Cloud has no project vendor/autoload.php).
# Lint with the in-tree configs under .qlty/configs, not a released tag. qlty
# Cloud has no project vendor, so .qlty/configs/autoload.php loads the bases.
[[plugin]]
name = "php-codesniffer"
# Pinned to the 4.x major consumers run via qlty; the suite is tested on both
# 3.x and 4.x in CI (the Tests workflow's phpcs matrix). Must stay at or above
# 4.0.2: earlier 4.x is affected by a command-injection advisory that Composer
# refuses to install, which fails the plugin outright rather than reporting it.
# The major consumers run. Composer refuses 4.x below 4.0.2 over a security
# advisory, which fails the plugin outright.
version = "4.0.4"
mode = "comment"
package_file = "composer.json"
package_filters = ["slevomat", "dealerdirect"]

# phpcs 4.x exits 3 on errors (bitmask: 1 errors + 2 fixable), which qlty's
# built-in driver, written for 3.x exit semantics, treats as a plugin failure -
# silently discarding the findings. The self-lint resolves php-codesniffer from
# the default source (not this repo's source.toml), so the override that
# source.toml ships to consumers is mirrored here. 0/1/2/3 = "ran and found
# issues" on both majors; a real fatal exits higher (255) and still errors.
# phpcs 4.x exits 3 on fixable errors, which qlty treats as a plugin failure
# and silently drops the findings. Mirrors the source.toml override, which the
# self-lint does not load.
[plugins.definitions.php-codesniffer.drivers.lint]
success_codes = [0, 1, 2, 3]

# This repo's fixer config builds its rules from the working tree rather than
# from the installed standards package, so the sandbox needs nothing but the
# tool itself - hence no package_file.
# The fixer config reads its rules from the working tree, so no package_file.
[[plugin]]
name = "php-cs-fixer"
version = "3.95.19"

# phpstan is NOT wired here: it needs the project vendor (composer install) that
# qlty Cloud lacks. Run it locally with `composer analyse` (phpstan.neon.dist).
# phpstan needs the project vendor, which qlty Cloud lacks; run `composer
# analyse` instead.

# php/ and .qlty/configs hold tool configs, not source, so the PHP plugins skip
# them; php/ stays so the cs-fixer config can require its rules file.
# php/ and .qlty/configs hold tool configs.
[[exclude]]
plugins = ["php-codesniffer", "php-cs-fixer"]
file_patterns = ["php/**", ".qlty/configs/**"]

# Release-please generates CHANGELOG.md with `*` bullets and long lines that
# markdownlint (MD004) and editorconfig-checker would reject. It is
# tool-authored, so exclude it from both (mirrors the source.toml excludes).
# Release-please writes CHANGELOG.md with `*` bullets and long lines.
[[exclude]]
plugins = ["editorconfig-checker", "markdownlint"]
file_patterns = ["**/CHANGELOG.md"]

# The qlty-generated git hooks carry tab indentation; they are tool-authored, so
# their indent style is not ours to fix. Exclude them from editorconfig-checker.
# The qlty-generated hooks are tab-indented.
[[exclude]]
plugins = ["editorconfig-checker"]
file_patterns = [".qlty/hooks/**"]

# Radarlint's function naming rule fights the snake_case global functions the
# standard requires; mirrors the source.toml triage, which this repo does not
# consume.
# Mirrors the source.toml triage: S100 fights the required snake_case global
# function names.
[[triage]]
match.rules = ["radarlint-php:php:S100"]
set.ignored = true

# Radarlint's unused private method and unused parameter rules misread trait
# calls, first-class callables and framework callbacks; mirrors the source.toml
# triage.
# S1144 and S1172 misread trait calls, first-class callables and framework
# callbacks.
[[triage]]
match.rules = ["radarlint-php:php:S1144"]
set.ignored = true
Expand Down
Loading
Loading