Add phpcs-changed (#33584)
* Add phpcs-changed * Put report flag value in quotes * Use phpcs action workflow instead * Remove no longer used phpcs script * Remove phpcs ignore rule * Use proper name for code sniffer step
This commit is contained in:
parent
adbe9f37d8
commit
14066bdeae
|
@ -15,13 +15,13 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 100
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 7.4
|
||||
tools: composer, cs2pr
|
||||
tools: composer
|
||||
|
||||
- name: Tool versions
|
||||
run: |
|
||||
|
@ -36,11 +36,9 @@ jobs:
|
|||
- name: Install and Build
|
||||
uses: ./.github/actions/install-build
|
||||
|
||||
- name: Run code sniff
|
||||
continue-on-error: true
|
||||
working-directory: plugins/woocommerce
|
||||
run: ./tests/bin/phpcs.sh "${{ github.event.pull_request.base.sha }}" "${{ github.event.after }}"
|
||||
|
||||
- name: Show PHPCS results in PR
|
||||
working-directory: plugins/woocommerce
|
||||
run: cs2pr ./phpcs-report.xml
|
||||
- name: Run code sniffer
|
||||
uses: thenabeel/action-phpcs@v8
|
||||
with:
|
||||
files: "**.php"
|
||||
phpcs_path: plugins/woocommerce/vendor/bin/phpcs
|
||||
standard: phpcs.xml
|
||||
|
|
|
@ -117,12 +117,6 @@
|
|||
<exclude-pattern>src/Admin/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- Temporary -->
|
||||
<rule ref="WooCommerce.Commenting.CommentHooks.MissingHooksComment">
|
||||
<exclude-pattern>plugins/woocommerce/src/Internal/Admin/</exclude-pattern>
|
||||
<exclude-pattern>src/Admin/</exclude-pattern>
|
||||
</rule>
|
||||
|
||||
<!-- Temporary -->
|
||||
<rule ref="WordPress.Security.NonceVerification.Recommended">
|
||||
<exclude-pattern>src/Internal/Admin/</exclude-pattern>
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
{
|
||||
"require-dev": {
|
||||
"woocommerce/woocommerce-sniffs": "^0.1.3"
|
||||
"woocommerce/woocommerce-sniffs": "^0.1.3",
|
||||
"sirbrillig/phpcs-changed": "^2.10"
|
||||
},
|
||||
"config": {
|
||||
"platform": {
|
||||
"php": "7.0"
|
||||
"php": "7.4"
|
||||
},
|
||||
"allow-plugins": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": true
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "9de5fb089d0fd21b5e15523eb7c07459",
|
||||
"content-hash": "df66db582a7c00ab0a701277e962ecce",
|
||||
"packages": [],
|
||||
"packages-dev": [
|
||||
{
|
||||
|
@ -254,6 +254,63 @@
|
|||
},
|
||||
"time": "2021-12-30T16:37:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sirbrillig/phpcs-changed",
|
||||
"version": "v2.10.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sirbrillig/phpcs-changed.git",
|
||||
"reference": "ba049e6f7da40d64056f7b6c4078e87f0f292d6b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sirbrillig/phpcs-changed/zipball/ba049e6f7da40d64056f7b6c4078e87f0f292d6b",
|
||||
"reference": "ba049e6f7da40d64056f7b6c4078e87f0f292d6b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
|
||||
"phpstan/phpstan": "^0.12.33",
|
||||
"phpunit/phpunit": "^6.4 || ^9.5",
|
||||
"sirbrillig/phpcs-import-detection": "^1.1.1",
|
||||
"sirbrillig/phpcs-variable-analysis": "^2.1.3",
|
||||
"squizlabs/php_codesniffer": "^3.2.1"
|
||||
},
|
||||
"bin": [
|
||||
"bin/phpcs-changed"
|
||||
],
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"PhpcsChanged/Cli.php",
|
||||
"PhpcsChanged/SvnWorkflow.php",
|
||||
"PhpcsChanged/GitWorkflow.php",
|
||||
"PhpcsChanged/functions.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"PhpcsChanged\\": "PhpcsChanged/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Payton Swick",
|
||||
"email": "payton@foolord.com"
|
||||
}
|
||||
],
|
||||
"description": "Run phpcs on files, but only report warnings/errors from lines which were changed.",
|
||||
"support": {
|
||||
"issues": "https://github.com/sirbrillig/phpcs-changed/issues",
|
||||
"source": "https://github.com/sirbrillig/phpcs-changed/tree/v2.10.0"
|
||||
},
|
||||
"time": "2022-03-09T18:16:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "squizlabs/php_codesniffer",
|
||||
"version": "3.7.1",
|
||||
|
@ -414,7 +471,7 @@
|
|||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"platform-overrides": {
|
||||
"php": "7.0"
|
||||
"php": "7.4"
|
||||
},
|
||||
"plugin-api-version": "2.3.0"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
Significance: patch
|
||||
Type: update
|
||||
Comment: Add phpcs-changed to CI to only sniff changed lines of code.
|
|
@ -88,7 +88,7 @@
|
|||
"phpcs -s -p"
|
||||
],
|
||||
"phpcs-pre-commit": [
|
||||
"phpcs -s -p -n"
|
||||
"phpcs-changed --git -s"
|
||||
],
|
||||
"phpcbf": [
|
||||
"phpcbf -p"
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
COMMIT_RANGE="${1} ${2}"
|
||||
CHANGED_FILES=`git diff --name-only --diff-filter=ACMR $COMMIT_RANGE | grep '\.php' | grep 'plugins/woocommerce/' | sed -e 's/^plugins\/woocommerce\///' | awk '{print}' ORS=' '`
|
||||
IGNORE="tests/cli/,includes/libraries/,includes/api/legacy/"
|
||||
|
||||
if [ "$CHANGED_FILES" != "" ]; then
|
||||
echo "Changed files: $CHANGED_FILES"
|
||||
echo "Running Code Sniffer."
|
||||
|
||||
./vendor/bin/phpcs --ignore=$IGNORE --encoding=utf-8 -s -n -p --report-full --report-checkstyle=./phpcs-report.xml ${CHANGED_FILES}
|
||||
else
|
||||
echo "No changes found. Skipping PHPCS run."
|
||||
fi
|
Loading…
Reference in New Issue