php - 如何编辑 vscode 的默认 php linter?

标签 php visual-studio-code

对于 JS,ESLint 具有为已赋值或已定义但从未使用的变量返回错误的功能。即

file: 'file:///home/mov-list.js'
severity: 'Error'
message: ''bar' is defined but never used. (no-unused-vars)'
at: '11,5'
source: 'eslint'  

|

file: 'file:///home/ajax222/mov-list.js'
severity: 'Error'
message: ''foo' is assigned a value but never used. (no-unused-vars)'
at: '20,5'
source: 'eslint'

从这里开始:https://code.visualstudio.com/docs/languages/php 。 Vscode 附带了默认的 PHP linter。

问题:我应该将哪个文件和什么代码添加到默认 PHP linter 中以返回两者的错误:
1. 声明但从未使用过的变量。
2. 变量已赋值但从未使用过。
就像它与 ESlint 一起工作一样。
或者我应该只关注其他特定的 PHP linter?

最佳答案

如上所述here ,VS Code默认使用默认的php linter。如果你想对官方的php linter进行改进,可以联系on github致 PHP 开发人员。

vscode 市场上还有另外两个 linter,其中一个使用 php code sniffer以及使用 php md 的一个.

Ppmd 应该能够捕获你想要的内容,如所述 here ,但您也可以创建 custom rules :

Unused Code Rules

UnusedPrivateField: Detects when a private field is declared and/or assigned a value, but not used.

UnusedLocalVariable: Detects when a local variable is declared and/or assigned, but not used.

UnusedPrivateMethod: Unused Private Method detects when a private method is declared but is unused.

UnusedFormalParameter: Avoid passing parameters to methods or constructors and then not using those parameters.

如果您不喜欢 phpmd 并且 Codesniffer linter 不能满足您的需要,它也可以按描述进行扩展 here .

关于php - 如何编辑 vscode 的默认 php linter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42645349/

相关文章:

php - 具有自动递增功能的用户可格式化 ID

php - 使用 php 脚本将 pimcore 中的现有数据对象导出到 XML 文件

visual-studio-code - 在 visual studio code c++ 中添加 .lib 文件

visual-studio-code - 如何使用 Tortoise SVN for Visual Studio Code check out 代码

java - Visual Studio Code 无法处理 Java

php - 如何在函数内的数组中使用变量?

php - Prestashop 1.6 session/cookie with smarty

visual-studio-code - 如何在 VSCode 中使用 Prettier 编辑 CSS/SCSS/LESS 的自动格式设置规则?

visual-studio-code - 无法定位android sdk flutter

PHP:如何找出一个值在数组中的位置?