Hi, I've read some questions on stackoverflow about the --ignore switch but I can't make it work. I've tried --ignore=_/directory/_ --ignore=directory --ignore=directory --ignore=/directory and a few else with no success. The command line says --ignore=
I've noticed that in CLI.php there's a preg_split with a regex '/(?<=(?
Can one example be provided that will make the ignore switch work?
Thanks
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-files-and-folders
--ignore=*directory/*
If you want to ignore your tests directory, use something like --ignore=*/tests/*. The option takes a regex, but allows you to use * instead of .* to make it a bit easier to read when ignoring extensions, such as --ignore=*.js.
I have tried the */directory/* pattern (my bad, I did not use the markdown and the asterisks got lost) and it still did not work. I'll give it another go later by directly testing it via command line, I was testing it inside an Ant file.
Ok, it seem that the args are being parsed correctly, but the directory is not being ignored. I have a vendor folder in my project root dir, if I pass ignore=_/vendor/_ it is still processing files inside the vendor directory.
Even though the parsed pattern is shown as ignored:
Ignored patterns: ignore=*/vendor/*
It is showing the following messages:
[exec] Notice: Undefined index: in D:\Users\marcelofilho\dev\projetos\siscebas2\fontes\vendor\squizlabs\php_codesniffer\CodeSniffer\File.php on line 3464
Oh, nevermind... The above notice is from the execution itself, it is not a problem being reported from CodeSniffer but from PHP, right? I guess that if I disable the notices it will go away...
That's what happens when people do not read the messages correctly.
Thanks for the help and answers.
So are your ignore patterns working now?
The PHP notice you got might be a symptom of a PHPCS bug. If you can replicate it, you can use the -v command line argument to show each file being processed and then determine which one is causing the issue. You'd see something like this:
Changing into directory /path/to/my/code
*snip*
Processing Test.php [PHP => 205 tokens in 51 lines]... PHP Notice: Undefined index: in D:\Users\marcelofilho\dev\projetos\siscebas2\fontes\vendor\squizlabs\php_codesniffer\CodeSniffer\File.php on line 3464
Which then lets you know that the file causing problems is /path/to/my/code/Test.php. If checking that file individually also gives you the error, it would be great to have a look at the file (if possible) to see if there is a problem with PHPCS.
I guess the patterns always did work :). I was misinterpreting the output.
I just did what you asked (ran phpcs using the -v switch) and found the culprit. It is actually a javascript file, one that should also be excluded from the analysis since it's an external file (Closure Library - https://github.com/google/closure-library). I tried to attach the file, but it wasn't possible. Anyway I guess it's an old version, since this is an ancient legacy code (the one being analysed).
The first error (notice) is:
"Processing entry.js [JS => 3985 tokens in 534 lines]...
Notice: undefined index: scope_condition in (...)vendorsquizlabsphp_codesnifferCodeSnifferStandardsGenericSniffsWhiteSpaceScopeIndentSniff.php on line 417"
Then it goes on forever like this:
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3476
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3476
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3476
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3476
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3476
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3476
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3476
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3476
Notice: Undefined index: in (...)vendorsquizlabsphp_codesnifferCodeSnifferFile.php on line 3464
Thanks for doing that testing. I tried running PHPCS over the two files called entry.js in that project and I'm not getting any errors, so I'll close this issue for now. Excluding that file from your checks is the right thing to be doing anyway, as you've said.
Are the wildcards necessary? When I do
<exclude-pattern>/temp/</exclude-pattern>
it seems to do the same thing as
<exclude-pattern>*/temp/*</exclude-pattern>
It's quite an important detail because of how PhpStorm invokes PHPCS so I'd like to confirm that. Thank you.
@borekb No, wildcards are not necessary in this case, although most people add them for clarity.
The matching is done via preg_match(). Without the *, the regex match would just act like a normal substring match. The patterns we are comparing are .*/temp/.* and /temp/, both with the i modifier, so they'll do the same thing.
@gsherwood Thanks.
Most helpful comment
@borekb No, wildcards are not necessary in this case, although most people add them for clarity.
The matching is done via
preg_match(). Without the*, the regex match would just act like a normal substring match. The patterns we are comparing are.*/temp/.*and/temp/, both with theimodifier, so they'll do the same thing.