This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 258832 - Code Sniffer does not support default project config file phpcs.xml
Summary: Code Sniffer does not support default project config file phpcs.xml
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Project (show other bugs)
Version: 8.1
Hardware: All All
: P3 normal (vote)
Assignee: Tomas Mysik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-14 15:43 UTC by simohe
Modified: 2016-04-20 01:49 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description simohe 2016-04-14 15:43:36 UTC
Recent php code sniffer (phpcs) loads phpcs.xml or phpcs.xml.dist form the current directory (or any parent directory, see [1]). But when configuring code sniffer in  options, I have to select a coding standard which overwrites this settings (because --standard=XXX disables looking for default configuration).

Please allow to select no standard (for loading the default),
or/and to select a path as standard (is supported by --standard, see [2]).

[1] https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a-default-configuration-file
[2] https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage#specifying-a-coding-standard
Comment 1 Tomas Mysik 2016-04-15 05:39:35 UTC
Could you please attach a sample project and provide exact steps to reproduce? Just to ensure that NetBeans will support it correctly.

Thanks for reporting.
Comment 2 Tomas Mysik 2016-04-15 05:42:48 UTC
More bug than enhancement.
Comment 3 simohe 2016-04-18 07:59:50 UTC
As a project using phpcs.xml.dist we can take PHP_CodeSniffer as an example:
  https://github.com/squizlabs/PHP_CodeSniffer/

When running "phpcs any/file.php" in the console in a directory of the project (the root folder, CodeSniffer/DocGenerators/, ...) the phpcs.xml.dist is used. This is what I expect to happen inside netbeans as well.


steps:
 * clone or copy https://github.com/squizlabs/PHP_CodeSniffer/
 * create new php project in netbeans, select "PHP Application with Existing Sources", select "PHP_CodeSniffer" as source (and finish the assistant)
 * open a php file (example CodeSniffer/DocGenerators/Generator.php)
 * (to be sure to see wrong configuration, go in menu Tools->Options, then to "PHP, Tab "Code Analysis", select "Code Sniffer"; select Zend as Default standard)
 * in Menu, select Source->Inspect
 * in the dialogue, select "Code Sniffer" as configuration and continue (click "Inspect")
Expected: phpcs.xml.dist is used, you should see no errors in the results
Current: --standard=Zend is used, many errors in the results


Is this helpful? Or do you prefer a repo with phpcs.xml.dist and nbproject/ included?
Comment 4 Tomas Mysik 2016-04-18 09:18:51 UTC
(In reply to simohe from comment #3)
> Expected: phpcs.xml.dist is used, you should see no errors in the results
> Current: --standard=Zend is used, many errors in the results

So, does it mean that if phpcs.xml[.dist] file exists in the project directory, NetBeans should not use CLI param --standard? Is it correct? In all situations? Or only sometimes (if e.g. standard is not defined in the XML file, if possible)?

> Is this helpful? Or do you prefer a repo with phpcs.xml.dist and nbproject/
> included?

I guess the steps you provided should be enough, will let you know if not.

Thanks for it! I will get to it quite soon I hope, definitely will try to fix it for the next stable version of NetBeans.

Thanks for reporting.
Comment 5 simohe 2016-04-19 10:03:25 UTC
Right, it will work like you describe.

Alternative to checking if phpcs.xml{,.dist} exists: do not provide "--standard XXX" but "--runtime-set default_standard XXX". Then XXX is used when no standard config file is found.

I generally do not see why I am forced to provide a value for --standard. phpcs has a default standard. I can change it with phpcs --config-set default_standard XXX.
(And --standard would also allow a path to a config file or multiple standards [1])


Thank you very much for looking into this.


[1] https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage#specifying-a-coding-standard
Comment 6 simohe 2016-04-19 13:23:53 UTC
Note: The working directory of the phpcs process must be the project root (or the directory containing the file being checked).
Comment 7 Tomas Mysik 2016-04-19 13:37:27 UTC
Should be done now, please verify if possible. Please note that the config file must be in a project directory (at least this is the workdir of the command NetBeans runs).

Thanks.

http://hg.netbeans.org/web-main/rev/5a0809700013
Comment 8 Quality Engineering 2016-04-20 01:49:15 UTC
Integrated into 'main-silver', will be available in build *201604200001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/5a0809700013
User: Tomas Mysik <tmysik@netbeans.org>
Log: #258832 - Code Sniffer does not support default project config file phpcs.xml