Problem/Motivation
When using version 8.3.14 from January 28, I get "ERROR: Referenced sniff "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist":
When using version 8.3.13, it works as expected.
Steps to reproduce
composer global require \
drupal/coder
phpcs --standard=Drupal example.module
ERROR: Referenced sniff "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist
composer global require \
drupal/coder:8.3.13
phpcs --standard=Drupal example.module
----------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
1 | ERROR | [x] Missing file doc comment
14 | ERROR | [x] Expected 1 space after FUNCTION keyword; newline
| | found
17 | ERROR | [x] Multi-line function declarations must define one
| | parameter per line
----------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
I am running this within a Docker container [using this project](https://github.com/dcycle/docker-php-lint).
Proposed resolution
Coder 8.3.14 now depends on the SlevomatCodingStandard and will setup the phpcs installed_paths configuration automatically on composer install with the dealerdirect/phpcodesniffer-composer-installer plugin. During the composer install process you need to answer Do you trust "dealerdirect/phpcodesniffer-composer-installer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?]
with "y" (yes, we trust this plugin to setup PHPCS paths).
Please also remove all extra commands that set the installed_paths with phpcs from any Coder setup scripts you use.
If you have a composer vendor directory already then you might have an outdated vendor/squizlabs/php_codesniffer/CodeSniffer.conf file there. Reinitialize that:
rm -rf vendor/squizlabs/php_codesniffer/
composer install
Again make sure that you trust the "dealerdirect/phpcodesniffer-composer-installer" plugin. Your composer.json file should look similar to this:
{
"require": {
"drupal/coder": "^8.3"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
The composer install should print PHP CodeSniffer Config installed_paths set to ../../drupal/coder/coder_sniffer,../../sirbrillig/phpcs-variable-analysis,../../slevomat/coding-standard
, then you know the new Slevomat coding standard path was configured.
Remaining tasks
Fix Drupal.org testbot script which has a hard-coded --config-set installed_paths
command.
#3283978: Remove --config-set installed_paths (Referenced sniff does not exist)
Comment | File | Size | Author |
---|---|---|---|
#49 | phpstorm-settings-php-quality-tools-phpcs.png | 719.89 KB | TomTech |
Comments
Comment #2
alberto56 CreditAttribution: alberto56 at Dcycle commentedHere are my automated test results using 8.3.13: https://app.circleci.com/pipelines/github/dcycle/docker-php-lint/14/work...
Here is my pull request on my Dockerized version of coder, which changes from 8.3.13 to the latest version: https://github.com/dcycle/docker-php-lint/pull/4/files
Here is the failing test for this pull request: https://app.circleci.com/pipelines/github/dcycle/docker-php-lint/15/work...
And here is the test being run: https://github.com/dcycle/docker-php-lint/blob/master/test.sh
This happens locally on a ARM macbook and on a VM with AMD as well.
Comment #3
IT-Cru@alberto56: I run into similar issue today with my Gitlab CI PHPCS job.
Problem for me was that I run set in this CI job PHPCS config manually
non working PHPCS config:
phpcs --config-set installed_paths /var/www/html/vendor/drupal/coder/coder_sniffer
working PHPCS config:
phpcs --config-set installed_paths /var/www/html/vendor/drupal/coder/coder_sniffer,/var/www/html/vendor/sirbrillig/phpcs-variable-analysis,/var/www/html/vendor/slevomat/coding-standard
My manual config overrides the one from composer install. So maybe this manual config set could completely removed from my CI job script.
Comment #4
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedI can confirm this issue. I am using dockerized Drupal via ddev and getting the same error as @alberto56. 8.3.13 is also working fine for me.
Comment #5
alberto56 CreditAttribution: alberto56 at Dcycle commentedThanks @Grevil. Unfortunately in my Docker tests @IT-Cru's solution does not work.
Comment #6
alberto56 CreditAttribution: alberto56 at Dcycle commentedComment #7
Grevil CreditAttribution: Grevil as a volunteer and at DROWL.de commentedI also tried @IT-Cru solution, but unfortunately it doesn't work for me either.
Comment #8
SweetchuckI ran into this issue, because I had a custom Composer script on the "post-update-cmd" event, with something like this: "phpcs --config-set installed_paths ...".
I removed this custom script.
dealerdirect/phpcodesniffer-composer-installer does the job very well.
Comment #9
SweetchuckI think the documentation should be updated, because the path "vendor/drupal/coder/coder_sniffer" simply not enough.
https://www.drupal.org/docs/contributed-modules/code-review-module/insta...
Comment #10
IT-CruI've tested remove of
phpcs --config-set installed_paths...
command yesterday in another project and for me this is working fine, because during composer install it is set with correct parameters.This also happens in @alberto56's CircleCI job as far as I see at https://app.circleci.com/pipelines/github/dcycle/docker-php-lint/15/work...
But in https://app.circleci.com/pipelines/github/dcycle/docker-php-lint/15/work... this is/was overridden again. And then the error occurs.
Comment #11
alexpott#3010032: Add dependency on slevomat/coding-standard has some more info on fixes.
Comment #12
hitesh.koli#3 setting the right installed_paths worked for me.
Comment #13
joachim CreditAttribution: joachim as a volunteer commentedI'm getting the same error running this programatically in Drupal Code Builder's tests: https://github.com/drupal-code-builder/drupal-code-builder/blob/380ca748...
Comment #14
klausiSorry, not sure if we can do anything in Coder directly - please remove all extra commands that set the installed_paths with phpcs. This is now done automatically when you install Coder 8.3.14. By setting them manually you are missing the new SlevomatCodingStandard that Coder depends on and then the installed_paths configuration for phpcs is wrong.
Added this to the release notes: "Coder 8.3.14 now depends on the SlevomatCodingStandard and will setup the phpcs installed_paths configuration automatically on composer install. Please remove all extra commands that set the installed_paths with phpcs from any Coder setup scripts you use." https://www.drupal.org/project/coder/releases/8.3.14
Please don't use Homebrew to install Coder as that is not really supported by us maintainers. We had an argument on the docs discussion page https://www.drupal.org/node/1419988/discuss where BramDriesen wanted to keep the Homebrew instructions, but I think we should delete them again.
Comment #15
jweowu CreditAttribution: jweowu at Catalyst IT commentedIf you have a
phpcs.xml
file then you would remove anyinstalled_paths
line like this:Deleting that will prevent the specified value from clobbering the default (and correct) value, which is now established automatically.
Comment #16
Chi CreditAttribution: Chi commentedFor me the only way to work around this issue was installing the slevomat manually.
<config name="installed_paths" value="vendor/slevomat/coding-standard"/>
Comment #17
jweowu CreditAttribution: jweowu at Catalyst IT commentedChi: That's interesting. I'd initially tried adding that exact same element, but quickly found I actually needed to use the following diff to get the right result:
Despite it being XML (and despite commas being valid in filenames!), the whole list apparently needed to be stuffed into a single value attribute, CSV style.
Subsequent reading had caused me to realise that deleting that line entirely was the better fix, and that worked equally well for me.
Comment #18
geoanders CreditAttribution: geoanders as a volunteer commentedIssue seems to be around slevomat coding standard/format.
After downgrading, all is well.
Useful site: https://gorannikolovski.com/blog/referenced-sniff-slevomat-coding-standa...
Comment #19
agileadamThank you, @geoanders. I downgraded coder (composer global require drupal/coder:8.3.13) and it fixed the issue right away.
Comment #20
uditrawat CreditAttribution: uditrawat as a volunteer and commentedThank you @geoanders, @agileadam,
Downgrading the coder fixed the issue.
Comment #21
uditrawat CreditAttribution: uditrawat as a volunteer and commentedBelow solution works for 8.3.14 & 8.3.15
https://gorannikolovski.com/blog/referenced-sniff-slevomat-coding-standa...
Comment #22
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedI see this error on contrib testing on drupal.org at Core 9.4 (which uses Coder 8.3.15). Tests at Core 9.3 which use Coder 8.3.13 run ok.
The project's phpcs.xml.dist file does not have the installed_paths config, so this must be added by the test script being run on d.o.
Has anyone else seen this on d.o. contrib testing and if so, did you manage to fix it?
There is no reference to this on https://www.drupal.org/project/drupalci_testbot so I might raise it there.
Comment #23
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedI have raised #3283978: Remove --config-set installed_paths (Referenced sniff does not exist) for the d.o. testbot project
Comment #24
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedUpdated IS to include link to drupal.org testbot issue
Comment #25
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedFor anyone who's contrib project has a phpcs.xml.dist file and they want to gets PHPCS running for testing on drupal.org at Core 9.4+ and have it compatible with running locally, here is what you can add into the phpcs.xml.dist
This gets away from the hard-coded /var/www/html/vendor, is compatible with Travis testing, and is also OK all versions of coder.
Hope this helps.
Comment #26
klausiThank you jonathan1055 for finding and reporting that problem!
Added some more help to the issue summary to get a correct vendor/squizlabs/php_codesniffer/CodeSniffer.conf config file for old vendor directories.
I will leave this issue open to collect more help and tricks on upgrading.
Comment #27
klausiAdded more important info to the issue summary: During the composer install process you need to answer
Do you trust "dealerdirect/phpcodesniffer-composer-installer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?]
with "y" (yes, we trust this plugin to setup PHPCS paths).Your composer.json file should look similar to this:
Comment #28
afschIn my case I opted to downgrade coder and php_codesniffer specifying the version which is still compatible with Drupal 9.4.1.
composer require drupal/coder:8.3.13
composer require --dev squizlabs/php_codesniffer:3.6.2
Comment #29
abdulaziz zaid#3 worked for me.
Comment #30
CBThanks alexis_s, #28 worked for me.
Comment #31
AaronBaumanissue persists to 8.3.16 and presumably dev
Comment #32
rpayanmI fixed it after reading this article:
https://gorannikolovski.com/blog/referenced-sniff-slevomat-coding-standa...
Before (Coder 8.3.13 and earlier):
After (Coder 8.3.14 and later):
Comment #33
reflie CreditAttribution: reflie as a volunteer and at Drupal Ukraine Community commentedI also faced into this issue. I was receiving mentioned error in PhpStorm.
In my case the problem was in wrong installed path in Project_Default.xml file. I just removed that line and the error disappeared.
Comment #34
mandclu CreditAttribution: mandclu as a volunteer and at Acquia commentedI was having this same problem, and couldn't fix it with the suggestions in the comments. I realized that I had installed phpcs via homebrew, so I installed it there and reinstalled it via composer, and now it works.
Comment #35
enaznin CreditAttribution: enaznin commentedhello @mandclu, #34 could you please elaborate on the steps, please? I installed phpcs with homebrew as well and facing the same issue
Comment #36
AnokR CreditAttribution: AnokR as a volunteer commentedHello @all, I was having same error But downgrading the global coder version to "8.3.13" run the command
composer global require drupal/coder:8.3.13
fix my issue.Hope it should helpfull.
Thanks
Comment #37
Anwaikurn CreditAttribution: Anwaikurn commented#36 works for me.
Also after downgrading Coder to the
8.3.13
version you can upgrade it again to the latest one and Slevomat coding standards appear inphpcs -i
. At least it did a "trick" for me.Comment #38
AaronBaumanafter R'ing TFA, I realized I needed to make a couple updates to my project's composer.json to get this working on latest coder stable.
Remove any config-set step from composer.json:
bin/phpcs --config-set installed_paths vendor/drupal/coder/coder_sniffer
Then remove dependencies which are now integrated with this module:
Good to go after that.
Comment #39
shivakumarshidkapla CreditAttribution: shivakumarshidkapla as a volunteer commentedThank you, @geoanders. I downgraded coder (composer global require drupal/coder:8.3.13) and it fixed the issue right away.
#18 worked for me thank you @geoanders
Comment #40
xeM8VfDh CreditAttribution: xeM8VfDh commentedsame issue for me on latest but not on 8.3.16
Comment #41
Nick Hope CreditAttribution: Nick Hope commentedThe downgrade-then-upgrade trick in #37 worked for me.
Downgrade to 8.3.13:
composer global require drupal/coder:8.3.13
Upgrade to the latest version (currently 8.3.18):
composer global require drupal/coder
Verify installed coding standards:
phpcs -i
outputs (for me):The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, Drupal, DrupalPractice, VariableAnalysis and SlevomatCodingStandard
Comment #42
jonnyhocks CreditAttribution: jonnyhocks at Welsh Government commentedJust to expand on #33, I was also experiencing the issue with PHPStorm even though the issue had been resolved when running with CLI.
I removed the installed paths section from the .idea/php.xml file. I'm guessing that some config is saved in different places depending on which version of PHPStorm you are using.
Comment #43
dynamdilshan CreditAttribution: dynamdilshan commented#18 worked for me as I followed the instructions from this resource below:
https://gorannikolovski.com/blog/referenced-sniff-slevomat-coding-standa...
I'm on D9.5, PHP 8.1 and the latest version of coder module.
Comment #44
selwynpolit CreditAttribution: selwynpolit at Mighty Citizen commentedJust to elaborate on #42. I found that by editing the .idea/php.xml file, even while PHPStorm is open, and removing the line:
from the section displayed below, the error immediately went away.
Comment #45
Dimetry CreditAttribution: Dimetry commented#44 does work. Many thanks.
Comment #46
Sivaji_Ganesh_Jojodae CreditAttribution: Sivaji_Ganesh_Jojodae as a volunteer and commented#36 works. Downgrading drupal/coder (8.3.21 => 8.3.13).
Comment #47
pfrenssenChanging this to a support request since this is not a bug in coder but rather a configuration issue on the user side.
Comment #48
fgmSeeing how it's so common since it happens as the default in the most popular IDE, I would say it's rather a bug, but that's your call.
Comment #49
TomTech CreditAttribution: TomTech at Centarro commentedI just encountered this issue.
You shouldn't need to edit any PhpStorm XML files. There is a setting for this.
Seems that JetBrains was being helpful, as this is configuration specifically documented for this module(and similar implementations): PHP - Quality Tools - PHP Code Sniffer.
You can clear the field and uncheck the "Installed standards path" to remove this setting in PhpStorm.
Seems some communication should be made with JetBrains that the latest version of coder requires multiple paths, not a single path. (Or could we just symlink the other directories into the coder directory as an alternative?)
Comment #50
emb03 CreditAttribution: emb03 commented#36 worked for me
Comment #51
j. ayen green CreditAttribution: j. ayen green commented@TomTech #49 (using ddev and PhPStorm) ... I owe you a beer!
Comment #52
selwynpolit CreditAttribution: selwynpolit commentedHopefully I captured the steps correctly here to save others some time: https://selwynpolit.github.io/d9book/setup_mac#code-sniffing