bashman
bashman

Reputation: 138

Ignore or bypass errors phpcs

How to bypass or ignore specific errors/warnings in vscode?, I am using phpcs.

enter image description here

Upvotes: 3

Views: 7364

Answers (2)

Muhammad Omer Aslam
Muhammad Omer Aslam

Reputation: 23788

What you are looking for is to ignore the warning and/or errors, that are notified by the phpcs in the console of the vscode.

For Warnings

Use the following config in your settings.json

"phpcs.showWarnings": false,

this will remove all the warnings displayed in the output console.

For Errors

You should go trough the DOCS for complete details but to remove the errors related to the Doc block and the formatting standards you can set the

"phpcs.errorSeverity": 6,

Although it is mostly used for testing or code reviews to check for total warnings and errors by setting different values for both, but for development i dont do that and keep it to the default value that is 5 but you can get rid of those errors above in your image.

Upvotes: 5

VonC
VonC

Reputation: 1329562

The vscode-phpcs refers to the GitHub project squizlabs/PHP_CodeSniffer, which integrates PHP_CodeSniffer into VSCode.

Its readme mentions the setting phpcs.ignorePatterns:

An array of glob patterns to skip files and folders that match when linting your documents.

{
    "phpcs.ignorePatterns": [
        "*/ignored-file.php",
        "*/ignored-dir/*"
    ]
}

That refers to PHP CodeSniffer --ignore option.

That is not what you want exactly, since it ignores all errors on a given set of file.

But you could use PHP CodeSniffer syntax to ignore errors:

Ignoring Parts of a File

Some parts of your code may be unable to conform to your coding standard. For example, you might have to break your standard to integrate with an external library or web service.
To stop PHP_CodeSniffer generating errors for this code, you can wrap it in special comments. PHP_CodeSniffer will then hide all errors and warnings that are generated for these lines of code.

$xmlPackage = new XMLPackage;
// phpcs:disable
$xmlPackage['error_code'] = get_default_error_code_value();
$xmlPackage->send();
// phpcs:enable

Again, not exactly what you want, since you have to specify that on a file-by-file basis

You can disable multiple error message codes, sniff, categories, or standards by using a comma separated list.
You can also selectively re-enable just the ones you want.

The following example disables the entire PEAR coding standard, and all the Squiz array sniffs, before selectively re-enabling a specific sniff. It then re-enables all checking rules at the end.

// phpcs:disable PEAR,Squiz.Arrays
$foo = [1,2,3];
bar($foo,true);
// phpcs:enable PEAR.Functions.FunctionCallSignature
bar($foo,false);
// phpcs:enable

Upvotes: 1

Related Questions