Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coding standards v3 #70

Merged
merged 18 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .github/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 32,10 @@ cd ~/fixture || exit 1
# Test that all standards were installed.
INSTALLED=$(./vendor/bin/phpcs -i)
EXPECTED=(
AcquiaDrupalMinimal
AcquiaDrupalStrict
AcquiaDrupalTransitional
AcquiaPHP
AcquiaPHPMinimal
AcquiaPHPStrict
Drupal
DrupalPractice
PHPCompatibility
Expand All @@ -54,13 55,14 @@ if [[ "$FAILURES" ]]; then
fi

# Place a good test file.
printf "<?php\n\n/**\n * @file\n * Good test file.\n */\n" > good.php
printf "<?php\n\n/**\n * @file\n * Good test file.\n */\n\ndeclare(strict_types=1);\n" > good.php

# Test that the SUT's standards can be run.
EXPECTED=(
AcquiaDrupalMinimal
AcquiaDrupalStrict
AcquiaDrupalTransitional
AcquiaPHP
AcquiaPHPMinimal
AcquiaPHPStrict
)
for STANDARD in "${EXPECTED[@]}"; do
./vendor/bin/phpcs -v --standard="$STANDARD" good.php
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 19,17 @@ Acquia Coding Standards for PHP includes a selection of sniffs from the followin

## Rulesets

Rules are split into rulesets according to the project language and framework:
Rules are split into rulesets according to the project *framework* and *audience*:

* [AcquiaPHP](src/Standards/AcquiaPHP/ruleset.xml) contains sniffs applicable to all PHP projects.
* [AcquiaDrupalStrict](src/Standards/AcquiaDrupalStrict/ruleset.xml) incorporates AcquiaPHP and adds all Drupal coding standards and best practices sniffs. Recommended for new Drupal projects and teams familiar with Drupal coding standards.
* [AcquiaDrupalTransitional](src/Standards/AcquiaDrupalTransitional/ruleset.xml) incorporates AcquiaPHP and adds Drupal core's own phpcs configuration, which is less strict than the official standards. Recommended for legacy Drupal codebases or teams new to Drupal coding standards.
* [AcquiaEdge](src/Standards/AcquiaEdge/ruleset.xml) incorporates AcquiaPHP and adds backwards-incompatible sniffs that will be included in AcquiaPHP with the next major release of this package.
* Projects targeting the Drupal community, e.g., Drupal modules, should adopt a *Drupal* ruleset. All others should adopt a (more generalized) *PHP* ruleset.
* Public projects, e.g., open-source Drupal modules, should adopt a *non-strict* ruleset to facilitate external collaboration. All others should adopt a more opinionated *internal* ruleset.

There are four permutations of these guidelines, leading to four rulesets to choose from:

* [AcquiaDrupalMinimal](src/Standards/AcquiaDrupalMinimal/ruleset.xml) is based on the Drupal coding standard and is intended for use on all public Drupal projects.
* [AcquiaDrupalStrict](src/Standards/AcquiaDrupalStrict/ruleset.xml) is based on AcquiaDrupal and adds the more opinionated DrupalPractice standard. It is intended for use on all internal Drupal projects.
* [AcquiaPHPMinimal](src/Standards/AcquiaPHPMinimal/ruleset.xml) is based on PSR-12 and is intended for use on all public non-Drupal projects.
* [AcquiaPHPStrict](src/Standards/AcquiaPHPStrict/ruleset.xml) is based on AcquiaPHP and adds additional, more opinionated standards. It is intended for use on all internal, non-Drupal projects.

## Installation & usage

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 34,7 @@
},
"extra": {
"branch-alias": {
"dev-develop": "2.x-dev"
"dev-develop": "3.x-dev"
}
},
"autoload": {
Expand Down
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions example/phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 7,10 @@

<!-- Uncomment your chosen standard and the filename extensions corresponding to it. -->
<!-- @see https://github.com/acquia/coding-standards-php/issues/18 for background on filename extensions. -->
<!-- <rule ref="AcquiaDrupalMinimal"/><arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,md,yml"/> -->
<rule ref="AcquiaDrupalStrict"/><arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,md,yml"/>
<!-- <rule ref="AcquiaDrupalTransitional"/><arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,md,yml"/> -->
<!-- <rule ref="AcquiaPHP"/><arg name="extensions" value="php,inc,test,css,txt,md,yml"/> -->
<!-- <rule ref="AcquiaEdge"/><arg name="extensions" value="php,inc,test,css,txt,md,yml"/> -->
<!-- <rule ref="AcquiaPHPMinimal"/><arg name="extensions" value="php,inc,test,css,txt,md,yml"/> -->
<!-- <rule ref="AcquiaPHPStrict"/><arg name="extensions" value="php,inc,test,css,txt,md,yml"/> -->

<arg name="colors"/>
<arg name="cache" value=".phpcs-cache"/>
Expand Down
44 changes: 44 additions & 0 deletions src/Standards/AcquiaDrupalMinimal/ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 1,44 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset -->
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../vendor/squizlabs/php_codesniffer/phpcs.xsd"
name="AcquiaDrupalMinimal"
>

<description>Acquia's Drupal coding standards.</description>

<!-- Drupal sniffs -->
<rule ref="Drupal">
<exclude name="Drupal.Files.TxtFileLineLength.TooLong"/>
</rule>

<!-- PHP Compatibility sniffs -->
<!-- The lowest version of PHP supported by both Drupal and Acquia Cloud.
@see https://www.drupal.org/docs/8/system-requirements/php-requirements
@see https://docs.acquia.com/acquia-cloud/arch/tech-platform/
For instructions on overriding this value in your project,
@see https://github.com/acquia/coding-standards-php/pull/37 -->
<config name="testVersion" value="7.4-"/>
<rule ref="PHPCompatibility">
<exclude name="PHPCompatibility.Extensions.RemovedExtensions.famRemoved"/>
</rule>

<!-- Relax rules for automated tests -->
<rule ref="Drupal.Arrays.Array.LongLineDeclaration">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Drupal.Commenting.ClassComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Drupal.Commenting.DocComment.MissingShort">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Drupal.Commenting.FunctionComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Drupal.Commenting.VariableComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>

</ruleset>
38 changes: 1 addition & 37 deletions src/Standards/AcquiaDrupalStrict/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 9,9 @@
<description>Acquia's strict Drupal coding standards.</description>

<!-- Drupal sniffs -->
<rule ref="Drupal">
<exclude name="Drupal.Files.TxtFileLineLength.TooLong"/>
</rule>
<!-- Relax rules for automated tests -->
<rule ref="Drupal.Arrays.Array.LongLineDeclaration">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Drupal.Commenting.ClassComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Drupal.Commenting.DocComment.MissingShort">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Drupal.Commenting.FunctionComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="Drupal.Commenting.VariableComment.Missing">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="AcquiaDrupalMinimal"/>

<!-- Drupal Practice sniffs -->
<rule ref="DrupalPractice"/>

<!-- Acquia PHP sniffs -->
<rule ref="AcquiaPHP"/>

<!-- Drupal should type hint hooks -->
<!-- @see https://www.drupal.org/project/drupal/issues/3229216 -->
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification">
<exclude-pattern>*/modules/custom/*/*\.(module|install)$</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingAnyTypeHint">
<exclude-pattern>*/modules/custom/*/*\.(module|install)$</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint">
<exclude-pattern>*/modules/custom/*/*\.(module|install)$</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification">
<exclude-pattern>*/modules/custom/*/*\.(module|install)$</exclude-pattern>
</rule>

</ruleset>
53 changes: 0 additions & 53 deletions src/Standards/AcquiaDrupalTransitional/ruleset.xml

This file was deleted.

18 changes: 0 additions & 18 deletions src/Standards/AcquiaEdge/ruleset.xml

This file was deleted.

Loading
Loading