Code quality
This module uses several code quality tools to maintain standards. Run these commands from the module root directory.
Running all checks at once
Option 1: Composer (recommended)
composer lint
Individual checks:
composer lint:cspell # Spell checking only
composer lint:phpcs # PHP code style only
composer lint:phpstan # Static analysis only
composer lint:eslint # JavaScript linting only
composer lint:stylelint # CSS linting only
Option 2: Shell script
./lint.sh
The script provides colored output and a summary of results. Exits with code 1 if any check fails.
Individual tools
Spell checking (cspell)
npx cspell "**/*.{php,js,yml,md,twig,css}" --config .cspell.json
PHP Code Sniffer (phpcs)
Scans the whole module: src/, tests/, css/, config/, docs/,
modules/ (submodules), and supported root files (for example *.module,
*.install, *.post_update.php, *.yml). Excludes .gitlab/ templates.
Markdown (*.md) is not scanned by phpcs (matches CI); use cspell for prose.
Comment and documentation lines over 80 characters are reported as warnings
via the Drupal standard (Drupal.Files.LineLength) in scanned file types.
Not scanned by phpcs (other tools or not applicable): *.md, composer.json,
lint.sh, phpstan*.neon, and other tool config dotfiles.
# From Drupal root
phpcs --standard=Drupal,DrupalPractice \
--extensions=php,module,inc,install,test,profile,theme,css,info,txt,yml \
--ignore='*/.gitlab/*' \
web/modules/contrib/ai_context
PHPStan
# From Drupal root
vendor/bin/phpstan analyze web/modules/contrib/ai_context
# Or from module directory with custom config
phpstan analyze --configuration=phpstan.neon.dist
ESLint
npx eslint js/**/*.js
Stylelint
Uses Drupal core's stylelint config and binary (property order, prettier formatting) so local results match the GitLab CI pipeline. Requires core Node dependencies once per checkout:
cd ../../../core && corepack enable && yarn install
../../../core/node_modules/.bin/stylelint \
--config .stylelint-local.json \
--config-basedir ../../../core \
"css/**/*.css"
Auto-fix where supported:
../../../core/node_modules/.bin/stylelint \
--config .stylelint-local.json \
--config-basedir ../../../core \
--fix css/ai_context_item.css
Prerequisites
- PHP CodeSniffer:
composer require --dev drupal/coder - PHPStan: included with Drupal 11 core dev dependencies
- Node tools (cspell, eslint, stylelint): installed via npm/npx (no installation needed with npx)
- Stylelint (pipeline parity):
yarn installin Drupal core (web/core)
Notes
Running the full lint on the entire module may show pre-existing warnings in other files. To check only specific files you are working on, use the individual tool commands with specific file paths.