phpmd icon indicating copy to clipboard operation
phpmd copied to clipboard

Feature request: Ignoring a file using a comment

Open alexboss opened this issue 9 years ago • 12 comments

Dear PHP MD developers,

PHP MD uses doc comment annotations to exclude methods or classes from PHPMD or to suppress special rules for some software artifacts.

But, unless I'm not using it correctly, it is not possible to ignore an entire file.

Code sniffer allows it, see https://pear.php.net/manual/en/package.php.php-codesniffer.advanced-usage.php#package.php.php-codesniffer.advanced-usage.ignore-files-folders :

You can also tell PHP_CodeSniffer to ignore a file using a special comment inserted at the top of > the file. This will stop the file being checked even if it does not match the ignore pattern. Ignoring a file using a comment

<?php
// @codingStandardsIgnoreFile
$xmlPackage = new XMLPackage;
$xmlPackage['error_code'] = get_default_error_code_value();
$xmlPackage->send();
?>

Would it be possible to completely ignore a file ? either by putting the suppress warnings instructions at the top of file

// @SuppressWarnings(PHPMD)

or putting it in the file comment

/**
 * @file
 *
 * @SuppressWarnings(PHPMD)
 */

What do you think of this feature request?

Best regards,

Alexandre 8)

alexboss avatar Oct 07 '15 12:10 alexboss

@manuelpichler sounds good to me, though I would prefer the annotation tag to be more expressive.

ravage84 avatar Oct 07 '15 15:10 ravage84

Glad to see you are considering this feature request.

Just for the rationale behind it... in our projects we are using Code Sniffer and PHP MD for the QA phase. This is great to audit and fix the code we write. But we are also including several external classes / helpers that don't comply with all CS or MD rules / recommendations. In that case, they generate warnings and appear in the final report of the QA. We don't want to patch these external libraries as it would make the maintenance harder when they are upgraded to the latest versions, so we simply want to discard them from the QA and only apply the QA and CS / MD audits to the code we actually wrote.

Best regards,

Alexandre 8)

alexboss avatar Oct 08 '15 06:10 alexboss

Not sure what your setup is and how you work but quality of software should not be a "phase", instead should be an ongoing process. To achieve this you should look into continuous integration.

For PHP , get started with this: http://jenkins-php.org/

Doing so, you can exclude certain files and folders by using the --exclude CLI parameter. Check out: http://phpmd.org/documentation/index.html

Also, if you have third party code, consider using Composer, this way you only have to exclude the vendor folder.

ravage84 avatar Oct 08 '15 12:10 ravage84

Thanks @ravage84 for all these useful resources. We are not at this stage yet but very interesting to improve our workflow from a phase to an ongoing process.

Using the --exclude CLI parameter could make the trick for me, will check how it can be configured within Netbeans at the project level rather than globally.

alexboss avatar Oct 08 '15 14:10 alexboss

@alexboss what is your current stance on this feature request?

ravage84 avatar Jun 27 '16 12:06 ravage84

HI @ravage84 , thanks for your feedback. It's a nice-to-have feature, but we can live without it at the moment, there's really no rush.

alexboss avatar Jun 28 '16 14:06 alexboss

+1

fracz avatar Nov 16 '16 08:11 fracz

+1

brunobg avatar Aug 31 '17 14:08 brunobg

Any chances to get this feature into the next release? :-)

From my beginner perspective, like mentioned above with phpcs' solution. this really makes sense.

Because the most messed up files can be ignored temporarily to dig into the details using the less messy files.

EDIT: Found a workaround for phpStorm, there you can add files to a internal ignore list, provided by phpStorm. See manual

Maybe this helps in the meantime.

ffmit avatar Dec 05 '19 09:12 ffmit

We will probably not have it in 2.8.0. It's not a top-priority for the core team, but pull-requests are welcome. And landing in 2.9.0 remains probable.

kylekatarnls avatar Dec 05 '19 12:12 kylekatarnls

+1 for this feature :)

benconvey avatar Sep 08 '20 07:09 benconvey

You can propose a PR. The probable entry-point for this feature is src/main/php/PHPMD/Node/Annotation.php

kylekatarnls avatar Sep 08 '20 08:09 kylekatarnls