squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

Feature Requst: Overwrite File locations #3892

Open MakerTim opened 11 months ago

MakerTim commented 11 months ago

Context

At places like https://github.com/squizlabs/PHP_CodeSniffer/blob/7566b4d89de1d08d2a8ad85910507d6633a35d28/src/Reports/Code.php#L169 we report the full file location. basepath is a config property that can be used to remove it, but doesn't fully work for this. In our pipelines we have another path then in develop. And not every developer has the same prefix, nginx/apache locations vary. So supporting multiple is needed to fix this for us.

To reproduce

In an apache docker container php cbf And see a File with /var/www/html/... In a nginx container /usr/share/nginx/html/... On bitbucket pipelines /opt/atlassian/pipelines/agent/build/...

The set to support is for us these 3, but currently unable to fix this natively

Work around

is use | sed and remove this prefix, but the substring process makes this process not reliable. https://github.com/squizlabs/PHP_CodeSniffer/blob/7566b4d89de1d08d2a8ad85910507d6633a35d28/src/Reports/Code.php#L171

Please confirm:

jrfnl commented 11 months ago

@MakerTim How are you setting the basepath ?

I normally use the below and would expect that to work exactly like you intend it for the situation you describe:

    <!-- Strip the directory the PHPCS config file lives in from the filepath. -->
    <arg name="basepath" value="./"/>