Page MenuHomePhabricator

Phpcs complaining about Universal.Constants.LowercaseClassResolutionKeyword not existing
Open, Needs TriagePublic

Description

When running phpcs from the command line, it fails with an error:

> vendor/bin/phpcs includes/content/ContentHandler.php
ERROR: Referenced sniff "Universal.Constants.LowercaseClassResolutionKeyword" does not exist

Running composer lint does not fail ,since that doesn't use phpc. It uses the vendor/bin/parallel-lint, which doesn't have the issue.

Also triggers an error in PHPStorm:

Screenshot 2024-03-02 at 17.44.54.png (190×384 px, 19 KB)

xref rMCSNdb786d224aad: Add first batch of rules from the PHPCSExtra standards and T349327: Audit PHPCSExtra to see if there are any sniffs we may want to add to our ruleset.

Event Timeline

vendor/phpcsstandards/phpcsextra/Universal/Sniffs/Constants/LowercaseClassResolutionKeywordSniff.phpdoes exist on disk...

Feels Autoloader related... The NS is namespace PHPCSExtra\Universal\Sniffs\Constants;

https://github.com/PHPCSStandards/PHPCSExtra/blob/develop/composer.json doesn't have any autoload entries, but not sure that matters...

Seems fine on my MW checkout/clone... with the same version of MediaWiki-Codesniffer...

Spoke too soon, no it's not...

I can reproduce this. One thing for sure -- it's a consequence of how PHPStorm runs phpcs (because it works if you run it directly, doesn't it). Looks like this might be the corresponding PHPStorm issue: https://youtrack.jetbrains.com/issue/WI-45521#focus=streamItem-27-3750486.0-0, which is marked as resolved except it's not?

Still a problem in 2022.3.3. The workaround still works. However, with one note: still need to provide a path to the local coding standard.

I was able to fix this by adding the following to PHPCS's "Installed standard paths": /path/to/vendor/phpcsstandards/phpcsextra,/path/to/vendor/phpcsstandards/phpcsutils. Updating packages via Tools -> Composer -> Update did not do this automatically (I also tried downgrading PHPCS and then updating it again).

Thanks!

The UI for "Installed standard paths" is... crappy, considering it looks like it can only be a single field, and the open file dialog doesn't do multiple select etc.

It looks like in that task, people are suggesting to just turn that off...

The UI for "Installed standard paths" is... crappy, considering it looks like it can only be a single field, and the open file dialog doesn't do multiple select etc.

Yeah, also, if I select anything using the UI, the window reopens and wants me to select it again for some reason. I didn't even bother trying to understand it, I just assumed that commas would work because I remember other options supporting them.

It looks like in that task, people are suggesting to just turn that off...

I tried that, but it didn't work. I kept getting the same error when disabling the option, and also when enabling it but leaving it empty. I guess something has changed since that workaround was posted.

Parsoid was updated to codesniffer 43.0.0 with 51baccc8741108a9e3f763f2c19c6ce6eda55ac4

Core was updated yesterday with fe1fbb3a5c5e98cd067cac583e0a1de5dcdfafc5

43.0.0 is the first version with LowercaseClassResolutionKeywordSniff

Are the problems there since yesterday or longer?


The new codesniffer needs the plugin dealerdirect/phpcodesniffer-composer-installer, maybe phpstorm does not like this when running something.

When looking at the code the plugin calls --config-set on phpcs and that stores the info in a file named CodeSniffer.conf
Using composer directly it is stored in the vendor of that project.
When running via phar the file is stored in the path it gets by \Phar::running(false);, when that is non-empty.

I have the same problem on the command line:

> vendor/bin/phpcs includes/content/ContentHandler.php
ERROR: Referenced sniff "Universal.Constants.LowercaseClassResolutionKeyword" does not exist

Runnig composer lint works, since it uses parallel-lint. Running parallel-lint directly also works.

daniel renamed this task from PhpStorm complaining about Universal.Constants.LowercaseClassResolutionKeyword not existing to Phpcs complaining about Universal.Constants.LowercaseClassResolutionKeyword not existing.Mar 4 2024, 8:05 PM
daniel updated the task description. (Show Details)

I can't replicate on my system. Are you running this in an odd environment?

➜  mw git:(master) ✗ git log --oneline -n1
11d7742ed50 (HEAD -> master, origin/master, origin/HEAD) Merge "build: Update karma-qunit to 4.2.0 and remove old `__karma__` hack"
➜  mw git:(master) ✗ vendor/bin/phpcs includes/content/ContentHandler.php -p
. 1 / 1 (100%)


Time: 265ms; Memory: 10MB

➜  mw git:(master) ✗ composer test-some includes/content/ContentHandler.php
> parallel-lint --exclude node_modules --exclude vendor 'includes/content/ContentHandler.php'
PHP 8.2.7 | 10 parallel jobs
.                                                            1/1 (100 %)


Checked 1 files in 0.1 seconds
No syntax error found
> phpcs -p -s --cache 'includes/content/ContentHandler.php'
. 1 / 1 (100%)


Time: 265ms; Memory: 10MB

I have the same problem on the command line

If you're seeing this on the CLI, it has to do with composer not installing the paths. Can you please double check that 1) you have run composer update and 2) that the dealerdirect/phpcodesniffer-composer-installer plugin can run? You should see something like this when installing:

Generating optimized autoload files
60 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
PHP CodeSniffer Config installed_paths set to ../../mediawiki/mediawiki-codesniffer,../../phpcsstandards/phpcsextra,../../phpcsstandards/phpcsutils
> MediaWiki\Composer\ComposerVendorHtaccessCreator::onEvent

I can't replicate on my system. Are you running this in an odd environment?

I was running it with MW's docker-compose environment. And also native WSL2. Same result.

Can you please double check that 1) you have run composer update and 2) that the dealerdirect/phpcodesniffer-composer-installer plugin can run?

I did run composer update, but didn't see the output you described.

However, I just pulled latest master, and ran composer update again. I still didn't see that output, but phpcs is now working. No idea what's going on... If this pop ups again, I'll let you know.

The update to the latest codesniffer does not work on Translate extension with this error, not sure if that is related to the phpstorm comments here, because it fails with plain composer from command line.

> parallel-lint . --exclude vendor --exclude node_modules --no-progress
> phpcs -p -s --cache
Script phpcs -p -s --cache handling the phpcs event returned with error code 3
Script @phpcs was called via test
PHP 8.2.13 | 10 parallel jobs
Checked 519 files in 46.5 seconds
No syntax error found
ERROR: Referenced sniff "Universal.Constants.LowercaseClassResolutionKeyword" does not exist

Run "phpcs --help" for usage information

It seems this is just the first sniff from phpcsextra added in db786d224aad3174f4121a64e228fd57074397a7