Coding Standards
An overview of coding standards that we adopt at Kalamuna across a number of different platforms and languages. This also covers recommending linting strategies to ensure the standards are met.
Drupal
For all code that lives in the Drupal ecosystem, like PHP code that appears within Drupal modules, CSS or Twig code that appears in Drupal themes, we adopt the Drupal coding standards:
Linters
PHP - Coder module
JavaScript - ESLint Drupal Settings
WordPress
For all code that applies to the WordPress ecosystem, we adopt the WordPress Coding Standards.
PHP
For PHP code that lives outside the WordPress or Drupal ecosystem, we adopt PSR-12: Extended Coding Style for coding standards at Kalamuna. PSR-12 is a general coding style guide that has been adopted by many players in the PHP world.
Linters
JavaScript
For JavaScript and Node.js code, we tend to adopt the the XO coding standards with two additions…
Tabs, instead of spaces
Semicolons: None
Linters
npm install xo --save-dev
"scripts": { "xo": "xo --no-semicolon ." },
npm run xo
CSS
For general CSS code, we tend to adopt the Drupal CSS coding standards.
SCSS coding standards: SCSS coding standards
Recommendations
Use
rem
instead ofpx
valuesUse variables for contextual values, rather than magic numbers
Order similar components together
Linters
Â
Common Standards
EditorConfig - When added to your code editor, it will automatically configure newline, tab/space, and whitespace fixes for your project.