Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CPNT-2249): PHPCS config #2

Merged
merged 17 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: 2.1
jobs:
lint-php:
docker:
- image: cimg/php:8.2-node
steps:
- checkout
- run:
name: Install production dependencies
command: composer install --no-dev -o
- run:
name: Composer validate
command: composer validate --strict
- run:
name: Check if NewsUK PHPCS standard is installed
command: |
vendor/bin/phpcs -i
if vendor/bin/phpcs -i | grep -q "NewsUK"; then
echo "NewsUK PHPCS standard is installed successfully."
else
echo "Error: NewsUK PHPCS standard is not installed."
exit 1
fi
- persist_to_workspace:
root: .
paths:
- vendor
workflows:
version: 2
build:
jobs:
- lint-php
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.circleci/ export-ignore
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "weekly"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @newsuk/tnl-wp-newspress
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 News UK

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
81 changes: 81 additions & 0 deletions NewsUK/ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0"?>
<ruleset name="NewsUK">
<config name="minimum_supported_wp_version" value="6.2" />
<config name="testVersion" value="8.2-"/>

jonnynews marked this conversation as resolved.
Show resolved Hide resolved
<rule ref="PHPCompatibilityWP" />

<rule ref="WordPress-Docs">
<severity>5</severity>
</rule>
<rule ref="WordPress-Extra">
<severity>5</severity>
</rule>
<rule ref="WordPress-Core">
<severity>5</severity>
</rule>
<rule ref="WordPress-VIP-Go">
<severity>5</severity>
</rule>

mohanrajpac marked this conversation as resolved.
Show resolved Hide resolved
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="newsuk"/>
</property>
</properties>
</rule>

<!-- Disable some sniffs that conflict with PSR-4. -->
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
<exclude-pattern>includes/*</exclude-pattern>
<exclude-pattern>inc/*</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
<exclude-pattern>includes/*</exclude-pattern>
<exclude-pattern>inc/*</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<rule ref="Universal.Operators.DisallowShortTernary.Found">
<severity>0</severity>
</rule>

<rule ref="Universal.Arrays.DisallowShortArraySyntax.Found">
<severity>0</severity>
</rule>

<rule ref="WordPress.PHP.YodaConditions.NotYoda">
<severity>0</severity>
</rule>

<rule ref="PSR12.Files.FileHeader.SpacingAfterBlock">
<severity>0</severity>
</rule>

mohanrajpac marked this conversation as resolved.
Show resolved Hide resolved
<rule ref="PSR2.Namespaces.UseDeclaration">
<exclude name="PSR2.Namespaces.UseDeclaration.MultipleDeclarations" />
</rule>
<rule ref="PSR2R.Namespaces.UnusedUseStatement" />
<rule ref="PSR2R.Namespaces.UseInAlphabeticalOrder" />

<!-- Check all PHP files in directory tree by default. -->
<arg name="extensions" value="php"/>
<file>.</file>

<!-- Show sniff codes in all reports -->
<arg value="sp"/>

<arg name="colors"/>
mohanrajpac marked this conversation as resolved.
Show resolved Hide resolved

<!-- Check up to 20 files simultaneously. -->
<arg name="parallel" value="20" />

<exclude-pattern>/node_modules/*</exclude-pattern>
<exclude-pattern>/vendor/*</exclude-pattern>
<exclude-pattern>/cypress/*</exclude-pattern>
<exclude-pattern>/build/*</exclude-pattern>
<exclude-pattern>/tests/*</exclude-pattern>
</ruleset>
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
### NUK WP PHPCS config
### NUK WP PHPCS config

This library contains WordPress VIP PHPCS configuration for NewsUK plugins and themes.

## Requirements
- PHP 8.2
- WordPress 6.2

## Installation

Composer install:

```bash
composer require --dev newsuk/nuk-wp-phpcs-config
```

## Using the ruleset
Create a `phpcs.xml.dist` file in your project and add the following:
mohanrajpac marked this conversation as resolved.
Show resolved Hide resolved

```xml
<?xml version="1.0"?>
<ruleset name="NewsUK WP PHPCS Rules">
<rule ref="NewsUK"/>
</ruleset>
```
💡 *It is recommended to use the `NewsUK` ruleset as it is without customising or overriding rules unless necessary.*

## Override or add custom rules
You can also override or add custom rules to the config as follows.

```xml
<?xml version="1.0"?>
<ruleset name="NewsUK WP PHPCS Rules">
<rule ref="NewsUK"/>
<!-- Overriding the existing text_domain -->
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="your_plugin_domain"/>
</property>
</properties>
</rule>
</ruleset>
```
## Composer scripts
Add the following to `scripts` section in `composer.json` file to run linting.

```json
"lint": "phpcs .",
"lint:fix": "phpcbf .",
```
21 changes: 21 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "newsuk/nuk-wp-phpcs-config",
"description": "PHPCS configuration for WordPress VIP plugins and themes",
"type": "phpcodesniffer-standard",
"license": "MIT",
"authors": [
{
"name": "Content Platforms",
"email": "contentplatforms@news.co.uk"
}
],
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"require": {
"automattic/vipwpcs": "^3.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0"
}
}
Loading