Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make phpcs ignore some files in PHP Storm?

Tags:

php

phpstorm

I've set up PHP Storm to use phpcs and show me in the IDE when I've violated a style.

However, I'd like to disable this for view files -- they often contain bits of PHP mixed with HTML that don't match the style guide, and I don't care in a view file.

In the options, I see a list of excluded files in the phpcs settings, but it only has buttons to remove a file or clear the whole list, but no way to ADD files to it.

Am I missing it somewhere?

like image 652
Sean Avatar asked Oct 19 '13 19:10

Sean


People also ask

How do I ignore Phpcs?

With the following comments you can ignore whatever part of a file you would like. With // phpcs:ignore and // phpcs:disable you can also specify which messages, sniffs, categories or standards you would like to disable, for example: // phpcs:ignore Squiz.

How do I use CodeSniffer?

In the Settings dialog, go to Editor > Inspections. From the inspections screen, expand the PHP | Quality tools node and enable “PHP CodeSniffer validation”. In the configuration pane that is now enabled, select “Custom” from the “Coding standard” dropdown, locate the ruleset configuration ( phpcs.

What is CodeSniffer?

Code Sniffer is a static test that uses static code analysis to detect violations of the Magento Coding Standard to prevent common coding errors.


2 Answers

Code Sniffer (as well as Mess Detector) integration is implemented in form of an Inspection which can be configured to be ON or OFF based on scope. Therefore:

  1. Settings | Scopes -- create new custom scope and include all unwanted files/folders

  2. Settings | Inspections | PHP | PHP Code Sniffer validation -- right click on it and choose Add Scope

  3. Now configure this inspection: turn OFF (uncheck) for that scope and leave ON for "Everywhere else" entry.

P.S. PhpStorm v8 has Inspections settings screen a bit redesigned; therefore steps are tiny bit different, but still the same overall (now it's easier for user to discover "scopes" functionality).

like image 190
LazyOne Avatar answered Sep 20 '22 13:09

LazyOne


This has been tested for PHPStorm 2017.*

  1. Settings/Preferences | Keymap

    find Add to PHPCS ignore list key and add Keyboard Shortcut enter image description here

  2. Go to the file, which one you want to add as ignored and use the shortcut enter image description here

like image 21
Hayk Avatar answered Sep 20 '22 13:09

Hayk