如何让phpcs忽略PHP Storm中的一些文件?

时间:2022-02-05 07:19:52

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

我已经设置了PHP Storm以使用phpcs并在我违反样式时在IDE中显示我。

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.

但是,我想为视图文件禁用它 - 它们通常包含与HTML混合的PHP,与样式指南不匹配,我不关心视图文件。

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.

在选项中,我在phpcs设置中看到了排除文件的列表,但它只有删除文件或清除整个列表的按钮,但没有办法将文件添加到它。

Am I missing it somewhere?

我在某处错过了吗?

4 个解决方案

#1


15  

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:

Code Sniffer(以及Mess Detector)集成以检查的形式实现,可以根据范围配置为ON或OFF。因此:

  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

    设置|检查| PHP | PHP Code Sniffer验证 - 右键单击​​它并选择Add Scope

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

    现在配置此检查:关闭(取消选中)该范围,并为“Everywhere else”条目保留ON。

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).

附: PhpStorm v8对Inspections设置屏幕进行了一些重新设计;因此步骤略有不同,但总体上仍然相同(现在用户更容易发现“范围”功能)。

#2


4  

This has been tested for PHPStorm 2017.*

这已经过PHPStorm 2017的测试。*

  1. Settings/Preferences | Keymap

    设置/首选项|按键图

    find Add to PHPCS ignore list key and add Keyboard Shortcut 如何让phpcs忽略PHP Storm中的一些文件?

    找到添加到PHPCS忽略列表键并添加键盘快捷方式

  2. Go to the file, which one you want to add as ignored and use the shortcut 如何让phpcs忽略PHP Storm中的一些文件?

    转到要添加为忽略的文件,然后使用快捷方式

#3


2  

With PHPStorm 8, you can find the Code Sniffer settings panel in:

使用PHPStorm 8,您可以在以下位置找到Code Sniffer设置面板:

Settings | Languages and Frameworks | PHP | Code Sniffer

设置|语言和框架| PHP | Code Sniffer

In this panel, you will find a list of ignored files.

在此面板中,您将找到被忽略文件的列表。

Edit: with PHPStorm 2016.x, this list is read only, you can't add ignore files this way.

编辑:使用PHPStorm 2016.x,此列表是只读的,您不能以这种方式添加忽略文件。

#4


0  

You can customise the toolbar to include a button for the "Add to PHPCS ignore list" action.

您可以自定义工具栏以包含“添加到PHPCS忽略列表”操作的按钮。

  1. View > Toolbar to display the toolbar if it's hidden.
  2. 查看>工具栏,以显示隐藏的工具栏。

  3. Mouse-right on toolbar, then "Customise Menus and Toolbars".
  4. 鼠标右键放在工具栏上,然后“自定义菜单和工具栏”。

  5. Select "Main Toolbar" and add the action as a button.
  6. 选择“主工具栏”并将操作添加为按钮。

Or customise the Editor Tab Popup Menu and add "Add to PHPCS ignore list" there (It'll be hidden for files already on the list).

或者自定义“编辑器”选项卡弹出菜单,并在那里添加“添加到PHPCS忽略列表”(它将隐藏在列表中已有的文件中)。

#1


15  

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:

Code Sniffer(以及Mess Detector)集成以检查的形式实现,可以根据范围配置为ON或OFF。因此:

  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

    设置|检查| PHP | PHP Code Sniffer验证 - 右键单击​​它并选择Add Scope

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

    现在配置此检查:关闭(取消选中)该范围,并为“Everywhere else”条目保留ON。

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).

附: PhpStorm v8对Inspections设置屏幕进行了一些重新设计;因此步骤略有不同,但总体上仍然相同(现在用户更容易发现“范围”功能)。

#2


4  

This has been tested for PHPStorm 2017.*

这已经过PHPStorm 2017的测试。*

  1. Settings/Preferences | Keymap

    设置/首选项|按键图

    find Add to PHPCS ignore list key and add Keyboard Shortcut 如何让phpcs忽略PHP Storm中的一些文件?

    找到添加到PHPCS忽略列表键并添加键盘快捷方式

  2. Go to the file, which one you want to add as ignored and use the shortcut 如何让phpcs忽略PHP Storm中的一些文件?

    转到要添加为忽略的文件,然后使用快捷方式

#3


2  

With PHPStorm 8, you can find the Code Sniffer settings panel in:

使用PHPStorm 8,您可以在以下位置找到Code Sniffer设置面板:

Settings | Languages and Frameworks | PHP | Code Sniffer

设置|语言和框架| PHP | Code Sniffer

In this panel, you will find a list of ignored files.

在此面板中,您将找到被忽略文件的列表。

Edit: with PHPStorm 2016.x, this list is read only, you can't add ignore files this way.

编辑:使用PHPStorm 2016.x,此列表是只读的,您不能以这种方式添加忽略文件。

#4


0  

You can customise the toolbar to include a button for the "Add to PHPCS ignore list" action.

您可以自定义工具栏以包含“添加到PHPCS忽略列表”操作的按钮。

  1. View > Toolbar to display the toolbar if it's hidden.
  2. 查看>工具栏,以显示隐藏的工具栏。

  3. Mouse-right on toolbar, then "Customise Menus and Toolbars".
  4. 鼠标右键放在工具栏上,然后“自定义菜单和工具栏”。

  5. Select "Main Toolbar" and add the action as a button.
  6. 选择“主工具栏”并将操作添加为按钮。

Or customise the Editor Tab Popup Menu and add "Add to PHPCS ignore list" there (It'll be hidden for files already on the list).

或者自定义“编辑器”选项卡弹出菜单,并在那里添加“添加到PHPCS忽略列表”(它将隐藏在列表中已有的文件中)。