Problem/Motivation
#2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core add coder rules to core. It uses a composer script to install a specific standard for PHPCS. This is problematic because it is a side effect that could affect another Drupal projects coding standards. We should try to eliminate such side effects.
Also if someone changes there phpcs installed paths they might run against other coding standards which is unfortunate.
Proposed resolution
Remove\Drupal\Core\Composer::configurePhpcs()
and use relative paths in core/phpcs.xml.dist
Some might raise an issue that this makes it more difficult to do coding standards checks against a non standard install where vendor has moved. But this is missing the point, coder and phpcs.xml.dist exist for checking core's coding standards at commit time and can suggest direction for the wider community. They are not there to provide a working system for contrib or custom. They are there to ensure core does not regress against the coding standards it is already complaint with.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#19 | 2851661-19.patch | 9.95 KB | alexpott |
#19 | 14-19-interidff.txt | 539 bytes | alexpott |
#14 | 2851661-14.patch | 9.74 KB | alexpott |
#14 | 6-14-interdiff.txt | 855 bytes | alexpott |
#6 | 2851661-6.patch | 9.61 KB | alexpott |
Comments
Comment #2
alexpottComment #3
xjmComment #4
alexpottComment #5
cilefen CreditAttribution: cilefen commentedPlus, what I posted at #2851510-11: Fix phpcs regressions by running phpcbf...
Comment #6
alexpottMissed the required change in composer.json
Comment #7
dawehnerDo we need to change the ref to the excluded ones as well?
Comment #8
alexpott@dawehner not according to my testing and also DrupalCI's testing! https://dispatcher.drupalci.org/job/drupal_patches/1909/consoleFull
Comment #9
xjmIn general it will be great for the same rules to be used automatically for everyone, but making assumptions about relative filepaths is always a bit risky.
Comment #10
alexpott@xjm but I think its less risky than making assumptions about PHPCS configuration of installed_paths being correct. Trade-offs here for sure.
Comment #11
klausiCreative change @alexpott, +1 from me. Reduces code we have to maintain, so that IMO trumps the downside of hard-coding the file location of sniffs like that. People can always copy phpcs.xml.dist to phpcs.xml anyway to do their own thing.
Patch does not apply anymore, sending for retesting.
Comment #12
klausiUrgs, looks like 8.3.x doesn't pass anyway right now, so setting this to "needs work" manually.
Comment #13
cilefen CreditAttribution: cilefen commentedI just ran into an issue where
vendor/bin/phps
could not find the sniffs referenced incore/phpcs/xml.dist
unless I set installed_paths manually:$ vendor/bin/phpcs --config-set installed_paths ~/Sites/drupal8x/vendor/drupal/coder/coder_sniffer
Note, for the record, I have two phpcs:
Comment #14
alexpottHere's a reroll and an update.
Comment #15
dawehnerThat's indeed a bit sad. I'm using the core version in a global alias, as it is less crazy in terms of the amount of rules :)
My actual question is, can we introduce an entry inside the
composer.json
which does the linting (see https://getcomposer.org/doc/articles/scripts.md#writing-custom-commands)? Similar to the entry inpackage.json
:"lint:js": "eslint . || exit 0"
we could have an entry in there which looks like this:"phpcs": "./vendor/bin/phpcs --standard=core/phpcs.xml.dist .
Comment #16
dawehnerI think this patch though is totally the right thing to do.
Comment #17
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedI worked on #2862565: Get rid of the absolute path generated by Composer::configurePhpcs today. Looks like its not necessary anymore because we remove the script in this issue.
Comment #19
alexpottRerolled and fixed the new ExpectedException sniff.
Comment #20
dawehnerI'm happy you had to reroll the patch!
Comment #21
cilefen CreditAttribution: cilefen commentedI was just about to commit this because it solves some problems that I have with multiple projects, but it looks as though
Drupal.Functions.FunctionDeclaration.SpaceAfter
went missing in the patch. This was made plain withgit --word-diff=color
.Comment #22
alexpottvendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Functions/FunctionDeclarationSniff.php contains two sniffs - Drupal.Functions.FunctionDeclaration.SpaceAfter and Drupal.Functions.FunctionDeclaration.SpaceBeforeParenthesis
Comment #23
cilefen CreditAttribution: cilefen commentedDoh! Ok.
Comment #24
cilefen CreditAttribution: cilefen commentedComment #27
cilefen CreditAttribution: cilefen commentedCommitted 34bf287 and pushed to 8.4.x. As I feel this is a non-disruptive dev tooling bug fix (see #13), I cherry-picked it as 8c970f7 and pushed to 8.3.x. Thanks!
Comment #28
dawehnerComment #29
Eric_A CreditAttribution: Eric_A commentedThis looks broken from the perspective of drupal/core as a root package, with a phpcs.xml.dist within drupal/core assuming a vendor dir outside of the drupal/core package. A standard drupal/core composer build will have vendor inside the drupal/core project root. There are enough use cases of developing/testing on just drupal/core.
Shouldn't we instead move the phpcs.xml.dist into drupal/drupal then and reference ./vendor?
Comment #30
jibranShouldn't https://www.drupal.org/node/2839574 be published?
Comment #31
alexpott@Eric_A you are free to copy core/phpcs.xml.dist to wherever you like and update the paths and add rules etc. The point of this change was to make applying core's rules to core simple and not reliant on the global state of phpcs settings which is unreliable and not compatible with maintain multiple projects on multiple versions of the standard.
@jibran if you notice an unpublished change record you can publish it yourself.
Comment #32
jibranI was merely asking about it because I was not sure. After reading my comment again I realized my tune was not helpful so sorry about that.
Comment #33
xjm@Eric_A If you do run into workflow problems with this change, you can open a new issue so we can discuss further. Thanks!
Comment #34
mondrakeNote that this patch broke code checking on DrupalCI for contrib modules that were referencing the "Drupal" rule in their
phpcs.xml.dist
files.I overcome this by referencing the standards' directory directly:
Comment #35
mondrakeActually AFAICS, if a contrib module does NOT have a
phpcs.xml.dist
file, PHPCS fails on DrupalCI with the following error, and no PHP code checking is performed (CSS an JS are OK).see https://dispatcher.drupalci.org/job/drupal_contrib/32270/console as an example.
Comment #36
mondrakeOpened #2870645: PHPCS is failing on contrib modules in DrupalCI: Drupal.org Testing Infrastructure issue queue.
Comment #38
cilefen CreditAttribution: cilefen commented#2902381: Revert phpcs.xml.dist changes from "Ensure that we're using the right ruleset for coding standards checking"