Closed arturm11 closed 1 week ago
@arturm11 Thank you for this PR.
I've been able to reproduce the issue with PHPCS itself via the command line using something along the lines of:
phpcs --ignore=D:\path\to\PHP_CodeSniffer\src\Tokenizers\CSS.php
which results in a:
Warning: preg_match(): Compilation failed: unknown property after \P or \p at offset * in D:\path\to\PHP_CodeSniffer\src\Filters\Filter.php on line 278
And the change made in this PR fixes this. :+1:
Before I can accept the PR, could you please have a look at the third checklist item in the "PR checklist" ?
I'd also like to see this change safeguarded via tests. There are some tests for the Filters in the tests/Core/Filters
directory already. These could probably be expanded.
@jrfnl Now I am not sure. Please analyze Ignoring Files and Folders section in the wiki. It is stated, that filter can be treated as regular expression. Backslash character is special character for RE. Therefore Windows paths shouldn't be accepted and backslash should be converted to slash in Windows path on input.
There is related bug in vscode-php-sniffer, so I close this request. https://github.com/wongjn/vscode-php-sniffer/pull/73
@arturm11 Thanks for getting back to me. Hope that bug gets fixed soon.
Fixed bad pattern replacements. Eliminates warnings when used as PHP Sniffer extension in VSCode.
Description
If full Windows path is used as ignore filter in shouldIgnorePath() function, then conversion to PREG pattern was buggy. Windows backslash separator should be converted into double backslash (escaped backslash) AND Linux slash separator should be converted into double backslash.
Suggested changelog entry
Add backslash into double backslash replacement for Windows.
Related issues/external references
PHP Sniffer extension for VSCode generates warnings on Windows without this fix.
Types of changes
PR checklist