Please revert the phpcs.xml.dist changes from #2851661: Ensure that we're using the right ruleset for coding standards checking
The assumption about the vendor directory location is broken when applied testing contrib modules and when using https://github.com/drupal-composer/drupal-project. This breaks site maintainers ability to use Core's coding standards checking when testing their own code.
PHPCS has its own clearly documented method for handling this and its the test runners responsibility to handle. Its a bit ugly but its straight forward and core should not have any magic or hard coded assumptions around this.
Comment | File | Size | Author |
---|---|---|---|
#59 | revert_phpcs_changes-2902381-59.patch | 12.46 KB | neclimdul |
#59 | revert_phpcs_changes-2902381-59.mergediff.txt | 2.37 KB | neclimdul |
Comments
Comment #2
cilefen CreditAttribution: cilefen at Institute for Advanced Study commentedComment #3
cilefen CreditAttribution: cilefen as a volunteer commented@alexpott wrote this on #2851661: Ensure that we're using the right ruleset for coding standards checking:
I am mentioning that position as a discussion viewpoint.
Comment #4
Mile23I just want to point out what the testbot does for phpcs:
Since core specifies a version of drupal/coder, it installs that (via composer). If your project specifies a higher version, that will be installed when your contrib is installed.
In all cases, if phpcs is present, the testbot will run
phpcs --config-set installed_paths /path/to/vendor/drupal/coder/coder_sniffer/
. This means the Drupal and DrupalPractice standards will be available to your project's phpcs.xml.dist file. (That's the change in #2870645: PHPCS is failing on contrib modules)If your project does not specify a phpcs.xml(.dist) file, phpcs will run against the Drupal standard, as provided by drupal/coder.
So from the d.o project maintenance point of view: Add a phpcs.xml.dist file and specify the standards/sniffs that you want.
For external projects, you can specify whatever CS you want and add a phpcs.xml.dist file. If you need the Drupal standard, add a require-dev for drupal/coder, and then either add a step to your CI build which does the
--config-set
part, or emulate this as a composer script: http://cgit.drupalcode.org/drupalci_testbot/tree/src/DrupalCI/Composer/C...That'd be the workaround, assuming we're not going to revert in this issue.
Comment #5
jhodgdonCan someone please explain what will change if what this issue is requesting is actually done? I.e., what the impact on core and/or contrib module automatic testing will be? Because reading the issue summary on the other issue, I am not clear on what impact it had either. Thanks!
My goal would be: if I have a contrib project without its own phpcs.xml.dist and using the standard vendor locations, the standard Drupal Core coding standards checks should be run whenever automated tests are run. Which is what is happening now that #2870645: PHPCS is failing on contrib modules is in, and what was happening a while back too, before the bug that caused that issue happened (I'm not clear on what made that happen).
Comment #6
Mile23Yah I guess I could have been clearer...
#2851661: Ensure that we're using the right ruleset for coding standards checking changed core's phpcs.xml.dist like this:
It used to use class references, now it uses paths to the files containing the classes. It also took out the composer script that configured phpcs to use the Drupal standard.
When this change was made, it trickled down into contrib because the testbot assumed that core was configuring phpcs to use the Drupal standard. This meant that if you had a phpcs.xml file that used the class reference style, phpcs couldn't find it because it was never configured that way.
#2870645: PHPCS is failing on contrib modules changed that so the testbot configures phpcs to use the Drupal standard in all circumstances.
Basically the super-annoying part here is that phpcs requires you to configure it to use external standards. :-)
If your phpcs.xml file uses classes (and not paths), then it should be OK under any circumstance where you *also* configure phpcs for the Drupal standard. The testbot does this, so it's OK.
If your phpcs.xml file uses file paths (and not classes), then it matters where vendor/ is. If you assume that vendor/ is in DRUPAL_ROOT, the testbot puts it there, so it's OK.
So the testbot is good either way, and if it turns out not, we'll fix it. :-)
Comment #7
neclimdulThere in lies the rub really. "standard" isn't really a thing in the sense of "the way it SHOULD be." Instead its more "common" or "what core does in its test suite" because autoload.php is included in Drupal specifically to allow you to move vendor around where ever you want. That is exactly what https://github.com/drupal-composer/drupal-project does so vendor is completely outside the web root. And it totally reasonable for any contrib or external module testing to put vendor in a location that makes sense to their testing environment as well and it was easily supported prior to this change.
PHPCS' configuration may be a bit akward but its a feature that exists to support the fact that PHP's autoloading's purpose it to allow developers to put code where ever makes sense to their needs and Drupal has supported that for the entirety of D8 and this is a subtle break saying "if you care about testing coding standards you have to use our structure or your own standards"
Comment #8
neclimdulI guess my point is that prior to 8.4.x phpcs.xml.dist was a codified version of our coding standards you could import into any project and or environment and use and test against. Now its something that only exists to support testbot and that's an unfortunate loss we can easily fix.
Edit: fix wording around when the change takes place.
Comment #9
Mile23Well, not really. The coding standards document is the real standard: https://www.drupal.org/docs/develop/standards
drupal/coder has the Drupal standard, which is (or should be) the more canonical tool for the standard.
If you look at core/phpcs.xml.dist, it has a ton of exclusions and things that aren't included in the first place. Core doesn't actually follow the coding standards completely.
Comment #10
jhodgdonWhat I meant by "standard" was "the Coder rules currently being used by the same version of Drupal Core for testing coding standards".
Comment #11
neclimdulre: #9 I opened my self up there I guess. I think de facto that is not true of we would be running drupal/coder and letting it fail and fighting out those exclusions in the coder queue. Religious discussion about what the standard is aside, vendor can be anywhere.
re: #10 I think I might not have been clear enough because it sounds like you're talking about standard coder rules. I was referring to your use of standard in terms of vendor location. Hard coding the vendor location was the bug that was introduced by #2851661: Ensure that we're using the right ruleset for coding standards checking.
Comment #12
Mile23But it's not a religious discussion. There's a ton of issues moving core closer to the coding standard, by adding each sniff one at a time: #2571965: [meta] Fix PHP coding standards in core If you use core's phpcs.xml.dist file, it will change as these are added, and you'll also find yourself surprised when your tests start reporting CS errors that were formerly excluded.
This is one of the reasons the testbot doesn't use core/phpcs.xml.dist as default for projects that don't have phpcs.xml files, and instead just uses the Drupal standard provided by coder.
Comment #13
neclimdulI'm going to clarify something real quick. I only think we should revert the phpcs.xml.dist changes from the original issue.
Removing `\Drupal\Core\Composer::configurePhpcs()` was the right thing to do because it was always broken and didn't actually work the way the author expected. mostly because of https://github.com/squizlabs/PHP_CodeSniffer/issues/1436
Really we should have been telling people to run phpcs as the 2 line method documented (still) in the handbook and used by Wordpress or with the more bullet proof --run-timeset oneliner.
Comment #14
neclimdulpatch to do that.
Comment #15
cilefen CreditAttribution: cilefen as a volunteer commented--runtime-set 😍
Comment #16
mfernea CreditAttribution: mfernea at AmeXio commentedHere's a re-roll. Multiple Drupal CS sniffs were merged in the last weeks.
Comment #18
mfernea CreditAttribution: mfernea at AmeXio commentedAnother re-roll.
Comment #19
heddnThere's still some more changes again from more stuff. Patch won't apply again.
Comment #20
heddnBTW, having this the way it is right now is causing confusion to at least one contrib author (me). See #2906653: How to add phpcs to contrib modules. Let's get this re-rolled and into the RTBC queue.
Comment #21
mfernea CreditAttribution: mfernea at AmeXio commentedRe-roll.
Comment #22
heddnI went through and made sure we didn't loose anything in the conversion. We didn't loose anything. However, we seem to have missed MethodDeclarationSniff.
Comment #23
Mile23Updated the testbot docs to tell people to use Drupal.Sniff syntax instead of file paths: https://www.drupal.org/drupalorg/docs/drupal-ci/using-coderphpcs-in-drup...
Comment #24
mfernea CreditAttribution: mfernea at AmeXio commentedHere is the updated patch and the interdiff.
Comment #25
heddnAnd are good now.
Comment #26
Mile23core's phpcs.xml.dist file is not the defacto coding standard for Drupal projects.
It is incomplete and will change over time.
The best automated tool for evaluating CS errors is the coding standard is the Drupal standard in Coder.
So if you are a contrib maintainer, use the Drupal standard, rather than core's config file.
For instance, Examples for Developers has its own phpcs.xml.dist file. This allows me to do a sniff like this:
The testbot works under the assumption that if you have a phpcs.xml(.dist) file, you want to use it. See: https://www.drupal.org/drupalorg/docs/drupal-ci/using-coderphpcs-in-drup...
You can also specify a different version of Coder than core uses in your composer.json file, if you know you need a certain sniff or a bugfix or whatever. The testbot knows how to do that. If you don't specify a Coder version, the testbot will
composer require --dev drupal/coder @stable
and use that. Since module dev dependencies aren't accounted for when you do a core install, you have to do a sub-install to run it locally:I'm not going to hold up this issue, but the solution is to not use core's phpcs.xml.dist file, which is probably a best practice anyway. Your code might have better CS compliance than core. :-) You could just have the XML file with one rule: Drupal.
Comment #27
mfernea CreditAttribution: mfernea at AmeXio commented@Mile23: I think you meant phpcs.xml.dist in your first sentence in the message above, no?
Comment #28
Mile23Er, yeah. :-) Thanks.
Comment #29
neclimdulWe're going to have to agree to disagree on the defacto point. As a contrib developer I want to be able to track the code checks I'll be expected to pass with patches to core. Additionally I'd have to update the file everytime I do maintenance on the code. Ditto on that point for sites I work on. I just don't want to mentally keep track of multiple standards for everything I'm doing when tracking core (and occasionally a PSR CS project) is hard enough. Therefor for me it is my defacto standard and that's the rational for my initial statement.
Thanks guys for the hard work re-rolling! I see a stray unrelated whitespace change but its the right thing so no kitten killing from me. Looks good to go!
Comment #30
Wim LeersI echo this statement, although I do understand where @Mile23 is coming from.
I simply think it's helpful for core to nudge contrib into respecting at least the coding standards that Drupal core respects. And since Drupal core is gradually becoming more consistent, this also allows contrib modules to gradually become more consistent.
In any case, this is what I've been doing and plan to continue to do for my contrib modules — e.g. for the CDN module I did this two weeks ago: #2910800: Core coding standards fixes: FileCommentSniff + DisallowLongArraySyntaxSniff + ExpectedExceptionSniff.
Comment #32
neclimdulI get where he's coming from too. It would be nice if rather then having drupal's code sniffer was treated more as a spec and be in sync with core. We'd need some staging area for rules not yet accepted by core or something and importing Core's rules from code sniffer would not be this complicated. Core's phpcs basically "import the core ruleset and go" and ditto for all us tracking core's rules. For more bleeding edge you'd pull in some other "profile."
In reality I don't know how well that would work out in practice but if someone where to make that happen it would be lovely.
Working on a reroll but as is the point of this issue... that's a miserable process so it will take a while.
Comment #33
neclimdulComment #34
neclimdulChasing head.
Comment #35
neclimdulChasing head
Comment #36
alexpottThe point is though that Coder's standards are for everyone and core's standards are for core. #2851661: Ensure that we're using the right ruleset for coding standards checking was done for valid reasons that I think outweigh the reason given for contrib. Contrib has coders standards or can even role their own phpcs.xml.dist and they can keep that inline with core if they want.
Comment #37
neclimdulChasing head again.
1) It is just not though. Its the community standard. If there was a way to match cores standard without copying phpcs.dist I would agree because I'd just point at drupal/code_sniffer and run and it worked I'd be more open to the argument but you just can't. We need some sort of profile managed outside of core that core points to for that to work. As I've reported repeatedly I target core with all work which means core's standards is my contrib standard is my project standard. The is a compatibility break to level of the community we support. Every time core breaks this patch it breaks every one of my contrib testing setup and my project setups.
2) .dist is designed to be copied out and used and pathing breaks that promise because folders are allowed to be moved around even to test core.
3) Even if its only core's standard, its not the right way. We should not want to do it because it makes things worse and more complicated(complected, tightly bound).
Comment #38
alexpott1. It is not the community standard. If the community standard provided by coder doesn't work that is not the fault of core.
2. where does it say that .dist is designed to be copied out?
3. It is less bound to global state and funky errors that come from not having the right standards installed.
Comment #39
dawehnerAs alternative we could put some documentation on top of the
phpcs.xml.dist
file to explain how you can create your own file.Comment #40
neclimdul1) I just don't agree and I've made my point as best I can and I'll just point to #29 as my final say on this. And I guess I agree it is not the fault of core. But fault also seems to imply this issue adds some burden to core when I don't think that's the case. @see point 3 on simplicity.
2) That's the assumption I've always worked under and the first result for "dist files" in google points to a S.O that seems to agree https://stackoverflow.com/a/16843246. Other search results talk about the non-dist(phpunit this time) being for developer specific customization https://stackoverflow.com/q/44764023. While subtly different I think the result is the same because that implies that .dist is setup to be easily customized to fit a developers environment. I didn't find a specific "standard" in my admittedly brief searches.
3) I'm not sure follow. Assuming you where disagreeing I'll try to make my point more clear, I see file paths as being constrained to a specific setup and therefore complected with that filesystem configuration. You can't modify one without modifying the other and that is complex. Especially when it means manually modifying dozens of entries in a file.
Note: I'm pretty frustrated. I took many deep breaths and hope this was a helpful response. If the frustration bled through I'm I'm genuinely sorry.
Comment #41
mfernea CreditAttribution: mfernea at AmeXio commentedimho: If for whatever reason Drupal CS is not ok for the contrib / custom project, a specific phpcs.xml.dist is the best solution. Something like:
More info at: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#using-a....
It doesn't depend on what coding standards core is following (which can change often and / or unexpectedly) and it's not bound to specific paths. You also don't depend on how soon this issue will get merged! :) My 2 cents!
Comment #42
neclimdulDiscussed with Alex and he's open to the change if we provide easy ways of using the calling method I referenced in #13. He's updated his gihooks[1] and I've updated with composer script to simplify the running of phpcs manually. I'll follow this up with a comment updating the phpcs work going on in core and we'll update the IS on that issue once its committed.
Comment #43
neclimdul#2572787: Fix 'Drupal.WhiteSpace.CloseBracketSpacing' coding standard and #2901572: Fix 'Drupal.Commenting.PostStatementComment' coding standard
Comment #44
neclimdulBah, i messed that up but had some other things that pulled my attention and I hadn't had a chance to get this in my test environment.
Comment #45
MixologicIf we switch this back, we need to ensure that codesniffing works on the testbots for both core and contrib, or we need instructions on how to make it work. So, we'll need to review drupalci_testbot and determine if anything needs to change in how we kick off codesniffing.
Comment #46
neclimdulMile23 updated the handbook to document this usage a ways back(#23) so I think we're good there. If it didn't work, contrib wouldn't be able to use that syntax today.
Also, it looks like its setting the config path during the run here:
http://cgit.drupalcode.org/drupalci_testbot/tree/src/DrupalCI/Composer/C...
Comment #47
Mile23The change was made to the drupalci_testbot phpcs plugin here: #2870645: PHPCS is failing on contrib modules
@neclimdul: http://cgit.drupalcode.org/drupalci_testbot/tree/src/DrupalCI/Composer/C... is setting up PHPCS for drupalci_testbot itself, not the build.
The phpcs configuration code is here: http://cgit.drupalcode.org/drupalci_testbot/tree/src/DrupalCI/Plugin/Bui...
It always sets installed_paths for all projects. If the phpcs.xml file uses literal paths to sniffs, then it should still work.
But nevertheless, here's an issue to make sure: #2916858: Test to ensure that various phpcs configuration types work properly
Comment #48
neclimdulChasing Head:
#2909163: Fix 'Drupal.Commenting.InlineComment.WrongStyle' coding standard
Comment #49
alexpottThis comment shouldn't be changing.
Comment #50
neclimdulYou are correct. Fixed.
Comment #51
alexpottI think we need to add the composer commands first. Then update all the coding standards issues. And then do this. So that we don't have people working on those issues using out-of-date standards.
Fortunately someone just had the same idea and created #2886279: Add PHPCS and PHPCBF as Composer scripts so let's get that done first.
Comment #52
alexpottOne problem with the composer script though is that it suffers from the same problems - ie. it is making a hard-coded assumption about vendor.
Comment #53
zaporylieI think this issue is great + #50 still applies which makes it good RTBC candidate, but I think, and as of #51 it is not just me, it should be postponed on #2886279: Add PHPCS and PHPCBF as Composer scripts.
Comment #54
neclimdulJust keeping this up to date. removed the #2886279: Add PHPCS and PHPCBF as Composer scripts bits in this patch so its ready to go.
Comment #55
dawehner🙃: Can we avoid these changes to keep the patch size small?
Here is a suggestion of an updated text for all the CS issues:
Before
After
.
You can add a progress in the command line by adding
-- -ps
Comment #56
neclimdul1) I'll happily kill that kitten here rather than reroll a white-space patch and fight/slow down all the cs fixes going on again. :)
2) That's probably part of the other issue actually adding the phpcs composer command but sure.
Comment #57
neclimdulThe other issue which actually is committed so we're not postponed. Thanks!
I'm not sure what text we should update pointing people to the composer script but happy to do it.
Comment #58
neclimdulbroken by #2909366: Fix 'Drupal.Commenting.VariableComment.EmptyVar' coding standard
Comment #59
neclimdulbroken by #2902407: Fix 'Drupal.Commenting.DataTypeNamespace' coding standard
Is there anything other then someone pushing this RTBC blocking this at this point?
Comment #60
heddnThis has been in RTBC a few times, or at least close and seems to be in re-roll perdition. Let's get this committed.
Comment #61
zaporylieI am ok with the patch - it does a very decent work.
I am ok-ish if unrelated CS fixes mentioned in #55 and #56 are fixed along, but I see potential for separate issue which aims to fix all whitespaces across all xml files in core (I counted 8 of them in two files).
Leaving it RTBC for committer to decide.
Comment #62
catchCommitted e9b1184 and pushed to 8.5.x. Thanks!
Comment #65
Wim LeersI used to do
and that worked fine.
Since this issue, I'm now getting:
It seems we now have to run
phpcs
like this:Hopefully this helps others who run into this.