From c90d97fa541068786f85bff4d458575bba2aee71 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 12 Nov 2023 03:10:16 +0100 Subject: [PATCH] 4.0 | Wiki: update for removal of CSS/JS support in sniffs --- wiki/Advanced-Usage.md | 6 +++++- wiki/Coding-Standard-Tutorial.md | 28 +++++++++++++++------------- wiki/FAQ.md | 4 +--- wiki/Home.md | 2 +- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/wiki/Advanced-Usage.md b/wiki/Advanced-Usage.md index 25bc73e..6a58c7d 100644 --- a/wiki/Advanced-Usage.md +++ b/wiki/Advanced-Usage.md @@ -7,7 +7,7 @@ ## Specifying Valid File Extensions -By default, PHP_CodeSniffer will check any file it finds with a `.inc`, `.php`, `.js` or `.css` extension, although not all standards will actually check all these file types. Sometimes, this means that PHP_CodeSniffer is not checking enough of your files. Sometimes, the opposite is true. PHP_CodeSniffer allows you to specify a list of valid file extensions using the `--extensions` command line argument. Extensions are separated by commas. +By default, PHP_CodeSniffer will check any file it finds with an `.inc` or `.php` extension. Sometimes, this means that PHP_CodeSniffer is not checking enough of your files. Sometimes, the opposite is true. PHP_CodeSniffer allows you to specify a list of valid file extensions using the `--extensions` command line argument. Extensions are separated by commas. To only check `.php` files: ```bash @@ -19,6 +19,10 @@ To check `.php`, `.inc` and `.lib` files: $ phpcs --extensions=php,inc,lib /path/to/code ``` +> [!NOTE] +> Prior to PHP_CodeSniffer 4.0.0, `.css` and `.js` files were also scanned by default, though only a limited number of sniffs included support for scanning JS and CSS files. +> Support for CSS and JavaScript file scanning was removed in PHP_CodeSniffer 4.0.0. +

back to top

diff --git a/wiki/Coding-Standard-Tutorial.md b/wiki/Coding-Standard-Tutorial.md index c3d3511..0766af0 100644 --- a/wiki/Coding-Standard-Tutorial.md +++ b/wiki/Coding-Standard-Tutorial.md @@ -143,19 +143,21 @@ final class DisallowHashCommentsSniff implements Sniff } ``` -By default, PHP_CodeSniffer assumes all sniffs are designed to check PHP code only. You can specify a list of tokenizers that your sniff supports, allowing it to be used with PHP, JavaScript or CSS files, or any combination of the three. You do this by setting the `$supportedTokenizers` property in your sniff. Adding the following code to your sniff will tell PHP_CodeSniffer that it can be used to check both PHP and JavaScript code: - -```php -/** - * A list of tokenizers this sniff supports. - * - * @var array - */ -public $supportedTokenizers = [ - 'PHP', - 'JS', -]; -``` +> [!NOTE] +> Since PHP_CodeSniffer 4.0.0, scanning JavaScript or CSS files is no longer supported. +> Prior to PHP_CodeSniffer 4.0.0, PHP_CodeSniffer assumed, by default, that all sniffs were designed to check PHP code only, but you could specify a list of tokenizers that your sniff supported, allowing it to be used with PHP, JavaScript or CSS files, or any combination of these. You indicated this by setting the `$supportedTokenizers` property in your sniff. So if you see the following code in a sniff for PHP_CodeSniffer < 4.0, this tells PHP_CodeSniffer that it can be used to check both PHP and JavaScript code: +> +> ```php +> /** +> * A list of tokenizers this sniff supports. +> * +> * @var array +> */ +> public $supportedTokenizers = [ +> 'PHP', +> 'JS', +> ]; +> ```

back to top

diff --git a/wiki/FAQ.md b/wiki/FAQ.md index 7da03c4..d60a878 100644 --- a/wiki/FAQ.md +++ b/wiki/FAQ.md @@ -55,8 +55,6 @@ Always run PHP_CodeSniffer until you get a passing result. Once you've made the ## What does PHP_CodeSniffer use to tokenize my code? -For PHP files, PHP_CodeSniffer uses [PHP's inbuilt tokenizer functions](http://www.php.net/tokenizer) to parse your code. It then modifies that output to include much more data about the file, such as matching function braces to function keywords. - -For all other file types, PHP_CodeSniffer includes a custom tokenizer that either makes use of PHP's inbuilt tokenizer or emulates it. In both cases, the token array must be checked and changed manually before all the standard PHP_CodeSniffer matching rules are applied, making tokenizing a bit slower for these file types. +PHP_CodeSniffer uses [PHP's inbuilt tokenizer functions](http://www.php.net/tokenizer) to parse your code. It then modifies that output to include much more data about the file, such as matching function braces to function keywords.

back to top

diff --git a/wiki/Home.md b/wiki/Home.md index 6d94d67..c9d5cc0 100644 --- a/wiki/Home.md +++ b/wiki/Home.md @@ -1,5 +1,5 @@ PHP_CodeSniffer is a set of two PHP scripts: -1. the main [`phpcs` script](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Usage) that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard; and +1. the main [`phpcs` script](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Usage) that tokenizes PHP files to detect violations of a defined coding standard; and 2. a [`phpcbf` script](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Fixing-Errors-Automatically) to automatically correct detected coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.