Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Add code linting and github action (#73)
Browse files Browse the repository at this point in the history
* Add config files for PHP and CSS linting + coding standards.

* Update readme with test info.

* Fix standards error and add newline at end of file.

* Test github action.

* Fix php version.

* Ignore warnings on exit and remove stan from autocheck.

* Apply clarifications and naming suggestions

Co-authored-by: Stephen Edgar <stephen@netweb.com.au>

* Formatting improvements.

* Pin actions to specific commit/version, use node v14

* Remove extra linebreaks.

* Fix yaml syntax errors.

* Remove reference to this branch.

Co-authored-by: Stephen Edgar <stephen@netweb.com.au>
  • Loading branch information
jffng and ntwb authored Oct 11, 2021
1 parent 5b0aa3b commit 6896110
Show file tree
Hide file tree
Showing 13 changed files with 3,313 additions and 2 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

66 changes: 66 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Code Quality - PHP

on:
pull_request:
branches: [trunk]
push:
branches: [trunk]

jobs:
lint:
name: Parallel lint
runs-on: ubuntu-latest

steps:
# Checkout repository
- name: Checkout
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
# Setup PHP versions, run checks
- name: PHP setup
uses: shivammathur/setup-php@a7f90656b3be3996d1ec5501e8e25d5d35aa9bb2 # v2.15.0
with:
php-version: 7.4
- name: Get composer cache directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@c64c572235d810460d0d6876e9c705ad5002b353 # v2.1.6
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install composer packages
run: composer install --no-progress
- name: Check for PHP errors
run: composer lint

phpcs_check:
name: PHPCS check
runs-on: ubuntu-latest

steps:
# Checkout repository
- name: Checkout
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
# Setup PHP versions, run checks
- name: PHP setup
uses: shivammathur/setup-php@a7f90656b3be3996d1ec5501e8e25d5d35aa9bb2 # v2.15.0
with:
php-version: 7.4
- name: Get composer cache directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@c64c572235d810460d0d6876e9c705ad5002b353 # v2.1.6
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install composer packages
run: composer install --no-progress
- name: Check coding standards using PHPCS
run: composer standards:check -- --runtime-set ignore_warnings_on_exit true --runtime-set testVersion 5.8-
25 changes: 25 additions & 0 deletions .github/workflows/stylelint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Code Quality - CSS

on:
pull_request:
branches: [trunk]
push:
branches: [trunk]

jobs:
stylelint:
name: stylelint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
- name: install node v14
uses: actions/setup-node@270253e841af726300e85d718a5f606959b2903c # v2.4.1
with:
node-version: 14
- name: npm install
run: npm install
- name: stylelint
uses: actions-hub/stylelint@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PATTERN: "**/*.css"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
vendor
3 changes: 3 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@wordpress/stylelint-config"
}
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ To get started with development:

Some theme features / PRs may require Gutenberg trunk and will be described or tagged accordingly.

To optionally run tests locally, you will also need:
- [Node.js](https://nodejs.org/en/)
- [Composer](https://getcomposer.org/)

You can install the test-specific development dependencies by running `npm i && composer install`. The following test commands are then available:
- `npm run lint:css` lints and autofixes where possible the CSS
- `composer run analyze [filename.php]` statically analyzes PHP for bugs
- `composer run lint` checks PHP for syntax errors
- `composer run standards:check` checks PHP for standards errors according to [WordPress coding standards](https://developer.wordpress.org/coding-standards/)
- `composer run standards:fix` attemps to automatically fix errors

## Resources
- [Twenty Twenty-Two Figma Mockups](https://www.figma.com/file/76mfUcaK4QDlrXElk8MK3H/Twenty-Twenty-Two?node-id=10%3A54)
- [Setting up a development environment](https://developer.wordpress.org/block-editor/handbook/tutorials/devenv/)
Expand Down
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "wordpress/twentytwentytwo",
"type": "package",
"description": "WordPress default theme for 2022.",
"keywords": [
"WordPress",
"Themes"
],
"homepage": "https://github.com/WordPress/twentytwentytwo",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "Contributors",
"homepage": "https://github.com/WordPress/twentytwentytwo/contributors.md"
}
],
"require": {
"php": ">=5.6"
},
"require-dev": {
"szepeviktor/phpstan-wordpress": "^0.7.7",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"wptrt/wpthemereview": "^0.2.1",
"php-parallel-lint/php-parallel-lint": "^1.3"
},
"scripts": {
"analyze": "@php ./vendor/bin/phpstan analyze",
"lint": "@php ./vendor/bin/parallel-lint --exclude .git --exclude vendor .",
"standards:check": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
"standards:fix": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
}
}
Loading

0 comments on commit 6896110

Please sign in to comment.