PHP Code Sniffer in VS Code : How do I ignore a certain rule to avoid getting errors?

Asked

Viewed 233 times

2

I want to use php code Sniffer to study and at the same time force me to follow the standards of Psrs but I don’t want to follow the rule that forces me to comment on every file and every function I create.

This rule, in my view, is more disturbing than helping in a study environment. It generates error even in my autoload file and as I did not find an extension in VS Code that gives an autocomplete with the comments when I create a function or when I create a file . php want to remove this requirement from Sniffer code.

Follow the mistakes I get all the time:

Missing file doc comment (PEAR.Commenting.Filecomment.Missing)

Missing doc comment for Function autoload() (PEAR.Commenting.Functioncomment.Missing)

  • 1

    you can configure the rules that your project will follow by creating a configuration file (https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options). After configuring the rules according to your goal, configure your extension to use your rules.

  • 1

    within the Sniffer code directory I renamed the Codesniffer.conf.dist file to Codesniffer.conf and inside it is the config: <? php $phpCodeSnifferConfig = array ( 'default_standard' => 'PSR2', 'report_format' => 'Summary', 'show_warnings' => '0', 'show_progress' => '1', 'report_width' => '120', ) ? > Apparently now only the PSR-2 is working but I would like the others to work as well (Mysource, PEAR, PSR1, PSR12, PSR2, Squiz and Zend)

  • 1

    My idea is to just delete the PEAR.Filecomment.Missing and PEAR.Functioncomment.Missing rule. In phpcs.xml you have this possibility of rule deletion but apparently I’m doing it wrong because after adding the rules <exclude name="PEAR.Commenting.Filecomment"/> <exclude name="PEAR.Commenting.Functioncomment"/> Nothing happens

  • 1

    For convenience, I would only adopt the PSR-12, which already includes the PSR-1. What might be happening is your phpcs.xml file is not being considered by the extension.

  • 2

    I believe this is it even though I tried unsuccessfully to find out why it is being disregarded, my solution was exactly this when I specified the PSR-12 the PSR-1 and 2 are in operation and fair they already bring a pleasant to the code. Thank you for your attention and suggestions.

1 answer

2

Inside the Sniffer code directory I renamed the file CodeSniffer.conf.dist for CodeSniffer.conf and within it is the config:

<?php 

$phpCodeSnifferConfig = array ( 
    'default_standard' => 'PSR2', 
    'report_format' => 'summary', 
    'show_warnings' => '0', 
    'show_progress' => '1', 
    'report_width' => '120', 
) 

?>

In 'default_standard' I renamed the PSR2 attribute to PSR12 that covers other Psrs. Unfortunately this disables other patterns that php code Sniffer brings like PEAR more even so the change brought more readability to my codes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.