Skip to content

Commit

Permalink
238 phpcs scaffold (#562)
Browse files Browse the repository at this point in the history
* #238: adjust phpcs scaffold to use dist extension.

---------

Co-authored-by: Sally Young <[email protected]>
  • Loading branch information
geekygnr and justafish authored May 22, 2024
1 parent 02b9a89 commit 0d15f38
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/TestStatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- name: Verify files were created
run: |
test -f phpcs.xml
test -f phpcs.xml.dist
- name: Fix settings.php
run: |
Expand Down
35 changes: 12 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ for a Drupal site, including:
- [Setup](#setup-1)
- [Testing](#testing)
- [Static Tests](#static-tests)
- [Excluding Files from PHP_CodeSniffer](#excluding-files-from-php_codesniffer)
- [Altering PHP_CodeSniffer Configuration](#altering-php_codesniffer-configuration)
- [Functional Tests](#functional-tests)
- [PHPUnit](#phpunit)
- [Nightwatch](#nightwatch)
Expand All @@ -41,6 +41,7 @@ for a Drupal site, including:
- [Pantheon](#pantheon-2)
- [Tugboat](#tugboat)
- [Contributor Docs](#contributor-docs)
- [Local Development](#local-development)
- [Peer Review Guidelines for Automated Updates](#peer-review-guidelines-for-automated-updates)
- [Handling Version Ranges](#handling-version-ranges)
- [Handling Test Failures](#handling-test-failures)
Expand Down Expand Up @@ -228,34 +229,18 @@ All the below static code analysis tests can be run with `task test:static`
| PHPCS | task test:phpcs | Runs PHPCS with Drupal coding standards provided by [Coder module](https://www.drupal.org/project/coder |


#### Excluding Files from PHP_CodeSniffer

`phpcs.xml` can be altered using Drupal's
[composer scaffold](https://www.drupal.org/docs/develop/using-composer/using-drupals-composer-scaffold#toc_4).
#### Altering PHP_CodeSniffer Configuration

- Create `phpcs.xml` to override the `phpcs.xml.dist` file with overrides being done in:
```
<rule ref="phpcs.xml.dist">
</rule>
```
- Edit `phpcs.xml` in the root of your project, e.g. to add an exclude pattern:
```
<!-- Custom excludes -->
<exclude-pattern>web/sites/sites.php</exclude-pattern>
```
- Create a patch file
```
diff -urN vendor/lullabot/drainpipe-dev/scaffold/phpcs.xml phpcs.xml > patches/custom/phpcs.xml.patch
```
- Add the patch to `composer.json`
```
"scripts": {
"pre-drupal-scaffold-cmd": [
"if [ -f \"phpcs.xml\" ]; then rm phpcs.xml; fi"
],
"post-drupal-scaffold-cmd": [
"if [ -f \"phpcs.xml\" ]; then patch phpcs.xml < patches/custom/phpcs.xml.patch; fi"
]
},
```
The pre hook is needed otherwise the composer scaffold attempts to re-patch a file it no longer has control over when running `composer install --no-dev`
- Delete the `vendor` directory and `phpcs.xml` and then run `composer install`
to verify everything works as expected

### Functional Tests

Expand Down Expand Up @@ -681,6 +666,10 @@ Peer Reviewing by looking at PR code changes is nice.

Testing PR code changes on real sites is extra beneficial.

### Local Development

In order to test local changes follow the instructions for the [test script](./docs/test-script.md).

### Peer Review Guidelines for Automated Updates

These are guidelines for conducting peer reviews on automated dependency update pull requests created by Renovate.
Expand Down
2 changes: 1 addition & 1 deletion docs/test-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A test script is available in `tests/local-test.sh` to setup a Drupal site
with Drainpipe packages installed from your local checkout.

Go to the directory above `drainpipe` and run the `tests/local-hest.sh` script
Go to the directory above `drainpipe` and run the `tests/local-test.sh` script
to setup a new test site e.g.
```
❯ pwd
Expand Down
2 changes: 1 addition & 1 deletion drainpipe-dev/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"[web-root]/sites/sites.php": "scaffold/nightwatch/sites.php",
"[project-root]/.ddev/docker-compose.selenium.yaml": "scaffold/nightwatch/docker-compose.selenium.yaml",
"[project-root]/test/nightwatch/example.nightwatch.js": "scaffold/nightwatch/example.nightwatch.js",
"[project-root]/phpcs.xml": "scaffold/phpcs.xml"
"[project-root]/phpcs.xml.dist": "scaffold/phpcs.xml.dist"
}
}
},
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ tasks:
desc: Runs PHPCS with Drupal Coding Standards
summary: |
Check your code against Drupal's coding standards. To override the default
ruleset, copy vendor/lullabot/drainpipe/scaffold/phpcs.xml to phpcs.xml
in the root of your project and edit as needed.
ruleset, create a phpcs.xml file and extend phpcs.xml.dist
cmds:
- |
{{ .FUNC_ENSURE_DIRS }}
Expand Down

0 comments on commit 0d15f38

Please sign in to comment.