Problem/Motivation
The PHPCS coding standards lint job is not checking the php scripts stored in /scripts/ and specifically not checking run-tests.sh.
The reason is that the core phpcs.xml.dist file does not include sh in the list of extensions, probably because in general .sh files are bash scripts not php. But it seems there was an attempt to include specific .sh files in the check. I don't know if this ever worked, but it certainly does nothing now, at least locally for me, because the list in "extensions" overrides any exceptions here.
There is currently a lot of activity relating to run-tests.sh - this problem was discovered in #3515347-57: Reduce run-tests.sh complexity in spawning subprocesses #57 but there are many other issues - see #2626986: [meta] Improvements to run-tests.sh so it would be very helpful if the PHPCS coding standards could be run. I don't know if PHPStan is being run on these php scripts, but that would be very useful too.
Proposed resolution
Add a PhpCFS filter ala https://stackoverflow.com/questions/47415146/how-can-php-codesniffer-che... so we can ensure any file listed in phpcs.xml.dist is scanned even if it does not match an extension in the list. This is how PHPCS 2 worked.
Remaining tasks
None
User interface changes
None
Introduced terminology
None
API changes
None
Data model changes
None
Release notes snippet
N/a
Issue fork drupal-3568959
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3568959-run-phpcs-on-php-scripts
changes, plain diff MR !14471
Comments
Comment #2
jonathan1055 commentedI know that there is a long-standing issue #655178: [PP-2] Rename run-tests.sh to run-tests.php but I'm not suggesting we push for that either. The scripts can stay exactly like now, we just need them to be checked in the linting jobs.
Comment #3
mondrakeAFAICS PHPStan does do checking of run-tests.sh.
EDIT: yep, there are even baselined errors
Comment #4
mondrakeComment #6
jonathan1055 commentedThe core phpcs.xml.dist has the following, specifically naming four scripts:
Adding a second call to phpcs using
--extensions=shand the job checks five files. We see:So the
<file>list for those four scripts is being ignored probably because the<file>.</file>means 'check everything here and below'. That list of files can probably be deleted from phpcs.xml.distComment #7
alexpottCopying the fix from the duplicate I filed - #3589520: Since we moved to PHPCS3 run-tests.sh amongst other things is not scanned.
Comment #8
jonathan1055 commentedThanks for doing this. Looks like you have solved it.
Comment #9
alexpottThanks @jonathan1055, fancy RTBC-ing this then?
Comment #10
alexpottRe #6 I don't think PHPCS should be scanning builds/core/scripts/dev/commit-code-check.sh - it's not PHP :)
Comment #11
smustgrave commentedLeft one question on the MR but don't mind marking it.
Comment #12
smustgrave commentedThanks alexpott
Comment #13
jonathan1055 commentedI know that the phpcs job ends green but there is no actual evidence that the file extra files are being checked. Would it be worth doing a temporary change to run it with the
-vflag to show each file that has been checked? Is there a way to pass in extra parameters via a manual pipeline run, like we can in contrib pipelines?Comment #14
alexpott@jonathan1055 over on the duplicate MR there is evidence https://git.drupalcode.org/project/drupal/-/merge_requests/15731/pipelines - plus it is quite simple to prove locally.
Comment #15
jonathan1055 commentedThanks for the link to https://git.drupalcode.org/project/drupal/-/jobs/9767126#L398
Yes I was just being lazy and not gettting this new work locally. I have now done that, and get
So all's good. It's a really nice use of a custom phpcs filter. I did not know about them before, so thank you for that, too.
Comment #18
longwaveCommitted and pushed 14676bf640b to main. Thanks!
Doesn't backport cleanly, don't think it's worth the effort as run-tests.sh will only really change in main going forward.