From e7d5da3eb266cf1febc33fdfdb9e504766ad4e6f Mon Sep 17 00:00:00 2001 From: Timotei Date: Tue, 17 Sep 2024 00:27:20 +0300 Subject: [PATCH 1/3] Add code sniffer --- .github/workflows/ci.yml | 23 +++++- .gitignore | 1 + .prettierignore | 6 ++ .prettierrc | 14 +++- composer.json | 13 ++++ composer.lock | 161 +++++++++++++++++++++++++++++++++++++++ phpcs.xml.dist | 62 +++++++++++++++ 7 files changed, 273 insertions(+), 7 deletions(-) create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 phpcs.xml.dist diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43e3edcf4..b38bd4b03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,19 +8,36 @@ on: - 'v*.*' pull_request: +# Cancels all previous workflow runs for pull requests that have not completed. +# concurrency: +# group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} +# cancel-in-progress: true + jobs: - test: + check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + # Initialize Cache Composer + - name: Cache Composer dependencies + uses: actions/cache@v3 + with: + path: .cache + key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} + + # Initialize Node.js - uses: actions/setup-node@v3 with: - node-version: '20' + node-version: '22' check-latest: true cache: npm cache-dependency-path: package-lock.json - - run: npm ci + # Start actions + - run: mkdir -p .cache + - run: composer install + - run: composer run sniff-check + - run: npm ci - run: npm run format-check diff --git a/.gitignore b/.gitignore index 5ac2a3cc3..e656415ed 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ .env* .vscode node_modules +/vendor diff --git a/.prettierignore b/.prettierignore index c5ec21291..32f938100 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,6 +1,12 @@ **/*.min.* **/*.ori.* **/*.tpl.php +composer.json +composer.lock +package.json +package-lock.json +vendor +.cache assets/js/css_async.js assets/js/webfontloader.js lib diff --git a/.prettierrc b/.prettierrc index 09fdb315e..369199fce 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,14 +2,20 @@ "overrides": [ { "files": ".prettierrc", - "options": { "parser": "json" } + "options": { + "parser": "json" + } }, { "files": "**/*.{yml,yaml}", - "options": { "tabWidth": 2 } + "options": { + "tabWidth": 2 + } } ], - "plugins": ["@prettier/plugin-php"], + "plugins": [ + "@prettier/plugin-php" + ], "arrowParens": "avoid", "braceStyle": "per-cs", "endOfLine": "auto", @@ -21,4 +27,4 @@ "trailingComma": "all", "trailingCommaPHP": true, "useTabs": true -} +} \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 000000000..79acec1ff --- /dev/null +++ b/composer.json @@ -0,0 +1,13 @@ +{ + "name": "litespeedtech/lscache_wp", + "require-dev": { + "squizlabs/php_codesniffer": "*", + "phpcompatibility/php-compatibility": "*" + }, + "prefer-stable": true, + "scripts": { + "post-install-cmd": "phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility", + "post-update-cmd": "phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility", + "sniff-check": "phpcs --standard=./phpcs.xml.dist" + } +} \ No newline at end of file diff --git a/composer.lock b/composer.lock new file mode 100644 index 000000000..39c17ed3a --- /dev/null +++ b/composer.lock @@ -0,0 +1,161 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "21330dd959c1642a4c7dbc91aa5effef", + "packages": [], + "packages-dev": [ + { + "name": "phpcompatibility/php-compatibility", + "version": "9.3.5", + "source": { + "type": "git", + "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243", + "reference": "9fb324479acf6f39452e0655d2429cc0d3914243", + "shasum": "" + }, + "require": { + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" + }, + "conflict": { + "squizlabs/php_codesniffer": "2.6.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", + "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Wim Godden", + "homepage": "https://github.com/wimg", + "role": "lead" + }, + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" + } + ], + "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", + "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", + "keywords": [ + "compatibility", + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues", + "source": "https://github.com/PHPCompatibility/PHPCompatibility" + }, + "time": "2019-12-27T09:44:58+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.10.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", + "reference": "86e5f5dd9a840c46810ebe5ff1885581c42a3017" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/86e5f5dd9a840c46810ebe5ff1885581c42a3017", + "reference": "86e5f5dd9a840c46810ebe5ff1885581c42a3017", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" + }, + "bin": [ + "bin/phpcbf", + "bin/phpcs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "Former lead" + }, + { + "name": "Juliette Reinders Folmer", + "role": "Current lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", + "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", + "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", + "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-07-21T23:26:44+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": true, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.6.0" +} diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 000000000..32d688516 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,62 @@ + + + Apply LiteSpeed Cache Coding Standards to all plugin files + + + + + + + + + + + + + + + + + + + + + + + + . + + + ^wordpress/* + + + /node_modules/* + /vendor/* + + + + + + + + + + + + From dfe6954acfe64503eba749cd2f54bb76c52d4aba Mon Sep 17 00:00:00 2001 From: Timotei Date: Tue, 17 Sep 2024 12:03:23 +0300 Subject: [PATCH 2/3] Review changes --- .github/workflows/ci.yml | 10 ++-------- .prettierrc | 12 +++--------- composer.json | 2 +- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b38bd4b03..6e5476629 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,26 +8,20 @@ on: - 'v*.*' pull_request: -# Cancels all previous workflow runs for pull requests that have not completed. -# concurrency: -# group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} -# cancel-in-progress: true - jobs: check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - # Initialize Cache Composer - name: Cache Composer dependencies uses: actions/cache@v3 with: path: .cache key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} - # Initialize Node.js - - uses: actions/setup-node@v3 + - name: Initialize Node.js + uses: actions/setup-node@v3 with: node-version: '22' check-latest: true diff --git a/.prettierrc b/.prettierrc index 369199fce..35955524a 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,20 +2,14 @@ "overrides": [ { "files": ".prettierrc", - "options": { - "parser": "json" - } + "options": { "parser": "json" } }, { "files": "**/*.{yml,yaml}", - "options": { - "tabWidth": 2 - } + "options": { "tabWidth": 2 } } ], - "plugins": [ - "@prettier/plugin-php" - ], + "plugins": ["@prettier/plugin-php"], "arrowParens": "avoid", "braceStyle": "per-cs", "endOfLine": "auto", diff --git a/composer.json b/composer.json index 79acec1ff..8f75b48be 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,6 @@ "scripts": { "post-install-cmd": "phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility", "post-update-cmd": "phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility", - "sniff-check": "phpcs --standard=./phpcs.xml.dist" + "sniff-check": "phpcs" } } \ No newline at end of file From b7fee13f385f426dfdd03705f5cb891a8cf02bd6 Mon Sep 17 00:00:00 2001 From: Timotei Date: Tue, 17 Sep 2024 18:34:29 +0300 Subject: [PATCH 3/3] Changes --- .github/workflows/ci.yml | 2 +- .prettierrc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e5476629..ed2c5e9b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,5 +33,5 @@ jobs: - run: composer install - run: composer run sniff-check - - run: npm ci + - run: npm clean-install - run: npm run format-check diff --git a/.prettierrc b/.prettierrc index 35955524a..09fdb315e 100644 --- a/.prettierrc +++ b/.prettierrc @@ -21,4 +21,4 @@ "trailingComma": "all", "trailingCommaPHP": true, "useTabs": true -} \ No newline at end of file +}