简体   繁体   English

如何从PHPStorm中的代码检查中排除文件/文件夹?

[英]How to exclude files/folders from code inspection in PHPStorm?

I have a project in PHPStorm, which contains a few libraries (Zend, Doctrine, ...) grouped under a library folder. 我在PHPStorm中有一个项目,它包含一些在library文件夹下分组的库(Zend,Doctrine,...)。

When running the code inspection, I do want the PHP code in these folders to be analysed (so that PHPStorm will know how Zend_Form is declared, for example). 在运行代码检查时,我确实希望分析这些文件夹中的PHP代码(例如,PHPStorm将知道如何声明Zend_Form )。

However, I do not want the issues found in these folders to be reported, as they are out of my control. 但是,我希望报告这些文件夹中发现的问题,因为它们不受我的控制。

The only workaround I've found so far is to mark the directories as "Test source", and uncheck the "Include test sources" box in the code inspection window. 到目前为止,我发现的唯一解决方法是将目录标记为“测试源”,并取消选中代码检查窗口中的“包含测试源”框。 Needless to say that this is not the best solution! 毋庸置疑,这不是最好的解决方案!

If you just need to disable inspections on one or two files, you can disable it at the file level easily: 如果您只需要禁用一个或两个文件的检查,则可以轻松地在文件级别禁用它:

  1. Open offending file 打开违规文件
  2. Click 'Code' -> 'Configure Current File Analysis' 点击“代码” - >“配置当前文件分析”
  3. Set slider for offending language to 'None' 将违规语言的滑块设置为“无”

(Using PHPStorm 8.0.2) (使用PHPStorm 8.0.2)

Please refer to the Scopes feature . 请参阅范围功能 You can define a custom scope for just your code, without the library folder, then run inspections on this scope only. 您可以仅为代码定义自定义范围,而不使用库文件夹,然后仅在此范围上运行检查。

In the Inspections settings it's also possible to add the scopes and enable/disable each inspection per scope. Inspections设置中 ,还可以添加范围并启用/禁用每个范围的每个检查。

If you need to completely exclude few files from any analyse (for example a compiled php file) like it not even exist, you can right click on file in source tree and select "Mark as Plain Text". 如果您需要完全排除任何分析中的少量文件(例如编译的php文件),就像它甚至不存在一样,您可以右键单击源树中的文件并选择“标记为纯文本”。 This action totally remove any inspections on this file. 此操作完全删除对此文件的任何检查。 With this I removed a lot of notifications about "source duplications" in Laravel 5. 有了这个,我在Laravel 5中删除了很多关于“源复制”的通知。

If you need to activate it again - once more right click and "Mark as PHP". 如果您需要再次激活它 - 再次右键单击并“标记为PHP”。

This works nice for a few files. 这适用于几个文件。 If you need to exclude whole directory with everything inside, use directory marking from settings or right click on directory and "Mark Directory As -> Excluded". 如果您需要排除包含所有内容的整个目录,请使用设置中的目录标记或右键单击目录并“将目录标记为 - >排除”。

There is alternative solution. 有替代解决方案。 You can add «read-only» libraries to Include path in Settings » PHP section. 您可以在Settings » PHP部分中添加«只读»库以Include path

It is not the same with php.ini include_path option, just referencing to some dirs as external, outside of your control. 这是不是 php.ini中的相同include_path选项,只是引用到一些目录外部,你的控制范围之外。 Exactly what you need. 正是你需要的。

As result 结果

  • no problems with scopes defining, just inspect whole project, if needed 没有问题的范围定义,只需检查整个项目,如果需要
  • no useless version control overhead in libs libs中没有无用的版本控制开销

If you want to totally exclude a file or folder from completion and code help: 如果要从完成和代码帮助中完全排除文件或文件夹:
Right click the folder or file in your file browser (left handed) choose "Mark"-> "excluded" 右键单击文件浏览器中的文件夹或文件(左手)选择“标记” - >“排除”

That's what I wanted, I add that answer here because I found this question in Google when looking for an answer. 这就是我想要的,我在这里添加了答案,因为我在寻找答案时在Google中发现了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM