Raised: $0
0% of monthly goal Help us cross the finish line!
Goal: $12,000
Raised: $0 Goal: $12,000
0% of monthly goal Help us cross the finish line!
Sponsor DDEV

tests add-on registry last commit GitHub Release

DDEV Drupal Code Quality

Overview

This add-on installs a local code quality tool suite for Drupal projects and IDE usage, starting from Drupal.org GitLab CI template defaults. It provides DDEV commands and host shims so developers can run the same checks locally that GitLab CI runs on Drupal.org.

DDEV add-on that installs local code quality tooling based on Drupal.org GitLab CI template defaults (PHPStan, PHPCS, ESLint, Stylelint, Prettier, CSpell) for local CLI and IDE usage.

Tools covered:

Installation

# Install from GitHub
ddev add-on get UltraBob/ddev-drupal-code-quality
ddev restart

# Or, for local development
ddev add-on get /path/to/ddev-drupal-code-quality
ddev restart

There is overlap with other Drupal-focused DDEV add-ons. The key difference is the project type each one is designed for.

Add-on Best for Typical project layout
UltraBob/ddev-drupal-code-quality Full Drupal website projects where your site repo already contains Drupal code and custom code. Existing site/project repo; installs code-quality configs and IDE shims in-place.
ddev/ddev-drupal-contrib Drupal contrib module/theme development where the contrib project is the center of the repo. Contrib project repo with Drupal scaffolded around it (symlink workflow).
justafish/ddev-drupal-core-dev / joachim-n/ddev-drupal-core-dev Drupal core development. Drupal core checkout or core-dev project template.

Practical guidance

Repository structure

During installation, the add-on copies Drupal.org GitLab CI template default config files into the project root. If conflicts are detected, you can choose to back up and replace, skip, or abort. Skipping a config may diverge from the Drupal.org GitLab CI template defaults. The installer will prompt for:

Recommended settings apply these defaults without further prompts: replace conflicts (with backups), install PHP dev tools, install JS deps in the project root, set PHPStan level 3, merge IDE settings, and add dcq-reports/ to .gitignore. Non-interactive runs with no overrides apply the recommended settings automatically.

If PHPStan/PHPCS/PHPCBF binaries are missing, the installer prompts to add drupal/core-dev (or to run ddev composer install if it is already required). It uses ddev composer require --with-all-dependencies to avoid lockfile conflicts.

Usage

For CLI usage, prefer the DDEV commands:

ddev phpstan
ddev phpcs
ddev phpcbf
ddev eslint
ddev stylelint
ddev prettier
ddev cspell
ddev composer-validate
ddev checks

Host shims are installed under .ddev/drupal-code-quality/tooling/bin. These are intended for IDE tool paths or tools that require a local binary path:

./.ddev/drupal-code-quality/tooling/bin/phpstan
./.ddev/drupal-code-quality/tooling/bin/phpcs
./.ddev/drupal-code-quality/tooling/bin/eslint
./.ddev/drupal-code-quality/tooling/bin/stylelint
./.ddev/drupal-code-quality/tooling/bin/prettier
./.ddev/drupal-code-quality/tooling/bin/cspell
./.ddev/drupal-code-quality/tooling/bin/checks

Fix commands

ddev eslint-fix, ddev prettier-fix, and ddev stylelint-fix apply formatting changes directly, matching the behavior of their underlying tools (eslint --fix, prettier --write, stylelint --fix). All three commands support an optional --preview flag that builds a patch preview (saved to dcq-reports/), displays it, and prompts Apply these changes? [y/N] before applying. Use --preview when you want to review changes before committing them.

IDE settings (VS Code/Codium)

Starter settings live in .ddev/drupal-code-quality/ide-settings/vscode. During install, you can choose to merge them into .vscode/settings.json and .vscode/extensions.json, back up and overwrite, or skip and handle them manually.

The template points PHP tooling at .ddev/drupal-code-quality/tooling/bin and JS tooling at local node_modules. Override the paths if you prefer a different location.

Requirements

Configuration notes

Installer environment variables

Maintaining upstream configs

The add-on ships config files sourced from Drupal core and the Drupal GitLab CI templates. A sync script checks for upstream changes:

# Check for upstream config changes (report only)
./scripts/sync-upstream-configs.sh

# Apply changes to local asset files
./scripts/sync-upstream-configs.sh --update

# Override upstream branches
./scripts/sync-upstream-configs.sh --branch-core=11.x --branch-templates=main

After applying updates, run the full test suite to validate configs still work:

DCQ_FULL_TESTS=1 bats --jobs 4 ./tests/test.bats

A weekly GitHub Actions workflow (upstream-config-check.yml) automatically checks for upstream drift and opens an issue when changes are detected.

Uninstall

Removing the add-on cleans up the .ddev payload (commands, shims, assets, manifest, and dcq-install.sh); project-root configs remain in place intentionally. Remove them manually if desired.

Credits

Contributed and maintained by @UltraBob