Skip to main content

Coding standards

lint checks the codebase with every linter you kept in the installer, and lint-fix runs the ones that can fix what they find:

make lint # Check coding standards
make lint-fix # Fix what the tools can fix

Checking coding standards

The tools​

lint runs them in the order of this table. Their configuration files sit in the root of the codebase, so you tune a rule in the same place for your machine and for CI.

ToolWhat it checksConfigurationFixes
PHPCSPHP against the Drupal, DrupalPractice, DrevOps and PHPCompatibility standards.phpcs.xmlYes
PHPStanPHP with static analysis, with PHPStan Drupal.phpstan.neonNo
Drupal RectorPHP for deprecated code.rector.phpYes
Twig CS FixerTwig templates..twig-cs-fixer.phpYes
ESLintJavaScript, with Prettier formatting..eslintrc.json, .prettierrc.jsonYes
StylelintCSS..stylelintrc.jsYes
CSpellSpelling across the codebase..cspell.jsonNo

Where they run​

The PHP and JavaScript tools run from the build directory, where the assembled site gives them Drupal core and your dependencies, so build the site before you lint. ESLint and Stylelint check the extension through its symlink in the site, and they only run when the build installed the frontend dependencies (see Frontend dependencies).

CSpell runs from the project root instead, and installs the root package.json dependencies first when node_modules is missing. It checks every file that git doesn't ignore, apart from the paths in the ignorePaths of .cspell.json.

Fixing what they report​

lint-fix runs Rector, PHPCBF (the fixer that comes with PHPCS), Twig CS Fixer, ESLint and Stylelint with their fix options:

make lint-fix

Review the changes before you commit them. When an automatic fix is wrong, adjust the tool's configuration to suppress the issue or change the fix.

Spelling​

CSpell checks prose, code and inline code in Markdown, and skips fenced code blocks. An unknown word fails the check, so a new term needs a home:

  • Add a word the whole project uses to the words of .cspell.json.
  • Add a word only 1 file uses to that file, in a comment such as cspell:ignore laminas written in the file's own comment syntax.

In CI​

CI runs the same tools in its lint jobs, 1 per Drupal major you test. To let a tool fail without failing its job while you work through its findings, set its ignore-failure variable.