Skip to content
This repository was archived by the owner on Sep 15, 2023. It is now read-only.

Commit 22f9211

Browse files
author
David Lakin
committed
Init commit
0 parents  commit 22f9211

File tree

7 files changed

+362
-0
lines changed

7 files changed

+362
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor/
2+
*.swp

README.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# PHPCS Differing Results POC
2+
3+
This repo shows PHPCS will provide different results when running against single and multiple files.
4+
5+
To reproduce the issue:
6+
7+
1. `git clone` this repo and `cd` into the project root
8+
1. `composer install` to install dependencies
9+
1. Run ` ./vendor/bin/phpcs`
10+
1. Run ` ./vendor/bin/phpcs category.php`
11+
1. Notice PHPCS flags warnings in `category.php` only when run against the project
12+
13+
#### Expected output of ` ./vendor/bin/phpcs`:
14+
15+
```
16+
FILE: /path/to/phpcs_poc/functions.php
17+
----------------------------------------------------------------------------------------
18+
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
19+
----------------------------------------------------------------------------------------
20+
13 | WARNING | Comment refers to a TODO task "Load this conditionally"
21+
| | (Generic.Commenting.Todo.TaskFound)
22+
15 | WARNING | In footer ($in_footer) is not set explicitly wp_enqueue_script; It is
23+
| | recommended to load scripts in the footer. Please set this value to
24+
| | `true` to load it in the footer, or explicitly `false` if it should be
25+
| | loaded in the header.
26+
| | (WordPress.WP.EnqueuedResourceParameters.NotInFooter)
27+
----------------------------------------------------------------------------------------
28+
FILE: /path/to/phpcs_poc/category.php
29+
----------------------------------------------------------------------------------------
30+
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
31+
----------------------------------------------------------------------------------------
32+
11 | WARNING | Found precision alignment of 1 spaces.
33+
| | (WordPress.WhiteSpace.PrecisionAlignment.Found)
34+
12 | WARNING | Found precision alignment of 1 spaces.
35+
| | (WordPress.WhiteSpace.PrecisionAlignment.Found)
36+
----------------------------------------------------------------------------------------
37+
```
38+
39+
#### Expected output of ` ./vendor/bin/phpcs category.php`:
40+
41+
42+
```
43+
. 1 / 1 (100%)
44+
45+
Time: 132ms; Memory: 8Mb
46+
```
47+
48+
#### Expected output of ` ./vendor/bin/phpcs functions.php`:
49+
50+
```
51+
FILE: /path/to/phpcs_poc/functions.php
52+
----------------------------------------------------------------------------------------
53+
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
54+
----------------------------------------------------------------------------------------
55+
13 | WARNING | Comment refers to a TODO task "Load this conditionally"
56+
| | (Generic.Commenting.Todo.TaskFound)
57+
15 | WARNING | In footer ($in_footer) is not set explicitly wp_enqueue_script; It is
58+
| | recommended to load scripts in the footer. Please set this value to
59+
| | `true` to load it in the footer, or explicitly `false` if it should be
60+
| | loaded in the header.
61+
| | (WordPress.WP.EnqueuedResourceParameters.NotInFooter)
62+
----------------------------------------------------------------------------------------
63+
```

category.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
*
4+
* This file should not generate warnings in phpcs
5+
*
6+
*/
7+
8+
?>
9+
10+
<div class="some-class">
11+
<img data-src="//image.png"
12+
src="//image-placeholder.png"
13+
class="lazyload" />
14+
</div>

composer.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "DaveLak/phpcs-poc",
3+
"description": "",
4+
"type": "wordpress-theme",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "DaveLak",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {},
13+
"require-dev": {
14+
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
15+
"squizlabs/php_codesniffer": "^3.3",
16+
"wp-coding-standards/wpcs": "^1.1"
17+
},
18+
"prefer-stable" : true,
19+
"config": {
20+
"vendor-dir": "vendor",
21+
"preferred-install": "dist",
22+
"optimize-autoloader": true,
23+
"sort-packages": true
24+
},
25+
"scripts": {
26+
"lint": ["phpcs"],
27+
"lint:report": [
28+
"[ -d ./reports ] || mkdir -p ./reports",
29+
"phpcs --report-file=./reports/phpcs_$(date +\"%Y-%m-%d-%H%M%S\").txt"
30+
],
31+
"lint:fix": ["phpcbf"]
32+
}
33+
}

composer.lock

+180
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

functions.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
*
4+
* This file should always cause warnings to be generated by phpcs
5+
*
6+
*/
7+
8+
function register_scripts() {
9+
wp_register_style( 'style-css', '/css/style.css', array(), '0.0.0', 'all' );
10+
11+
wp_enqueue_style( 'style1', '/css/style1.css', '', '0.0.1' );
12+
wp_enqueue_style( 'style2', '/css/style2.css', '', '0.0.2' );
13+
14+
wp_enqueue_style( 'style-with-todo', 'style-with-todo.css', '', '0.0.1' ); // TODO: Load this conditionally
15+
16+
wp_enqueue_script( 'jquery', '/js/vendor/jquery.min.js', '', '3.2.1' );
17+
}
18+
add_action( 'wp_enqueue_scripts', 'register_scripts' );

phpcs.xml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="POC">
3+
<description>These rules generate different output depending on what they are run against.</description>
4+
5+
<!-- Start scanning from project root. -->
6+
<file>./</file>
7+
8+
<!-- Exclude the Composer Vendor directory. -->
9+
<exclude-pattern>vendor/*</exclude-pattern>
10+
11+
<!--
12+
=======================================
13+
Define CLI args PHPCS should run with.
14+
=======================================
15+
-->
16+
17+
<!-- Show colors in console. -->
18+
<arg value="-colors"/>
19+
20+
<!--
21+
p flag: Show progress of the run.
22+
s flag: Show the name of the rule violated in reports.
23+
-->
24+
<arg value="ps"/>
25+
26+
<!--
27+
===========================
28+
Define rulesets to enforce.
29+
===========================
30+
-->
31+
32+
<!-- Include the WordPress-Extra standard. -->
33+
<rule ref="WordPress-Extra">
34+
<!--
35+
For a list of configurable rules included by WordPress Coding Standards
36+
see here: https://git.io/fx0T4
37+
-->
38+
<!-- Allow spaces instead of tabs. -->
39+
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent"/>
40+
</rule>
41+
42+
<rule ref="Generic.Commenting.Todo"/>
43+
44+
<!-- THIS IS THE RULE THAT IS HAS ISSUES -->
45+
<rule ref="WordPress.WhiteSpace.PrecisionAlignment">
46+
<properties>
47+
<!-- Allow Precision Alignment in HTML and Comments. -->
48+
<property name="ignoreAlignmentTokens" type="array" value="T_COMMENT,T_INLINE_HTML"/>
49+
</properties>
50+
</rule>
51+
52+
</ruleset>

0 commit comments

Comments
 (0)