Skip to content

4.0 | Wiki: update for removal of CSS/JS support in sniffs #33

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
6 changes: 5 additions & 1 deletion wiki/Advanced-Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

<p align="right"><a href="#table-of-contents">back to top</a></p>


Expand Down
28 changes: 15 additions & 13 deletions wiki/Coding-Standard-Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
*/
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<string>
> */
> public $supportedTokenizers = [
> 'PHP',
> 'JS',
> ];
> ```

<p align="right"><a href="#table-of-contents">back to top</a></p>

Expand Down
4 changes: 1 addition & 3 deletions wiki/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<p align="right"><a href="#table-of-contents">back to top</a></p>
2 changes: 1 addition & 1 deletion wiki/Home.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -43,7 +43,7 @@
88 | ERROR | Line not indented correctly; expected 9 spaces but found 6
--------------------------------------------------------------------------------

FILE: /path/to/code/yourfile.php

Check warning on line 46 in wiki/Home.md

View workflow job for this annotation

GitHub Actions / Spellcheck

Unknown word (yourfile) Suggestions: (outfile, oupfile, outFile, Outfile, houtfile)

Check warning on line 46 in wiki/Home.md

View workflow job for this annotation

GitHub Actions / Spellcheck

Unknown word (yourfile) Suggestions: (outfile, oupfile, outFile, Outfile, houtfile)
--------------------------------------------------------------------------------
FOUND 1 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
Expand Down
Loading