对于 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/