vscode-phpcs icon indicating copy to clipboard operation
vscode-phpcs copied to clipboard

Custom extensions?

Open josias-r opened this issue 6 years ago • 8 comments

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

josias-r avatar Oct 25 '19 08:10 josias-r

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 avatar Jan 29 '20 23:01 bwaindwain

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

dawidnawrot avatar Mar 19 '20 14:03 dawidnawrot

no update

bwaindwain avatar Mar 19 '20 16:03 bwaindwain

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) {

markfullmer avatar Jul 01 '20 22:07 markfullmer

Thank you @markfullmer Works like charm.

dawidnawrot avatar Aug 19 '20 09:08 dawidnawrot

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

danny-englander avatar Sep 05 '20 21:09 danny-englander

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

mchelen-gov avatar Mar 02 '21 23:03 mchelen-gov

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?

jaybabak avatar Aug 16 '23 20:08 jaybabak