diff --git a/.editorconfig b/.editorconfig index 66c4980..43008e1 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,8 +10,7 @@ indent_style = tab insert_final_newline = true trim_trailing_whitespace = true -# Two-space indent for config and data files. -[*.{yml,yaml,json,md}] +[*.{yml,yaml,md}] indent_size = 2 indent_style = space diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 7b9e5b9..423b43b 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -21,12 +21,13 @@ npm run wp-env start ## Before you open a PR -Run all four checks locally — all of them must exit `0`: +Run all five checks locally — all of them must exit `0`: ```bash composer lint composer analyse npm run lint:js +npm run format:check npm run test:php ``` @@ -37,6 +38,7 @@ composer lint # PHPCS against the rtCampWP standard (rtcamp/wp-phpcs) composer lint:fix # auto-fix fixable violations composer analyse # PHPStan static analysis npm run lint:js # ESLint (@rtcamp/eslint-config) on bin/ +npm run format npm run test:php # PHPUnit in the wp-env test container ``` @@ -46,7 +48,7 @@ Follow TDD: add a failing test under `tests/phpunit/Integration/` (which mirrors ## Pull request checklist -- [ ] `composer lint`, `composer analyse`, `npm run lint:js`, and `npm run test:php` pass. +- [ ] `composer lint`, `composer analyse`, `npm run lint:js`, `npm run format:check`, and `npm run test:php` pass. - [ ] New/changed behavior is covered by tests. - [ ] Any change to `inc/Contracts/` is flagged as breaking in the PR description. - [ ] Contract changes are reflected in `ai/primitives-php.instructions.md`. diff --git a/.github/workflows/test-measure.yml b/.github/workflows/test-measure.yml index 73f3c30..e112f47 100644 --- a/.github/workflows/test-measure.yml +++ b/.github/workflows/test-measure.yml @@ -8,108 +8,34 @@ on: types: - opened - synchronize + - reopened - ready_for_review permissions: contents: read concurrency: - group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.ref }} - cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: lint-php: - name: 'Lint PHP' - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - - name: Setup PHP - uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2.40.0 - with: - php-version: '8.2' - coverage: none - tools: cs2pr - - - name: Get Composer Cache Directory - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" - - - name: Configure Composer cache - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - - name: Install Composer dependencies - run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction - - - name: Validate composer.json - run: composer --no-interaction validate --no-check-all - - - name: Detect coding standard violations (PHPCS) - run: vendor/bin/phpcs -q --report=checkstyle --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 | cs2pr --graceful-warnings - - analyse-php: - name: 'PHPStan Analysis' - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - - name: Setup PHP - uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2.40.0 - with: - php-version: '8.2' - coverage: none - - - name: Get Composer Cache Directory - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" - - - name: Configure Composer cache - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - - name: Install Composer dependencies - run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction - - - name: Run PHPStan - run: composer analyse + name: Lint PHP + uses: rtCamp/wp-shared-workflows/.github/workflows/ci-lint-php.yml@6a4d945cc07377a6ce02ae4831a9817fe629d5b1 # v1.1.1 + with: + php-version: '8.2' + enable-phpstan: true + phpstan-command: composer analyse lint-js: - name: 'Lint JS' - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false - - - name: Setup Node - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - with: - node-version-file: '.nvmrc' - cache: 'npm' - - - name: Install Node dependencies - run: npm ci - env: - CI: true - - - name: Run ESLint - run: npm run lint:js + name: Lint JS and check formatting + uses: rtCamp/wp-shared-workflows/.github/workflows/ci-lint-js.yml@6a4d945cc07377a6ce02ae4831a9817fe629d5b1 # v1.1.1 + with: + lint-command: >- + status=0; + npm run lint:js || status=1; + npm run format:check || status=1; + exit $status unit-test-php: name: 'PHP ${{ matrix.php }} / WP ${{ matrix.wp }}' diff --git a/docs/maintainers.md b/docs/maintainers.md index 10d07db..df687be 100644 --- a/docs/maintainers.md +++ b/docs/maintainers.md @@ -27,6 +27,7 @@ Run these before opening a pull request: composer lint composer analyse npm run lint:js +npm run format:check npm run test:php ``` @@ -58,7 +59,7 @@ npm run wp-env stop - Add reusable test-only classes under `tests/phpunit/Tests/Fixtures/`. - Keep tests order-independent; PHPUnit runs them in random order. -CI runs PHPCS, PHPStan, ESLint, and a PHP × WordPress integration-test matrix. The local commands above are the closest single-environment equivalent. +CI runs PHPCS, PHPStan, ESLint, a Prettier formatting check, and a PHP × WordPress integration-test matrix. The local commands above are the closest single-environment equivalent. ## Changing the library diff --git a/package-lock.json b/package-lock.json index beefe5d..74cf059 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,8 @@ "@rtcamp/eslint-config": "2.0.0", "@wordpress/env": "12.2.0", "@wordpress/prettier-config": "5.2.0", - "@wordpress/scripts": "37.2.0" + "@wordpress/scripts": "37.2.0", + "prettier": "npm:wp-prettier@3.9.6" }, "engines": { "node": "^24.22.1 || >=26.12.1" diff --git a/package.json b/package.json index 5adaa35..c2c88c1 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "scripts": { "format": "wp-scripts format . '**/*.md'", + "format:check": "prettier --check --ignore-path .prettierignore '**/*.{cjs,cts,js,json,jsx,mjs,mts,ts,tsx,yml,yaml,md}'", "lint:js": "wp-scripts lint-js", "lint:js:fix": "wp-scripts lint-js --fix", "lint:php": "composer run-script lint", @@ -23,7 +24,8 @@ "@rtcamp/eslint-config": "2.0.0", "@wordpress/env": "12.2.0", "@wordpress/prettier-config": "5.2.0", - "@wordpress/scripts": "37.2.0" + "@wordpress/scripts": "37.2.0", + "prettier": "npm:wp-prettier@3.9.6" }, "overrides": { "@wp-playground/storage": { @@ -32,6 +34,6 @@ "express": { "qs": "6.16.2" }, - "prettier": "npm:wp-prettier@^3" + "prettier": "$prettier" } }