From eb2237abfee1e5032937e8e2b2438b30c3feed05 Mon Sep 17 00:00:00 2001 From: Ryan Welcher Date: Thu, 23 Jan 2025 14:28:07 -0500 Subject: [PATCH] Initial commit --- .editorconfig | 14 +++++++ .eslintignore | 3 ++ .eslintrc | 3 ++ .github/workflows/pull-request-actions.yml | 46 ++++++++++++++++++++++ .gitignore | 5 +++ .nvmrc | 1 + README.md | 21 ++++++++++ composer.json | 18 +++++++++ package.json | 26 ++++++++++++ phpcs.xml | 9 +++++ src/.gitkeep | 0 11 files changed, 146 insertions(+) create mode 100644 .editorconfig create mode 100644 .eslintignore create mode 100644 .eslintrc create mode 100644 .github/workflows/pull-request-actions.yml create mode 100644 .gitignore create mode 100644 .nvmrc create mode 100644 README.md create mode 100644 composer.json create mode 100644 package.json create mode 100644 phpcs.xml create mode 100644 src/.gitkeep diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7cae5d5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# 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 diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..ee68111 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,3 @@ +build +node_modules +vendor diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..ea57661 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": [ "plugin:@wordpress/eslint-plugin/recommended" ] +} \ No newline at end of file diff --git a/.github/workflows/pull-request-actions.yml b/.github/workflows/pull-request-actions.yml new file mode 100644 index 0000000..7a11166 --- /dev/null +++ b/.github/workflows/pull-request-actions.yml @@ -0,0 +1,46 @@ +name: Static Linting + +on: + pull_request: + push: + branches: + - trunk + +jobs: + php: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Install dependencies + uses: php-actions/composer@v6 + - name: Lint PHP files + run: composer run lint + + name: PHP Files + + other: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x, 16.x] + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: npm ci + - name: Lint JavaScript files + run: npm run lint:js + - name: Lint CSS files + run: npm run lint:css + - name: Lint package.json files + run: npm run lint:pkg-json + env: + CI: true + + name: Javascript, CSS, and package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b668faa --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules +vendor +build +.DS_Store +.vscode diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..b009dfb --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +lts/* diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b4f53f --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# WordPress Code Examples Starter + +This template repository is pre-configured to provide all of the tools to format code to match the WordPress coding standards. + + +## What does it provide? + +1. Linting and formatting tools for PHP, JavaScript, CSS and package.json files. +2. A GitHub action to that runs linting on PRs and merged to trunk. +3. Build process provided by `@wordpress/scripts` + +## How do I use it? +1. Start by clicking the `Use this template` to use this as a starting point for your project. +2. Run `npm run setup` to install everything. +3. If using VSCode add the following to your settings.json +```json +"editor.codeActionsOnSave": { + "source.fixAll.eslint": true +}, +``` + diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..816c14e --- /dev/null +++ b/composer.json @@ -0,0 +1,18 @@ +{ + "name": "ryanwelcher/wordpress-project-template", + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", + "squizlabs/php_codesniffer": "^3.6", + "wp-coding-standards/wpcs": "^2.3" + }, + "scripts": { + "lint": "./vendor/bin/phpcs --standard=phpcs.xml" + }, + "config": { + "allow-plugins": { + "squizlabs/php_codesniffer": true, + "dealerdirect/phpcodesniffer-composer-installer": true, + "wp-coding-standards/wpcs": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..f5e6f58 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "wordpress-project-template", + "version": "0.1.0", + "description": "A starting point for WordPress projects", + "author": "Ryan Welcher", + "license": "GPL-2.0-or-later", + "main": "build/index.js", + "scripts": { + "setup": "npm install --force && composer install", + "build": "wp-scripts build", + "format": "wp-scripts format", + "lint:css": "wp-scripts lint-style", + "lint:js": "wp-scripts lint-js", + "lint:pkg-json": "wp-scripts lint-pkg-json", + "format:js": "wp-scripts format", + "packages-update": "wp-scripts packages-update", + "plugin-zip": "wp-scripts plugin-zip", + "start": "wp-scripts start" + }, + "prettier": "@wordpress/prettier-config", + "devDependencies": { + "@wordpress/scripts": "^23.1.0", + "eslint-plugin-prettier": "^4.0.0", + "prettier": "npm:wp-prettier@2.2.1-beta-1" + } +} diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..d94ddfe --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,9 @@ + + + + + . + + */vendor/* + */build/* + diff --git a/src/.gitkeep b/src/.gitkeep new file mode 100644 index 0000000..e69de29