Skip to content
Closed
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
25 changes: 25 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://developer.wordpress.org/coding-standards/wordpress-coding-standards/

# This is largely aligned with the .editorconfig in wordpress-develop and Gutenberg.
# Matches: https://github.com/WordPress/wordpress-develop/blob/bff31ca3a823e89127a7d3c2d953eda3d9b2193e/.editorconfig#L7-L21
# See also: https://github.com/WordPress/gutenberg/blob/trunk/.editorconfig

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
37 changes: 37 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!-- Thanks for contributing to the Accessibility Lab plugin! Please follow the Contributing Guidelines:
https://github.com/WordPress/accessibility-lab/blob/main/CONTRIBUTING.md -->

## What?
<!-- Link this PR to its associated issue with an appropriate keyword: Closes, See, Follow up to, etc. -->
Closes <!-- #ISSUE-NUMBER or URL -->

<!-- In a few words, what is the PR actually doing? -->

## Why?
<!-- Why is this PR necessary? What problem is it solving? Reference any existing previous issue(s) or PR(s), but please add a short summary here, too -->

## How?
<!-- How is your PR addressing the issue at hand? What are the implementation details? -->

## Testing Instructions
<!-- Please provide steps on how to test or validate that the change in this PR works as described. -->

## Screenshots or screencast
<!-- If this PR includes UI changes, please provide screenshots or a screen recording for clarity. -->
<!-- This section can be removed if not applicable. -->

| Before | After |
| ------ | ----- |
| | |

## Changelog Entry
<!--
Please include a summary for this PR, noting whether this is something being Added / Changed / Deprecated / Removed / Fixed / or Security related. You can replace the sample entries after this comment block with the single changelog entry line for this PR. -->

> Added - New feature.
> Changed - Existing functionality.
> Deprecated - Soon-to-be removed feature.
> Removed - Feature.
> Fixed - Bug fix.
> Security - Vulnerability.
> Developer - Development related updates.
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
php:
name: PHP (${{ matrix.php-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3', '8.4']
steps:
- uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer
coverage: none

- name: Install Composer dependencies
run: composer install --no-progress --no-interaction --prefer-dist

- name: PHPCS
run: composer lint

- name: PHPStan
run: composer phpstan

js:
name: JS & build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm

- name: Install dependencies
run: npm ci

- name: Lint JS
run: npm run lint:js

- name: Lint CSS
run: npm run lint:css

- name: Build
run: npm run build
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Build artefacts (rebuilt via `npm run build`)
# Build artefacts (rebuilt via `npm run build` / `npm run plugin-zip`)
/build/
/vendor/
*.zip

# Dependencies
/node_modules/
Expand Down
35 changes: 35 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env sh

# `printf` rather than `echo`: POSIX sh (dash, as on Linux/CI) does not
# interpret \033 or \n in echo, so escapes would print literally.
red() {
printf '\033[0;31m%s\033[0m\n' "$1"
}

rule() {
printf '\033[0;31m%s\033[0m\n' '--------------------------------------------------------------------------------'
}

# 1. Lint only staged files (CSS/JS/PHP) — fast, scoped to what's changing.
printf '\n'
red 'Linting staged files...'
npx lint-staged --no-stash || {
printf '\n'
rule
red 'Linting failed. Commit aborted.'
rule
printf '\n'
exit 1
}

# 2. PHPStan runs project-wide — it needs whole-codebase context, so it can't
# be scoped to staged files like the linters above.
red 'Running PHPStan...'
composer phpstan || {
printf '\n'
rule
red 'PHPStan failed. Commit aborted.'
rule
printf '\n'
exit 1
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
24.19.0
3 changes: 3 additions & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/
node_modules/
vendor/
6 changes: 6 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": ["@wordpress/stylelint-config/scss"],
"rules": {
"selector-class-pattern": null
}
}
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Changelog

All notable changes to this project will be documented in this file, per [the Keep a Changelog standard](http://keepachangelog.com/), and will adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] - TBD

### Added

- Linting and static analysis: ESLint, Stylelint, PHP_CodeSniffer (WordPress Coding Standards) and PHPStan at level 8, all runnable through `npm run lint` and `npm run format`.
- Continuous integration via GitHub Actions, running PHPCS and PHPStan against PHP 8.1 through 8.4 alongside JavaScript and CSS linting and a production build.
- A pre-commit hook that lints staged files and runs PHPStan across the project, so failures surface before review.
- Scripts for the bundled `wp-env` environment (`env:start`, `env:stop`, `env:clean`), giving contributors a disposable WordPress install with debugging enabled.
- Contributor documentation: contributing guidelines, a pull request template, and this changelog.
- A pinned Node version (`.nvmrc`) and shared editor settings (`.editorconfig`).
- A declared minimum PHP version of 8.1 in `composer.json`.

### Changed

- Reformatted the JavaScript, TypeScript, SCSS and PHP source to the WordPress Coding Standards, and documented every PHP class, method and property.
- Expanded the README with a full script reference, the Node version requirement, and instructions for running the plugin locally.
- Narrowed the `credits()` return type on modules that always supply attribution.

### Fixed

- The Media Library view-preference handler now sanitises the submitted value before use.
- Uninstalling no longer assigns to WordPress's global `$plugin` variable.
- Corrected CSS selector specificity ordering in the Media Library view options, so the thumbnail density rules apply as intended.
- Replaced an invalid design-system colour token in the validation settings table with the intended value, restoring the muted styling of the description text.
- Removed an unused registry dependency from the settings page, along with several unused variables and imports across the editor scripts.
- Corrected the supported PHP range in CI, which previously claimed 8.0 despite the plugin requiring 8.1.
- Committed the dependency lock files, without which continuous integration could not install dependencies.
155 changes: 155 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Contributing Guidelines

Welcome to the Accessibility Lab plugin! Here you'll find information on how to get started contributing to the plugin.

## Getting Started

### Prerequisites

- Composer
- Node.js — the version is pinned in `.nvmrc`; the toolchain requires 22.12 or newer
- Docker, only if you plan to use the bundled `wp-env` environment

### Local development setup

1. **Clone the repository:**

The repository *is* the plugin directory, so the simplest setup is to clone it
straight into the `wp-content/plugins/` of a WordPress install you already have
(WordPress Studio, Local, or any other local server):

```bash
cd path/to/wp-content/plugins
git clone https://github.com/WordPress/accessibility-lab.git accessibility-lab
cd accessibility-lab
```

2. **Install dependencies and build assets:**

If you use `nvm`, run `nvm use` first to switch to the pinned Node version.
On older Node, `npm run lint:js` fails with `ERR_REQUIRE_ESM`.

```bash
nvm use
composer install && npm i && npm run build
```

3. **Activate the plugin:**

Through WordPress admin or via WP-CLI:

```bash
wp plugin activate accessibility-lab
```

Alternatively, `npm run env:start` spins up a throwaway Docker-based WordPress
with the plugin mounted and debugging enabled. See the
[README](README.md) for the full list of scripts.

### Quality checks

Before submitting a pull request:

```bash
# Lint everything — JS, CSS, PHPCS, PHPStan
npm run lint

# Auto-fix what can be fixed
npm run format
```

The pre-commit hook already runs `lint-staged` plus a project-wide PHPStan, so
a commit that goes through has passed most of this. CI runs the same checks
against PHP 8.1–8.4.

There is no automated test suite yet. Please describe how you verified your
change in the pull request's testing instructions.

### Coding standards

All code must follow the [WordPress Coding Standards](https://developer.wordpress.org/coding-standards/). This ensures consistency across the WordPress ecosystem and makes the codebase maintainable.

### PHP compatibility

The minimum supported PHP version is **8.1**. The codebase uses `readonly`
properties, constructor promotion, and enum-style class constants accordingly.

### WordPress compatibility

The plugin requires **WordPress 6.5** or higher. Ensure all WordPress functions
and hooks used are available in that version.

### Naming conventions

The following conventions must be followed for consistency and autoloading:

- Namespaces follow the pattern `AccessibilityLab\{Component}`.
- Autoloading is PSR-4-ish (see `includes/autoload.php`): **the file name matches
the class name** — `Bucket.php` contains `Bucket`. This project does *not* use
WordPress core's `class-bucket.php` convention, which is why
`WordPress.Files.FileName` is excluded in `phpcs.xml.dist`.
- Classes use WordPress naming conventions with underscores where useful for
readability (e.g. `Settings_Page`, `Abstract_Module`).
- Modules extend `AccessibilityLab\Abstracts\Abstract_Module` and live under
`includes/Modules/Features/` or `includes/Modules/Experiments/`.

### Documentation standards

Every class, method, and property needs a docblock with a summary line — PHPCS
runs the `WordPress-Docs` ruleset and the codebase currently passes clean. Use
explicit type hints on parameters and return values, and document array shapes
with generics (e.g. `array<string, Abstract_Module>`) so PHPStan can check them
at level 8.

```php
/**
* Holds every registered module and their enabled/disabled state.
*/
final class Registry {

/**
* Registered modules, keyed by id.
*
* @var array<string, Abstract_Module>
*/
private array $modules = array();

/**
* Register a module. No-ops on duplicate id or invalid bucket/track.
*
* @param Abstract_Module $module Module instance to register.
*/
public function register( Abstract_Module $module ): void {
// Implementation
}
}
```

### Internationalization

All user-facing strings must be translatable using WordPress i18n functions,
with the `accessibility-lab` text domain:

```php
// Good
__( 'Hello World', 'accessibility-lab' );
esc_html__( 'Hello World', 'accessibility-lab' );

// Bad
echo 'Hello World';
```

Strings with placeholders need a `translators:` comment immediately above the
`__()` call.

## Guidelines

- As with all WordPress projects, we want to ensure a welcoming environment for everyone. With that in mind, all contributors are expected to follow our [Code of Conduct](https://make.wordpress.org/handbook/community-code-of-conduct/).
- All WordPress projects are licensed under the GPLv2+, and all contributions to the Accessibility Lab plugin will be released under the GPLv2+ license. You maintain copyright over any contribution you make, and by submitting a pull request, you are agreeing to release that contribution under the GPLv2+ license.

---

## Additional resources

- [README](README.md) — architecture, the Feature/Experiment and Core-track/Practical model, registering your own modules and validation checks, and the full script reference
- [CHANGELOG](CHANGELOG.md) — release history
Loading
Loading