Skip to content

Coding Standards & Related Development Tools

Greg Clapp edited this page Jun 6, 2018 · 2 revisions

In order to keep our custom code consistent and maintainable, developers on the POWR project should adhere to standardized Drupal/php coding conventions as described in detail on Drupal.org. Developers are encouraged to read and follow these well-established conventions.

For the time being, individual developers are responsible for writing code that follows these standards and employing development tools that aid that goal, and standards will be enforced though code reviews done as part of pull requests.

Standards documentation

Recommended development tools

Though not mandated, developers are encouraged to use VS Code as their primary IDE. The extensions listed here are geared towards VS Code users, but equivalent extensions may be available for other editor tools.

  • Debugger for Chrome (msjsdiag.debugger-for-chrome) is a Microsoft official extension that adds JavaScript debugging support.
  • PHP Debug (felixfbecker.php-debug) provides launch configuration support for XDebug. Requires XDebug.
  • PHP DocBlocker (neilbrayfield.php-docblocker) provides auto-complete for PHP docblocks.
  • PHP Intelephense (bmewburn.vscode-intelephense-client) provides support for PHP intellisense that supports any PHP file (module, inc, etc...), which is not supported by the
  • PHP IntelliSense (felixfbrecker.php-intellisense) extension. phpcs (ikappas.phpcs) provides integration for PHP CodeSniffer (phpcs) code linting.
  • Composer (ikappas.composer) provides an interface to Composer dependency manager for PHP. It also provides schema validation for composer.json configuration files.
  • Twig Language 2 (mblode.twig-language-2) provides snippets, syntax highlighting, hover, and formatting for the Twig file format.
  • PHP_CodeSniffer is a library that tokenises PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.

Base VS Code editor settings

The following settings are related to basic formatting for PHP, CSS, JavaScript or HTML files. These settings can be used as-is in either User or Workspace settings. If you use Visual Studio Code for other projects that use a different line length, tab/space size, then it would be better to add these settings to your Drupal site, module, theme or installer Workspace.

{
  "css.validate": true,
  "diffEditor.ignoreTrimWhitespace": false,
  "editor.tabSize": 2,
  "editor.autoIndent": true,
  "editor.insertSpaces": true,
  "editor.formatOnPaste": true,
  "editor.formatOnSave": false,
  "editor.wordWrapColumn": 80,
  "editor.wordWrap": "off",
  "editor.detectIndentation": true,
  "files.associations": {
    "*.inc": "php",
    "*.module": "php",
    "*.install": "php",
    "*.theme": "php",
    "*.tpl.php": "php",
    "*.test": "php",
    "*.php": "php"
  },
  "html.format.enable": true,
  "html.format.wrapLineLength": 80
}

Visit Configuring Visual Studio Code for the full list of recommended toos from Drupal.org, as well as recommended editor settings for each extension.