2017 © Pedro Peláez
 

project coding-standards

Human Made coding standards

image

humanmade/coding-standards

Human Made coding standards

  • Tuesday, June 19, 2018
  • by rmccue
  • Repository
  • 15 Watchers
  • 47 Stars
  • 25,463 Installations
  • PHP
  • 24 Dependents
  • 0 Suggesters
  • 3 Forks
  • 17 Open issues
  • 29 Versions
  • 17 % Grown

The README.md

Human Made Coding Standards
WordPress coding standards, enhanced for modern development.
Build Status
A Human Made project. Maintained by @rmccue and @mikeselander.

This is a codified version of the Human Made style guide. We include phpcs, ESLint, and stylelint rules., (*1)

Contributing

We welcome contributions to these standards and want to make the experience as seamless as possible. To learn more about contributing, please reference the CONTRIBUTING.md file., (*2)

Setup

Each ruleset is available individually via Composer or NPM. To install the needed ruleset, use one of the following commands:, (*3)

  • PHPCS: composer require --dev humanmade/coding-standards
  • ESLint: npx install-peerdeps --dev @humanmade/eslint-config@latest
  • stylelint: npm install --save-dev stylelint @humanmade/stylelint-config

Using PHPCS

Run the following command to run the standards checks:, (*4)

vendor/bin/phpcs --standard=vendor/humanmade/coding-standards .

We use the DealerDirect phpcodesniffer-composer-installer package to handle installed_paths for PHPCS when first installing the HM ruleset. If you an error such as ERROR: Referenced sniff "WordPress-Core" does not exist, delete the composer.lock file and vendor directories and re-install Composer dependencies., (*5)

The final . here specifies the files you want to test; this is typically the current directory (.), but you can also selectively check files or directories by specifying them instead., (*6)

You can add this to your Travis YAML file as a test:, (*7)

script:
  - phpunit
  - vendor/bin/phpcs --standard=vendor/humanmade/coding-standards .

Excluding Files

This standard includes special support for a .phpcsignore file (in the future, this should be built into phpcs itself). Simply place a .phpcsignore file in your root directory (wherever you're going to run phpcs from)., (*8)

The format of this file is similar to .gitignore and similar files: one pattern per line, comment lines should start with a #, and whitespace-only lines are ignored:, (*9)

# Exclude our tests directory.
tests/

# Exclude any file ending with ".inc"
*\.inc

Note that the patterns should match the PHP_CodeSniffer style: * is translated to .* for convenience, but all other characters work like a regular expression., (*10)

Patterns are relative to the directory that the .phpcsignore file lives in. On load, they are translated to absolute patterns: e.g. */tests/* in /your/dir/.phpcsignore will become /your/dir/.*/tests/.* as a regular expression. This differs from the regular PHP_CodeSniffer practice., (*11)

Advanced/Extending

If you want to add further rules (such as WordPress.com VIP-specific rules) or customize PHPCS defaults, you can create your own custom standard file (e.g. phpcs.ruleset.xml):, (*12)


<ruleset>
    <!-- Files or directories to check -->
    <file>.</file>

    <!-- Path to strip from the front of file paths inside reports (displays shorter paths) -->
    <arg name="basepath" value="." />

    <!-- Set a minimum PHP version for PHPCompatibility -->
    <config name="testVersion" value="7.2-" />

    <!-- Use HM Coding Standards -->
    <rule ref="vendor/humanmade/coding-standards" />

    <!-- Add VIP-specific rules -->
    <rule ref="WordPress-VIP" />
</ruleset>

You can then reference this file when running phpcs:, (*13)

vendor/bin/phpcs --standard=phpcs.ruleset.xml .

Excluding/Disabling Checks

You can also customise the rule to exclude elements if they aren't applicable to the project:, (*14)

<rule ref="vendor/humanmade/coding-standards">
    <!-- Disable short array syntax -->
    <exclude name="HM.Debug.ForceShortArray" />
</rule>

Rules can also be disabled inline. phpcs rules can be disabled with a // @codingStandardsIgnoreLine comment, and ESLint rules can be disabled with a /* eslint disable ... */ comment., (*15)

To find out what these codes are, specify -s when running phpcs, and the code will be output as well. You can specify a full code, or a partial one to disable groups of errors., (*16)

Included Checks

The phpcs standard is based upon the WordPress-VIP standard from WordPress Coding Standards, with customisation and additions to match our style guide., (*17)

Using ESLint

The ESLint package contains an ESLint configuration which you can use to validate your JavaScript code style. While it is possible to run ESLint via phpcs, we recommend you install and use eslint via npm directly or use linter-bot. See the @humanmade/eslint-config package README for more information on configuring ESLint to use the Human Made coding standards., (*18)

Once you have installed the @humanmade/eslint-config npm package, you may simply specify that your own project-level ESLint file extends the humanmade configuration. If you install this globally (npm install -g @humanmade/eslint-config) you can also reference the configuration directly from the command line via eslint -c humanmade ., (*19)

Alternatively, you can create your own configuration and extend these rules:, (*20)

.eslintrc, (*21)

{
  "extends": "@humanmade"
}

Using stylelint

The stylelint package contains a stylelint configuration which you can use to validate your CSS and SCSS code style. We recommend you install and use stylelint via npm directly or use linter-bot. See the @humanmade/stylelint package README for more information on configuring stylelint to use the Human Made coding standards., (*22)

To integrate the Human Made rules into your project, add a .stylelintrc file and extend these rules. You can also add your own rules and overrides for further customization., (*23)

{
  "extends": "@humanmade/stylelint-config",
  "rules": {
    ...
  }
}

The Versions

19/06 2018

dev-stylint-config

dev-stylint-config

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

22/05 2018

dev-master

9999999-dev

Human Made coding standards

  Sources   Download

GPL-2.0 GPL-2.0-or-later

The Requires

 

The Development Requires

22/05 2018

v0.5.0

0.5.0.0

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

02/05 2018

v0.4.2

0.4.2.0

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

19/04 2018

v0.4.1

0.4.1.0

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

19/04 2018

dev-oh-dot-four

dev-oh-dot-four

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

18/04 2018

dev-remove-node-modules

dev-remove-node-modules

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

18/04 2018

dev-allow-unaligned-array-items

dev-allow-unaligned-array-items

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

18/04 2018

dev-fix-function-use-order

dev-fix-function-use-order

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

18/04 2018

v0.4.0

0.4.0.0

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

18/04 2018

dev-add-examples-and-update-rules

dev-add-examples-and-update-rules

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

18/04 2018

dev-fix-tests

dev-fix-tests

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

18/04 2018

dev-allow-without-semicolon

dev-allow-without-semicolon

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

18/04 2018

dev-allow-filesystem

dev-allow-filesystem

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

18/04 2018

dev-allow-filesyste-functions

dev-allow-filesyste-functions

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

02/04 2018

dev-unused-use-statement

dev-unused-use-statement

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

16/03 2018

dev-add-object-property-newline-rule

dev-add-object-property-newline-rule

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

28/02 2018

dev-spaces-in-jsx-curly-braces

dev-spaces-in-jsx-curly-braces

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

16/02 2018

dev-upgrade-wpcs

dev-upgrade-wpcs

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

30/01 2018

dev-php-only

dev-php-only

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

19/01 2018

0.3.0

0.3.0.0

Human Made coding standards

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

22/11 2017

dev-phpcs-tests

dev-phpcs-tests

Human Made coding standards

  Sources   Download

GPL-2.0

The Requires

 

The Development Requires

11/09 2017

dev-update-wpcs

dev-update-wpcs

Human Made coding standards

  Sources   Download

GPL-2.0

The Requires

 

31/08 2017

0.2.2

0.2.2.0

Human Made coding standards

  Sources   Download

GPL-2.0

The Requires

 

09/03 2017

dev-switchcase

dev-switchcase

Human Made coding standards

  Sources   Download

GPL-2.0

The Requires

 

26/01 2017

dev-always-spaces-in-arrays

dev-always-spaces-in-arrays

Human Made coding standards

  Sources   Download

GPL-2.0

The Requires

 

08/12 2016

0.2.1

0.2.1.0

Human Made coding standards

  Sources   Download

GPL-2.0

The Requires

 

08/12 2016

0.2.0

0.2.0.0

Human Made coding standards

  Sources   Download

GPL-2.0

The Requires

 

08/12 2016

0.1.0

0.1.0.0

Human Made coding standards

  Sources   Download

GPL-2.0

The Requires