Skip to content

Commit c4f14f9

Browse files
authored
fix: add ruleset testing workflow and fix annotation standards (#9)
* fix: Disable `Squiz.Commenting.VariableComment.MissingVar` in favor of `SlevomatCodingStandard.TypeHints.PropertyTypeHint`. * fix: Ignore `SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation` for PHPStan annotations. * ci: Add ruleset testing Workflow. * ci: try again * ci: no ruleset matrix * ci: try again * fix: XML formatting issue in WPGraphQL-Core ruleset. * fix: exclude location for SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation
1 parent 5224143 commit c4f14f9

File tree

5 files changed

+100
-6
lines changed

5 files changed

+100
-6
lines changed

.github/workflows/test.yml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Test Rulesets
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
pull_request:
9+
branches:
10+
- main
11+
- develop
12+
schedule:
13+
# Run weekly on Mondays at 00:00 UTC
14+
- cron: '0 0 * * 1'
15+
workflow_dispatch: # Allow manual triggering
16+
17+
# Cancels all previous workflow runs for the same branch that have not yet completed.
18+
concurrency:
19+
# The concurrency group contains the workflow name and the branch name.
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
test-rulesets:
25+
name: Test rulesets
26+
runs-on: ubuntu-latest
27+
28+
strategy:
29+
matrix:
30+
php: [8.4, 8.3, 8.2, 8.1, 8.0, 7.4]
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v4
35+
36+
- name: Setup PHP
37+
uses: shivammathur/setup-php@v2
38+
with:
39+
php-version: ${{ matrix.php }}
40+
extensions: mbstring, xml, zip
41+
tools: composer:v2
42+
# Allow for PHP deprecation notices.
43+
ini-values: error_reporting = E_ALL & ~E_DEPRECATED
44+
coverage: none
45+
env:
46+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Validate composer.json file
49+
run: composer validate --no-check-all --strict
50+
51+
- name: Install Composer dependencies
52+
uses: ramsey/composer-install@v3
53+
with:
54+
# Bust the cache at least once a month - output format: YYYY-MM.
55+
custom-cache-suffix: $(date -u "+%Y-%m")
56+
57+
- name: Download latest WPGraphQL from GitHub Releases
58+
run: |
59+
# Download the latest release
60+
mkdir -p temp/wp-graphql
61+
curl -L -o temp/wp-graphql/wp-graphql.zip https://github.com/wp-graphql/wp-graphql/releases/latest/download/wp-graphql.zip
62+
# Unzip the downloaded file
63+
cd temp/wp-graphql
64+
unzip wp-graphql.zip
65+
# List files to verify extraction
66+
ls -la
67+
68+
# Validate the Ruleset XML files.
69+
- name: Validate the WordPress rulesets
70+
uses: phpcsstandards/xmllint-validate@v1
71+
with:
72+
pattern: "./*/ruleset.xml"
73+
xsd-file: "vendor/squizlabs/php_codesniffer/phpcs.xsd"
74+
75+
- name: Lint WPGraphQL Core
76+
run: |
77+
# Run the PHP CodeSniffer tests against the WPGraphQL Core ruleset.
78+
vendor/bin/phpcs --standard=./WPGraphQL-Core/ruleset.xml --basepath=temp/wp-graphql/wp-graphql --runtime-set ignore_warnings_on_exit 1 -s temp/wp-graphql/wp-graphql/src --report-full --report-width=120
79+

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a
66

77
## [ Unreleased ]
88

9+
- fix: Disable `Squiz.Commenting.VariableComment.MissingVar` in favor of `SlevomatCodingStandard.TypeHints.PropertyTypeHint`.
10+
- fix: Ignore `SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation` for PHPStan annotations.
11+
- fix: Fix incorrect excludes in `WPGraphQL-Core` ruleset.
12+
- ci: Add ruleset testing Workflow.
13+
914
## [2.0.0] - 2025-02-15
1015

1116
This release updates the `WPGraphQL-Core` ruleset to match the latest changes included in WPGraphQL [v2.0.0](https://github.com/wp-graphql/wp-graphql/releases/tag/v2.0.0).

WPGraphQL-Core/ruleset.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
<exclude name="WordPress.WP.Capabilities.Undetermined" />
1111
<!-- Most would require breaking changes to fix in core. Tracking: https://github.com/wp-graphql/wp-graphql/issues/2925 -->
1212
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter" />
13-
14-
<!-- Depends on Squiz.Commenting.FunctionComment.MissingParamComment -->
15-
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation" />
1613
</rule>
1714

18-
<rule ref="WPGraphQL-Docs" />
15+
<rule ref="WPGraphQL-Docs">
1916
<!-- Conflicts with b/c in AbstractConnectionResolver -->
2017
<exclude name="Squiz.Commenting.FunctionComment.InvalidNoReturn" />
2118

@@ -27,5 +24,8 @@
2724
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment" />
2825
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop" />
2926
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
30-
<rule />
27+
28+
<!-- Depends on Squiz.Commenting.FunctionComment.MissingParamComment -->
29+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation" />
30+
</rule>
3131
</ruleset>

WPGraphQL-Docs/ruleset.xml

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<exclude name="Squiz.Commenting.FunctionComment.IncorrectTypeHint" />
1111
<!-- Conflicts with b/c in AbstractConnectionResolver -->
1212
<exclude name="Squiz.Commenting.FunctionComment.InvalidNoReturn" />
13+
<!-- Better handled by SlevomatCodingStandard.TypeHints.PropertyTypeHint -->
14+
<exclude name="Squiz.Commenting.VariableComment.MissingVar" />
1315
</rule>
1416
<rule ref="Squiz.Commenting.FunctionComment">
1517
<properties>

WPGraphQL-Minimum/ruleset.xml

+9-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@
6363
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure" />
6464
<rule ref="SlevomatCodingStandard.Functions.UselessParameterDefaultValue" />
6565

66-
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation"/>
66+
<rule ref="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameInAnnotation">
67+
<properties>
68+
<property name="ignoredAnnotationNames" type="array">
69+
<element value="@phpstan-var" />
70+
<element value="@phpstan-param" />
71+
<element value="@phpstan-return" />
72+
</property>
73+
</properties>
74+
</rule>
6775
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash" />
6876

6977
<rule ref="SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking" />

0 commit comments

Comments
 (0)