ikappas / vscode-phpcs

PHP CodeSniffer for Visual Studio Code
MIT License
128 stars 56 forks source link

Custom extensions? #159

Open josias-r opened 4 years ago

josias-r commented 4 years ago

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 :/

bwaindwain commented 4 years ago

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

dawidnawrot commented 4 years ago

@bwaindwain Is there any update around this issue? phpcs used in VSC still does not track custom extensions

bwaindwain commented 4 years ago

no update

markfullmer commented 4 years ago

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) {
dawidnawrot commented 4 years ago

Thank you @markfullmer Works like charm.

danny-englander commented 3 years ago

I tested https://github.com/ikappas/vscode-phpcs/issues/159#issuecomment-652672079 and it works great. Thanks @markfullmer.

mchelen-gov commented 3 years ago

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

jaybabak commented 1 year ago

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?