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

Fix #18: Correct extensions not scanned, allow extensions to be overridden #27

Merged
merged 2 commits into from
Oct 11, 2021
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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,24 @@ Rules are split into rulesets according to the project language and framework:
1. Check code for standards compliance:

```bash
./vendor/bin/phpcs --standard=AcquiaDrupalStrict path/to/code
./vendor/bin/phpcs --standard=AcquiaDrupalStrict --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml path/to/code
```

Automatically fix any standards violations possible:

```bash
./vendor/bin/phpcbf --standard=AcquiaDrupalStrict path/to/code
./vendor/bin/phpcbf --standard=AcquiaDrupalStrict --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml path/to/code
```

The `--extensions` argument must match the chosen code standard. For AcquiaPHP, use `--extensions=php,inc,test,css,txt,md,yml`.

1. Optionally create a [default configuration file](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file) for your project so you don't have to provide the command-line arguments every time (i.e., below). Here's a working example: [`example/phpcs.xml.dist`](example/phpcs.xml.dist).

```bash
./vendor/bin/phpcs
```

Modify `phpcs.xml.dist` to suit your project, especially to set the preferred code standard and matching extensions.

1. Optionally add code checking to your [Git pre-commit hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) to prevent committing code with violations. Since client-side Git hooks are not copied when a repository is cloned, you might like to use an automated solution like [`BrainMaestro/composer-git-hooks`](https://packagist.org/packages/BrainMaestro/composer-git-hooks) to manage them, for example: [`example/composer.json`](example/composer.json).

Expand Down
10 changes: 5 additions & 5 deletions example/phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

<description>An example PHP CodeSniffer configuration.</description>

<!-- Set extensions to scan (taken from Coder 8.3.6). -->
<!-- @see https://git.drupalcode.org/project/coder/blob/8.3.6/coder_sniffer/Drupal/ruleset.xml#L8 -->
<arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,md,yml"/>
<!-- 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="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"/> -->

<arg name="colors"/>
<arg name="cache" value=".phpcs-cache"/>
Expand All @@ -20,6 +22,4 @@
<!-- @see https://github.com/squizlabs/PHP_CodeSniffer/issues/981 -->
<exclude-pattern>vendor/*</exclude-pattern>

<rule ref="AcquiaDrupalStrict"/>

</ruleset>
2 changes: 0 additions & 2 deletions src/Standards/AcquiaDrupalStrict/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

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

<arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,md,yml"/>

<!-- Drupal sniffs -->
<rule ref="Drupal">
<exclude name="Drupal.Files.TxtFileLineLength.TooLong"/>
Expand Down
2 changes: 0 additions & 2 deletions src/Standards/AcquiaDrupalTransitional/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

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

<arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,md,yml"/>

<!-- Drupal sniffs -->
<rule ref="Drupal">
<exclude name="Drupal.Files.TxtFileLineLength.TooLong"/>
Expand Down
2 changes: 0 additions & 2 deletions src/Standards/AcquiaPHP/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

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

<arg name="extensions" value="php,inc,test,css,txt,md,yml"/>

<!-- Drupal sniffs -->
<rule ref="Drupal.WhiteSpace.ScopeIndent"/>

Expand Down