Skip to content

Commit 470c361

Browse files
committed
New reusable workflow: "find token properties"
PHP_CodeSniffer originally offered a number of "token groups" as static properties in the `Tokens` class to allow re-use of these groups across sniffs. As of PHP_CodeSniffer 4.0.0, these static properties still exist, but are now (soft) deprecated in favour of class constants in the `Tokens` class for the same, which should create more stability, as this means the token groups can no longer be changed from within a(n external) sniff. PHP_CodeSniffer related projects which still support both PHPCS 3.x as well as 4.x, will, for the time being, still need to use the static properties from the `Tokens` class. Once a PHP_CodeSniffer related project has dropped support for PHPCS 3.x though, they can enforce the use of the class constants from the `Tokens` class by running this re-usable workflow in their CI. * This workflow is particularly useful for repositories which have existing open PRs at the time of the PHPCS version drop and these open PRs should not re-introduce references to the static properties. * This workflow can also be helpful for repositories which have contributors which contribute to a range of PHPCS related repos and for whom it would be very easy to overlook that they've used the "old-school" token group instead of the new-fangled token group constants. In contrast to most of the other reusable workflows, this workflow does not work based on a configuration file. One should only add a job calling this workflow to a project's CI once support for PHPCS 3.x has been dropped. Includes adding documentation about this workflow to the `README` file.
1 parent 545ea21 commit 470c361

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: FindTokenPropertiesRefs
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
find-token-properties:
8+
# The properties in the PHPCS Tokens class have been deprecated since PHPCS 4.0.0.
9+
name: 'Find use of Tokens properties'
10+
runs-on: windows-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
15+
with:
16+
persist-credentials: false
17+
18+
- name: Find uses
19+
id: findprops
20+
shell: cmd
21+
run: |
22+
findstr /S /N /C:"Tokens::$" *.php
23+
IF %ERRORLEVEL% NEQ 1 (Echo Please use the Tokens constants instead of the properties &Exit /b 1)
24+
IF %ERRORLEVEL% EQU 1 (Echo All good &Exit /b 0)

README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Additional community health files may be added over time and/or when GitHub adds
1616

1717
## Re-usable workflows
1818

19-
Aside from the community health files, this repository also offers a number of configuration file driven re-usable GitHub Actions workflows.
19+
Aside from the community health files, this repository also offers a number of (mostly) configuration file driven re-usable GitHub Actions workflows.
2020

2121
### What does "configuration file driven" mean and why are the workflows set up that way ?
2222

@@ -49,7 +49,10 @@ The following re-usable workflows are available:
4949
**Inputs**:
5050
+ `strict`: Optional. Whether to enable strict mode. Defaults to "false".
5151
2. [actionlint] which runs a static analysis check on GitHub Actions workflow files only.
52-
_Note: this is the only check without a configuration file requirement._
52+
_Note: this check does not have a configuration file requirement._
53+
* [`reusable-findtokenprops.yml`][reusable-findtokenprops] to find any uses of the PHPCS static `Tokens::$groupName` properties.
54+
These properties have been (soft) deprecated since PHP_CodeSniffer 4.0.0 and should no longer be used in code bases which have dropped support for PHP_CodeSniffer 3.x.
55+
_Note: this check does not have a configuration file requirement._
5356

5457
Example configuration files for most of these can be found in the root directory of this repository.
5558

@@ -70,17 +73,19 @@ This has two benefits:
7073
> It is best practice for tags for repositories which will be used in GitHub Actions workflows to be prefixed with `v` before the version number, so tags in this repository should start with a `v` prefix too.
7174
7275

73-
[community health files]: https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/creating-a-default-community-health-file
76+
[community health files]: https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/creating-a-default-community-health-file
7477

75-
[reusable-markdownlint]: https://github.com/PHPCSStandards/.github/blob/main/.github/workflows/reusable-markdownlint.yml
76-
[markdownlint-cli2]: https://github.com/DavidAnson/markdownlint-cli2
78+
[reusable-markdownlint]: https://github.com/PHPCSStandards/.github/blob/main/.github/workflows/reusable-markdownlint.yml
79+
[markdownlint-cli2]: https://github.com/DavidAnson/markdownlint-cli2
7780

78-
[reusable-phpstan]: https://github.com/PHPCSStandards/.github/blob/main/.github/workflows/reusable-phpstan.yml
79-
[phpstan]: https://phpstan.org/
81+
[reusable-phpstan]: https://github.com/PHPCSStandards/.github/blob/main/.github/workflows/reusable-phpstan.yml
82+
[phpstan]: https://phpstan.org/
8083

81-
[reusable-remark]: https://github.com/PHPCSStandards/.github/blob/main/.github/workflows/reusable-remark.yml
82-
[remark-lint]: https://github.com/remarkjs/remark-lint
84+
[reusable-remark]: https://github.com/PHPCSStandards/.github/blob/main/.github/workflows/reusable-remark.yml
85+
[remark-lint]: https://github.com/remarkjs/remark-lint
8386

84-
[reusable-yamllint]: https://github.com/PHPCSStandards/.github/blob/main/.github/workflows/reusable-yamllint.yml
85-
[yamllint]: https://yamllint.readthedocs.io/en/stable/
86-
[actionlint]: https://github.com/rhysd/actionlint
87+
[reusable-yamllint]: https://github.com/PHPCSStandards/.github/blob/main/.github/workflows/reusable-yamllint.yml
88+
[yamllint]: https://yamllint.readthedocs.io/en/stable/
89+
[actionlint]: https://github.com/rhysd/actionlint
90+
91+
[reusable-findtokenprops]: https://github.com/PHPCSStandards/.github/blob/main/.github/workflows/reusable-findtokenprops.yml

0 commit comments

Comments
 (0)