diff --git a/.github/workflows/dependency-updates.yml b/.github/workflows/dependency-updates.yml index 4c689da..8231f86 100644 --- a/.github/workflows/dependency-updates.yml +++ b/.github/workflows/dependency-updates.yml @@ -40,7 +40,6 @@ jobs: runs-on: ubuntu-latest steps: - - name: Trigger the dependency-updates worker env: GH_TOKEN: ${{ secrets.DEPENDENCIES_DISPATCH_TOKEN }} diff --git a/.github/workflows/quality-gates.yml b/.github/workflows/quality-gates.yml index 4da78eb..5030565 100644 --- a/.github/workflows/quality-gates.yml +++ b/.github/workflows/quality-gates.yml @@ -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 @@ -54,11 +53,7 @@ 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: @@ -66,17 +61,14 @@ jobs: 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 }} @@ -106,11 +98,7 @@ 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: @@ -118,9 +106,7 @@ jobs: 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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8164f91..1fd8904 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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: @@ -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 @@ -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 diff --git a/.npmignore b/.npmignore index 6edad74..56fd1fa 100644 --- a/.npmignore +++ b/.npmignore @@ -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/ @@ -12,7 +9,7 @@ composer.lock vendor/ .php-cs-fixer.cache -# Repo tooling that doesn't belong in the npm tarball. +# Repo tooling. .github/ .idea/ .qlty/ @@ -20,7 +17,7 @@ vendor/ .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/ diff --git a/.qlty/configs/.php-cs-fixer.dist.php b/.qlty/configs/.php-cs-fixer.dist.php index f1ebf3c..12631e5 100644 --- a/.qlty/configs/.php-cs-fixer.dist.php +++ b/.qlty/configs/.php-cs-fixer.dist.php @@ -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', diff --git a/.qlty/configs/autoload.php b/.qlty/configs/autoload.php index 6f5862c..eab5fd7 100644 --- a/.qlty/configs/autoload.php +++ b/.qlty/configs/autoload.php @@ -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\\'; diff --git a/.qlty/configs/phpcs.xml b/.qlty/configs/phpcs.xml index 6434aaf..6e44c22 100644 --- a/.qlty/configs/phpcs.xml +++ b/.qlty/configs/phpcs.xml @@ -2,12 +2,8 @@ autoload.php @@ -17,16 +13,9 @@ ../../SineMacula/Tests */Sniffs/* @@ -38,21 +27,14 @@ */Sniffs/* - + */src/* */Sniffs/* */Tests/* - + */PHPStan/* diff --git a/.qlty/qlty.toml b/.qlty/qlty.toml index 9953137..6d1c058 100644 --- a/.qlty/qlty.toml +++ b/.qlty/qlty.toml @@ -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.*", @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7f229b6..9549210 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,13 +1,13 @@ # Contributing -Contributions are welcome via GitHub pull requests. This guide covers the expectations for working on this package. +Contributions are welcome via GitHub pull requests. ## Requirements - PHP 8.3+ - Composer 2 -- Node.js is only needed when working on the JavaScript, Markdown, YAML or shell configs distributed via npm -- macOS and Qlty CLI are needed when working on the SwiftLint or SwiftFormat policy +- Node.js, for the JavaScript, Markdown, YAML and shell configs distributed via npm +- Qlty CLI, for the policy integration tests; the Swift one also needs macOS ## Getting Started @@ -15,6 +15,7 @@ Contributions are welcome via GitHub pull requests. This guide covers the expect git clone git@github.com:sinemacula/coding-standards.git cd coding-standards composer install +npm ci ``` ## Development Workflow @@ -33,7 +34,7 @@ Branch from `master` using the appropriate prefix: ### Commits -This project uses [Conventional Commits](https://www.conventionalcommits.org/). Prefix your commit messages accordingly: +This project uses [Conventional Commits](https://www.conventionalcommits.org/): ```text feat(phpcs): add sniff for redundant else branches @@ -44,13 +45,14 @@ chore: update qlty configuration ### Code Quality -All code must pass static analysis before submission: +All code must pass these before submission: ```bash -composer check # Static analysis and lint checks via qlty (PHPStan, - # PHP-CS-Fixer, CodeSniffer) -composer format # Format the codebase via qlty -composer smells # Advisory code smells (duplication, complexity) +composer check # Static analysis and lint via qlty +composer format # Format via qlty +composer smells # Code smells (duplication, complexity) via qlty +composer analyse # PHPStan over the sniffs and rules +npm run lint:js # ESLint over the ESLint rules ``` ### Testing @@ -58,40 +60,38 @@ composer smells # Advisory code smells (duplication, complexity) Run the full test suite before submitting: ```bash -composer test # Run the PHPUnit sniff test suite -composer test:coverage # With Clover coverage report (requires Xdebug) -bash scripts/test-swift-policy.sh # Validate Swift exports, formatting and linting on macOS -bash scripts/test-terraform-policy.sh # Validate Terraform exports, formatting and linting +composer test # PHPUnit suite for the sniffs and PHPStan rules +composer test:coverage # With Clover coverage report (requires Xdebug) +composer test:mutation # Infection mutation gate on the diff against origin/master +npm run test:js # Vitest suite for the ESLint rules +bash scripts/test--policy.sh # Qlty consumer integration test for knip, shared, swift, terraform, trivy or zizmor ``` Single test file or method: ```bash vendor/bin/phpunit SineMacula/Tests//SniffTest.php -vendor/bin/phpunit --filter testDetectsViolations SineMacula/Tests//SniffTest.php +vendor/bin/phpunit --filter SineMacula/Tests//SniffTest.php ``` ### Standards -- New sniffs and PHPStan rules ship with tests and maintain 100% line coverage; the package's mutation-testing gate - (`composer test:mutation`) is the enforced floor -- Swift policy changes must pass the isolated Qlty consumer integration test on macOS -- Terraform policy changes must pass the isolated Qlty consumer integration test +- New sniffs and PHPStan rules ship with tests and 100% line coverage; `composer test:mutation` is the enforced floor +- Changes to an exported Qlty policy must pass its consumer integration test (`scripts/test-*-policy.sh`) - Full type hints on all method parameters and return types - PHPDoc on all classes and methods - Sniffs are token-based; PHPStan rules are AST/reflection-based ## Pull Requests -- Keep changes minimal and scoped to a single concern +- Keep changes scoped to a single concern - Do not change static-analysis or formatting configuration without prior discussion - Include tests for new or changed behaviour - Ensure `composer check` and `composer test` pass ## Security -If you discover a security vulnerability, please report it directly to Sine Macula rather than opening a public issue. -See [SECURITY.md](SECURITY.md) for details. +Report vulnerabilities directly to Sine Macula rather than opening a public issue. See [SECURITY.md](SECURITY.md). ## License diff --git a/README.md b/README.md index 636dd42..771e882 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,38 @@ -

Coding Standards

- -
+# Coding Standards [![Latest Stable Version](https://img.shields.io/packagist/v/sinemacula/coding-standards.svg)](https://packagist.org/packages/sinemacula/coding-standards) [![npm Version](https://img.shields.io/npm/v/@sinemacula/coding-standards.svg)](https://www.npmjs.com/package/@sinemacula/coding-standards) -[![PHP Version](https://img.shields.io/packagist/dependency-v/sinemacula/coding-standards/php.svg)](https://packagist.org/packages/sinemacula/coding-standards) [![Build Status](https://github.com/sinemacula/coding-standards/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/sinemacula/coding-standards/actions/workflows/tests.yml) -[![Quality Gates](https://github.com/sinemacula/coding-standards/actions/workflows/quality-gates.yml/badge.svg?branch=master)](https://github.com/sinemacula/coding-standards/actions/workflows/quality-gates.yml) -[![Maintainability](https://qlty.sh/gh/sinemacula/projects/coding-standards/maintainability.svg)](https://qlty.sh/gh/sinemacula/projects/coding-standards) -[![Code Coverage](https://qlty.sh/gh/sinemacula/projects/coding-standards/coverage.svg)](https://qlty.sh/gh/sinemacula/projects/coding-standards) -[![Total Downloads](https://img.shields.io/packagist/dt/sinemacula/coding-standards.svg)](https://packagist.org/packages/sinemacula/coding-standards) [![License](https://img.shields.io/github/license/sinemacula/coding-standards.svg)](LICENSE) -
- -Centralized coding standards, static analysis configurations, and code quality tooling for all Sine Macula repositories. +Shared coding standards, static analysis configs and the Qlty source for Sine Macula repositories. -This package ships config files only - no runtime dependencies. Consuming projects install the tools themselves. +The packages ship configuration only, with no runtime dependencies. Consuming projects install the tools themselves. ## Installation -### Composer (PHP-side: PHP CS Fixer, PHPStan, PHPCS) +### Composer (PHP CS Fixer, PHPCS, PHPStan) ```bash composer require --dev sinemacula/coding-standards ``` -### npm (JS-side: Biome, ESLint) +### npm (Biome, ESLint, tsconfig) ```bash npm install --save-dev @sinemacula/coding-standards ``` The npm package ships only the static configs (`js/`, `markdown/`, `yaml/`, `shell/`, `security/`, `swift/`, -`terraform/`). The PHP autoloaded code lives in the Composer package. - -### Qlty (Swift-side: SwiftLint, SwiftFormat) - -Swift consumers do not need the Composer or npm package. Qlty fetches the shared Swift configs from this repository as -a pinned source and installs the native tools on macOS. +`terraform/`). The PHP code ships in the Composer package. -### Qlty (Terraform-side: Terraform, TFLint) +### Qlty (Swift, Terraform) -Terraform consumers do not need the Composer or npm package either. The Qlty source enables and pins both tools and -supplies the shared TFLint config. +Swift and Terraform consumers need neither package. The Qlty source supplies the shared configs and pins the tools. ## Usage -Each consuming project creates thin wrapper files at its root that reference the shared configs. +Each consuming project adds thin wrapper files at its root that reference the shared configs. ### PHP CS Fixer @@ -64,6 +49,15 @@ return PhpCsFixerConfig::make([ ]); ``` +Pass rule overrides as a second argument: + +```php +return PhpCsFixerConfig::make( + [__DIR__ . '/src', __DIR__ . '/tests'], + ['strict_comparison' => false], +); +``` + Give the qlty plugin this package for its tool sandbox, and do **not** set `package_file` or `package_filters` on it: ```toml @@ -72,37 +66,23 @@ name = "php-cs-fixer" extra_packages = ["sinemacula/coding-standards@1.23.0"] ``` -`extra_packages` installs into the tool sandbox alone, so none of this reaches your own dependency graph. The config -above autoloads `PhpCsFixerConfig` from this package - the only thing `package_file` was doing for this plugin. Give it -an exact version rather than a range. This entry is raised by the shared Renovate preset, which resolves a constraint -to the newest release it already allows, so a caret range is reported as current for the life of the major and -silently stays at the version it was written with. The entry stays in your own file rather than coming from the shared -source, because the source is consumed at a tag and cannot pin the release of the package it is published alongside. +`extra_packages` installs into the tool sandbox only, so it does not touch your dependency graph. Setting +`package_file` makes qlty ignore `extra_packages` silently. Use an exact version: the shared Renovate preset resolves a +caret range to the newest release it already allows, so a range is reported as current and never raised. The entry +lives in your own file because the source, consumed at a tag, cannot pin the package it is published with. The shared source runs qlty on PHP 8.5. A project that analyses on another PHP version sets its own runtime, and qlty -resolves each tool sandbox for it, so PHP 8.3 installs a Symfony that 8.3 can run: +resolves each tool sandbox for it: ```toml [runtimes.enabled] php = "8.3" ``` -Setting `package_file` makes qlty ignore `extra_packages`, silently. `php-codesniffer` and `phpstan` are unaffected and -keep their `package_file`, their sandboxes being where the sniff and rule code comes from. - -You can pass rule overrides as a second argument: - -```php -return PhpCsFixerConfig::make( - [__DIR__ . '/src', __DIR__ . '/tests'], - ['strict_comparison' => false], -); -``` - ### PHPCS -The `SineMacula` coding standard is auto-discovered via the `phpcodesniffer-standard` composer type. Create a -`phpcs.xml` at your project root: +The `SineMacula` standard is auto-discovered through the `phpcodesniffer-standard` Composer type. Create a `phpcs.xml` +at your project root: ```xml @@ -115,8 +95,8 @@ The `SineMacula` coding standard is auto-discovered via the `phpcodesniffer-stan ### PHPStan -The shared PHPStan configs are auto-included via the `extra.phpstan.includes` section in `composer.json`. Your project's -`phpstan.neon` only needs its paths: +The base config is auto-included through `extra.phpstan.includes` in `composer.json`. Your project's `phpstan.neon` +only needs its paths: ```neon parameters: @@ -133,35 +113,29 @@ name = "phpstan" package_file = "composer.json" ``` -Do not set `level`. Analysis runs through qlty, whose phpstan driver passes `--level=9` on the command line, and a -command-line level overrides the config file outright - so a level set here does nothing except mislead whoever reads -it next. +Do not set `level`. qlty's phpstan driver passes `--level=9` on the command line, which overrides the config file. -The base config enables PHPStan's checked-exception analysis: every exception a method can throw must appear in its -`@throws` tag, except a configured set of programming-error and infrastructure exceptions that stay unchecked - the -`LogicException`, `RuntimeException` and `Error` families among them (see `php/phpstan-base.neon` for the full list). -Suppress a deliberate case with `@phpstan-ignore missingType.checkedException`. The PHPCS standard asks for a -`@throws` tag for each exception thrown in a method's body, checked or not, but does not count the tags against those -exceptions, so a tag for an exception a callee propagates is accepted there too; PHPStan's `tooWideThrowType` still +The base config enables checked-exception analysis: every exception a method can throw must appear in its `@throws` +tag, except the programming-error and infrastructure exceptions listed in `php/phpstan-base.neon` (the +`LogicException`, `RuntimeException` and `Error` families among them). Suppress a deliberate case with +`@phpstan-ignore missingType.checkedException`. The PHPCS standard asks for a `@throws` tag for each exception thrown in +a method's body, checked or not, and accepts a tag for an exception a callee propagates; PHPStan's `tooWideThrowType` reports a tag for an exception nothing can throw. -The base config also reports `argument.type`. The shared PHP CS Fixer rules declare `strict_types` and add native types -from docblocks, so passing an argument of the wrong type - a string where an int is expected, null to an internal -function, a `Stringable` where a string is expected - is a `TypeError` at runtime rather than a silent coercion. Fix a -finding by narrowing the value where it is read (`$request->integer('limit')`, `Config::integer(...)`, an explicit null -check) or, where the conversion is intended, with an explicit cast. +`argument.type` is reported. The shared PHP CS Fixer rules declare `strict_types`, so an argument of the wrong type is +a `TypeError` at runtime. Narrow the value where it is read (`$request->integer('limit')`, `Config::integer(...)`, a +null check) or cast it explicitly where the conversion is intended. #### Laravel projects -For Laravel projects, also install -[`sinemacula/coding-standards-laravel`](https://github.com/sinemacula/coding-standards-laravel) and reference its -`SineMaculaLaravel` PHPCS standard (which includes this one) in place of `SineMacula`. It adds the Laravel-specific -sniffs and PHPStan rules; see that package's README for setup. +Also install [`sinemacula/coding-standards-laravel`](https://github.com/sinemacula/coding-standards-laravel) and +reference its `SineMaculaLaravel` PHPCS standard, which includes this one, in place of `SineMacula`. It adds the +Laravel-specific sniffs and PHPStan rules; see that package's README for setup. ### Biome (JavaScript / TypeScript) -Through Qlty, the source stages the shared config at the repository root as `biome.shared.json` while Biome runs. Enable -Biome at 2.2.0 or later in your `.qlty/qlty.toml`: +Through Qlty, the source stages the shared config at the repository root as `biome.shared.json` while Biome runs. +Enable Biome 2.2.0 or later in your `.qlty/qlty.toml`: ```toml [[plugin]] @@ -188,45 +162,40 @@ Then create `.qlty/configs/biome.json`, which extends the shared config by that } ``` -The project config is required: without one, Biome runs on its own defaults. Anything set in it applies over the shared -config, so project-specific `files.includes` and overrides stay there. A project config that still extends -`js/biome.json`, by package name or through the Qlty source mirror, must switch to `./biome.shared.json`. Leave the -Biome plugin definition and its drivers as the source sets them; a `--config-path` or an `exported_config_paths` -override breaks the staging. Biome before 2.2.0 resolves the relative `extends` from the real location of the staged -file and fails to load it. +The project config is required; without one, Biome runs on its own defaults. Settings in it apply over the shared +config, so project-specific `files.includes` and overrides go there. A project config that still extends +`js/biome.json` must switch to `./biome.shared.json`. Leave the Biome plugin definition and its drivers as the source +sets them: a `--config-path` or `exported_config_paths` override breaks the staging. Biome before 2.2.0 resolves the +relative `extends` from the staged file's real location and fails to load it. -Without Qlty, install the npm package and extend `@sinemacula/coding-standards/js/biome.shared.json` from the project's -`biome.json`. The shared config leaves Biome's VCS integration off, because Qlty formats a copy of each file outside the -repository, where no ignore file exists. A project that runs Biome directly can turn it on in its own `biome.json`. +Without Qlty, install the npm package and extend `@sinemacula/coding-standards/js/biome.shared.json` from the +project's `biome.json`. The shared config leaves Biome's VCS integration off, because Qlty formats a copy of each file +outside the repository; a project that runs Biome directly can turn it on in its own `biome.json`. ### ESLint (JavaScript / TypeScript) -ESLint runs *alongside* Biome, not in place of it. Biome keeps owning formatting and the fast syntactic lint; ESLint -adds only the two things Biome structurally cannot express: this package's custom structural rules and the opt-in -type-aware rules (the curated typescript-eslint set plus the type-driven custom rules). Add the linter, the -typescript-eslint tooling, and this package to your dev dependencies: +ESLint runs alongside Biome. Biome owns formatting and the syntactic lint; ESLint adds this package's custom +structural rules and the opt-in type-aware rules. Install: ```bash npm install --save-dev eslint typescript typescript-eslint eslint-plugin-jsdoc yaml-eslint-parser \ @sinemacula/coding-standards ``` -`yaml-eslint-parser` is imported by the base layer for the YAML comment-width block, so it has to resolve even in a -repository with no YAML worth linting; without it the flat config fails to load at all. +`yaml-eslint-parser` is imported by the base layer, so the config fails to load without it, even in a repository with +no YAML. The package exposes three flat-config entry points: -- `@sinemacula/coding-standards/js/eslint` - the base layer of syntax-only custom rules; needs no `tsconfig`, so it - stays cheap and runs anywhere Biome runs. Covers `.ts`/`.js` and, for the comment-width rule alone, `.yml`/`.yaml`. -- `@sinemacula/coding-standards/js/eslint/type-checked` - the opt-in type-aware layer. It includes the base layer and - adds the cross-file / type-driven rules, so it needs a consumer `tsconfig`; use it in place of the base layer where - one exists. -- `@sinemacula/coding-standards/js/eslint/vue` - the opt-in Vue layer for single-file components. Unlike the type-aware - layer it carries no base rules of its own, so spread it *alongside* whichever layer the repository already uses rather - than in place of one. +- `@sinemacula/coding-standards/js/eslint` - the base layer of syntax-only rules. Needs no `tsconfig`. Covers + `.ts`/`.js` and, for the comment-width rule alone, `.yml`/`.yaml`. +- `@sinemacula/coding-standards/js/eslint/type-checked` - the base layer plus the type-aware rules. Needs a + `tsconfig`; use it in place of the base layer where one exists. +- `@sinemacula/coding-standards/js/eslint/vue` - the Vue single-file-component layer. It carries no base rules, so + spread it after whichever layer the repository uses. -Create an `eslint.config.js` (or `.qlty/configs/eslint.config.js` when wired through Qlty) that spreads the layer you -want. Without a `tsconfig`, use the base layer: +Create an `eslint.config.js` (or `.qlty/configs/eslint.config.mjs` when wired through Qlty) that spreads the layer +you want. Without a `tsconfig`: ```js import sm from '@sinemacula/coding-standards/js/eslint'; @@ -234,7 +203,7 @@ import sm from '@sinemacula/coding-standards/js/eslint'; export default [...sm]; ``` -Where a `tsconfig` exists, use the type-aware layer instead (it already carries the base rules): +With a `tsconfig`: ```js import typeChecked from '@sinemacula/coding-standards/js/eslint/type-checked'; @@ -242,7 +211,7 @@ import typeChecked from '@sinemacula/coding-standards/js/eslint/type-checked'; export default [...typeChecked]; ``` -Vue repositories add the Vue toolchain and spread the Vue layer after the layer they already use: +Vue repositories add the Vue toolchain and spread the Vue layer after their existing one: ```bash npm install --save-dev eslint-plugin-vue vue-eslint-parser eslint-plugin-check-file @@ -255,16 +224,12 @@ import vue from '@sinemacula/coding-standards/js/eslint/vue'; export default [...typeChecked, ...vue]; ``` -The Vue layer registers the single-file-component parser (without it `.vue` files are not linted at all), resolves -`