vscode-phpcs
vscode-phpcs copied to clipboard
Custom extensions?
Phpcs supports the cli argument --extensions=foo,bar . Is there a way I can pass the --extensions=phtml,php to work with phtml files? Currently, I get no linting results for phtml files inside the editor :/
By default, PHP_CodeSniffer will check any file it finds with a .inc, .php, .js or .css extension
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#specifying-valid-file-extensions
For our Dupal work, I was able to hack this by adding lintArgs.push('--extensions=inc,install,module,php,profile,theme'); after line 111 of server/src/linter.js. Not a brilliant solution but it's a start.
An idea may be to tie into files.associations which is what intelephense does.
It would be nice to get it to do CSS and JS files too >> https://github.com/ikappas/vscode-phpcs/issues/17
@bwaindwain Is there any update around this issue? phpcs used in VSC still does not track custom extensions
no update
Here's a quick reference for implementing the Drupal-specific fix in https://github.com/ikappas/vscode-phpcs/issues/159#issuecomment-580015114
File is most likely located in ~/.vscode/extensions/ikappas.phpcs-1.0.5/server/src/linter.js
diff --git a/linter.js b/linter.js
index c8782e9..b6da7b7 100644
--- a/linter.js
+++ b/linter.js
@@ -109,6 +109,7 @@ class PhpcsLinter {
return [];
}
}
+ lintArgs.push('--extensions=inc,install,module,php,profile,theme');
lintArgs.push(`--error-severity=${settings.errorSeverity}`);
let warningSeverity = settings.warningSeverity;
if (settings.showWarnings === false) {
Thank you @markfullmer Works like charm.
I tested https://github.com/ikappas/vscode-phpcs/issues/159#issuecomment-652672079 and it works great. Thanks @markfullmer.
Found another workaround to this, create a phpcs.xml.dist in project root and set the file extensions there:
<arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,md,yml"/>
See https://github.com/pfrenssen/coder#store-settings-in-a-phpcsxmldist-file for sample file
I have created a PR for this change in #150, https://github.com/ikappas/vscode-phpcs/pull/207 - any chance it could be merged in?