digitoimistodude/dude-coding-standards

Dude Coding Standards (DCS) for WordPress theme and plugin development

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Language:JavaScript

Type:phpcodesniffer-standard

pkg:composer/digitoimistodude/dude-coding-standards

1.0.0 2025-12-05 17:34 UTC

This package is auto-updated.

Last update: 2025-12-08 15:36:09 UTC


README

Note

Please note: The Dude Coding Standard is a work in progress. We're in the process of replacing WordPress-Core standard in dudestack with our own DSC standard, the one you are currently looking at (internal reference: DEV-624). This PHPCS standard is used by Dude staff and may not provide additional value for external developers.

version WordPress PHP GitHub Actions Workflow Status

PHP_CodeSniffer and Stylelint rules for WordPress theme and plugin development at Digitoimisto Dude Oy.

This repository contains:

  • PHPCS standard (DCS) - via Composer
  • Stylelint config - via npm

PHPCS Installation

composer require --dev digitoimistodude/dude-coding-standards

The standard will be automatically registered with PHP_CodeSniffer via the Composer installer plugin.

Usage

In phpcs.xml

Create a phpcs.xml in your project root:

<?xml version="1.0"?>
<ruleset>
  <rule ref="DCS"/>
</ruleset>

Command line

phpcs --standard=DCS path/to/your/code

With custom configuration

You can override rules in your project's phpcs.xml:

<?xml version="1.0"?>
<ruleset>
  <rule ref="DCS">
    <!-- Exclude specific rules if needed -->
    <exclude name="DCS.PHP.ForbiddenFunctions"/>
  </rule>

  <!-- Add project-specific patterns to exclude -->
  <exclude-pattern>*/some-legacy-folder/*</exclude-pattern>
</ruleset>

What's included

DCS is based on WordPress Coding Standards with Dude-specific customizations:

Code style

  • 2-space indentation instead of tabs
  • Short array syntax [] allowed (instead of array())
  • Relaxed commenting requirements
  • Flexible function formatting with spaces
  • ...and more in the future

Security

All WordPress security sniffs are enabled:

  • WordPress.Security.NonceVerification
  • WordPress.Security.ValidatedSanitizedInput
  • WordPress.Security.EscapeOutput
  • And more...

PHP compatibility

Checks code compatibility with > PHP 8.3 using PHPCompatibilityWP.

Development functions

error_log() and print_r() are allowed but flagged as warnings to remind you to review before deployment.

Excluded rules

The following WordPress rules are excluded for Dude's workflow:

  • Yoda conditions (WordPress.PHP.YodaConditions)
  • Strict file naming (WordPress.Files.FileName)
  • Tab indentation (Generic.WhiteSpace.DisallowSpaceIndent)
  • Long array syntax requirement (Universal.Arrays.DisallowShortArraySyntax)
  • See DCS/ruleset.xml for the full list

Adding forbidden functions

To add more forbidden functions to your project, create a custom sniff or override in your phpcs.xml:

<rule ref="Generic.PHP.ForbiddenFunctions">
  <properties>
    <property name="forbiddenFunctions" type="array">
      <element key="my_deprecated_function" value="new_function"/>
    </property>
  </properties>
</rule>

Development and local testing

If you want to test DCS locally before the package is published, first install dependencies in dude-coding-standards:

cd /path/to/dude-coding-standards
composer install

Then add path repository to your project's composer.json:

{
  "repositories": [
    {
      "type": "path",
      "url": "../dude-coding-standards"
    }
  ],
  "require-dev": {
    "digitoimistodude/dude-coding-standards": "@dev"
  }
}

Run composer update in your project:

composer update digitoimistodude/dude-coding-standards

Note: Path repositories create symlinks, so any changes you make to dude-coding-standards are instantly available in your test project without reinstalling.

Check that DCS is available:

./vendor/bin/phpcs -i
# Should show: ... DCS ...

Create phpcs.xml in your project, can be as simple as this:

<?xml version="1.0"?>
<ruleset>
  <rule ref="DCS"/>
</ruleset>

Run phpcs:

# From the dev project
./vendor/bin/phpcs --standard=phpcs.xml path/to/your/code

# By using the global version
phpcs --standard=phpcs.xml path/to/your/code

You can also run phpcs directly from dude-coding-standards against your project:

cd /path/to/dude-coding-standards

# From the dev project
./vendor/bin/phpcs --standard=DCS /path/to/your/project/

# By using the global version
phpcs --standard=DCS /path/to/your/project/

Check the standard itself for development:

phpcs --standard=phpcs.xml DCS/

Stylelint Config

Installation

npm install --save-dev @digitoimistodude/stylelint-config stylelint

Usage

Create .stylelintrc in your project root:

{
  "extends": "@digitoimistodude/stylelint-config"
}

Overriding rules

{
  "extends": "@digitoimistodude/stylelint-config",
  "rules": {
    "declaration-no-important": null
  }
}

See stylelint.config.js for all rules.

References