Follow-up to #2887052: Ignore Diff component files in phpcs coding standards

Problem/Motivation

We hav following files in core with @codingStandardsIgnoreFile comment.

core/lib/Drupal/Core/Archiver/ArchiveTar.php
core/lib/Drupal/Core/Command/DbDumpCommand.php
core/lib/Drupal/Core/Command/GenerateProxyClassCommand.php
core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
core/lib/Drupal/Core/ProxyClass/Batch/BatchStorage.php
core/lib/Drupal/Core/ProxyClass/Config/ConfigInstaller.php
core/lib/Drupal/Core/ProxyClass/Cron.php
core/lib/Drupal/Core/ProxyClass/Entity/ContentUninstallValidator.php
core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php
core/lib/Drupal/Core/ProxyClass/Extension/RequiredModuleUninstallValidator.php
core/lib/Drupal/Core/ProxyClass/Field/FieldModuleUninstallValidator.php
core/lib/Drupal/Core/ProxyClass/File/MimeType/ExtensionMimeTypeGuesser.php
core/lib/Drupal/Core/ProxyClass/File/MimeType/MimeTypeGuesser.php
core/lib/Drupal/Core/ProxyClass/Lock/DatabaseLockBackend.php
core/lib/Drupal/Core/ProxyClass/Lock/PersistentDatabaseLockBackend.php
core/lib/Drupal/Core/ProxyClass/PageCache/ChainResponsePolicy.php
core/lib/Drupal/Core/ProxyClass/ParamConverter/AdminPathConfigEntityConverter.php
core/lib/Drupal/Core/ProxyClass/ParamConverter/MenuLinkPluginConverter.php
core/lib/Drupal/Core/ProxyClass/Plugin/CachedDiscoveryClearer.php
core/lib/Drupal/Core/ProxyClass/Render/BareHtmlPageRenderer.php
core/lib/Drupal/Core/ProxyClass/Routing/MatcherDumper.php
core/lib/Drupal/Core/ProxyClass/Routing/RouteBuilder.php
core/modules/book/src/ProxyClass/BookUninstallValidator.php
core/modules/field/src/ProxyClass/FieldUninstallValidator.php
core/modules/filter/src/ProxyClass/FilterUninstallValidator.php
core/modules/forum/src/ProxyClass/ForumUninstallValidator.php
core/modules/language/src/ProxyClass/LanguageConverter.php
core/modules/migrate_drupal/tests/fixtures/drupal6.php
core/modules/migrate_drupal/tests/fixtures/drupal7.php
core/modules/node/src/ProxyClass/ParamConverter/NodePreviewConverter.php
core/modules/simpletest/files/php-1.txt
core/modules/simpletest/files/php-2.php
core/modules/system/tests/fixtures/update/drupal-8.language-enabled.php
core/modules/system/tests/src/Kernel/Scripts/DbDumpCommandTest.php
core/modules/user/src/MigratePassword.php
core/modules/user/src/UserServiceProvider.php
core/modules/views_ui/src/ProxyClass/ParamConverter/ViewUIConverter.php
core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php

The apporach has been confirmed by @xjm in #2887052: Ignore Diff component files in phpcs coding standards.

Proposed resolution

Come up with the pattern(s) in core/phpcs.xml.dist so that we can ignore them cleanly.

Remaining tasks

  • Create pattern(s).
  • Create patch.
  • Review.
  • RTBC.
  • Commit.

User interface changes

None

API changes

None

Data model changes

None

Comments

jibran created an issue. See original summary.

jibran’s picture

Status: Active » Needs review
StatusFileSize
new19.98 KB

Only files with @codingStandardsIgnoreFile in core right now are

app/core/modules/user/src/MigratePassword.php
app/core/modules/user/src/UserServiceProvider.php

We should remove the files anyway.

Status: Needs review » Needs work

The last submitted patch, 2: remove-2891586-2.patch, failed testing. View results

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new20.01 KB

:/

tstoeckler’s picture

Status: Needs review » Needs work

So the proxy classes and database dump files are auto-generated by \Drupal\Core\Command\GenerateProxyClassCommand and \Drupal\Core\Command\DbDumpCommand, respectively. So we need to remove that line from the templates in those files. And ideally re-run them (at least on a couple files) to validate that the output still matches.

jibran’s picture

Status: Needs work » Needs review

And ideally re-run them (at least on a couple files) to validate that the output still matches.

I ran GenerateProxyClassCommand once for core and once for modules. Feel free to verify the DbDumpCommand.

jibran’s picture

So we need to remove that line from the templates in those files.

That's already done.

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Oops, I am a total dummy. Sorry about that!

xjm’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/phpcs.xml.dist
    @@ -8,7 +8,19 @@
    +  <exclude-pattern>./core/modules/*/tests/fixtures/*</exclude-pattern>
    

    I'm not sure about this; it's really broad. There are a lot more fixtures than the ones ignored:

    [ibnsina:drupal | Sun 14:18:18] $ ls -lR `find ./core -name "fixtures"` | grep "^-" | wc -l
         111

    Also, most of those 111 files are not intentionally empty or violating coding standards (which is what the header comment says).

  2. +++ b/core/phpcs.xml.dist
    @@ -8,7 +8,19 @@
    +  <exclude-pattern>./core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php</exclude-pattern>
    +  <exclude-pattern>./core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php</exclude-pattern>
    +  <exclude-pattern>./core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php</exclude-pattern>
    

    Hm, can we confirm with references that these should be considered "third-party code"? A blame/reference of the issue that added the the ignore would be nice to confirm this.

  3. +++ b/core/phpcs.xml.dist
    @@ -8,7 +8,19 @@
    +  <!--Exclude auto generated proxy classes. -->
    

    Nit: auto-generated.

    Also, it looks like this is missing an initial space. I introduced that problem in the other patch I think. The comment on the first section has neither an initial nor trailing space; the later ones have both initial and trailing spaces. AFAIK initial and trailing spaces are the correct standard.

  4. +++ b/core/phpcs.xml.dist
    @@ -8,7 +8,19 @@
    +  <exclude-pattern>./core/lib/Drupal/Core/ProxyClass/*</exclude-pattern>
    +  <exclude-pattern>./core/modules/*/src/ProxyClass/*</exclude-pattern>
    

    I wasn't sure about this, but I did confirm that the namespace for the proxy class is enforced:

          $proxy_filename = $namespace_root . '/ProxyClass/' . str_replace('\\', '/', $rest_fqcn) . '.php';
          $proxy_class_name = $root_namespace . '\\ProxyClass\\' . $rest_fqcn;
    
    

    I wonder if we could use something narrower than *? OTOH it's not that likely that we're going to add other things with this namespace pattern if they aren't the generated classes.

xjm’s picture

Another thing to note is that a trailing asterisk doesn't seem to be necessary to recursively match all the files within a directory (see the diff rule and others). So we could probably be consistent about that too.

xjm’s picture

For #2, I noticed this as well when looking into the other issue. Yet another issue probably? And 8.4.x-only for that issue since (unfortunately) file removals can be disruptive when backported.

If we tighten the rules up on this one, I think we can probably consider it for backport since then it would just be implementing the same coding standards coverage and avoiding branch divergence.

Thanks!

jibran’s picture

StatusFileSize
new1.98 KB
new20.18 KB

Thanks, for the review.

  1. Updated the comment. The fixtures file shouldn't be included imo.
  2. #1552744: Bootstrap for the Dependency Injection Container and make sure SimpleTest abides to it, #1939660: Use YAML as the primary means for service registration and #1972300: Write a more scalable dispatcher
  3. Fixed.
  4. This is borrowed from example.gitingore pattern. I don't see a reason to narrow this. This rule is core only and core enforces this namespace. If this would include contrib then narrowing it would have made sense IMHO.
  5. Fixed the trailing asterisks as well.
xjm’s picture

Updated the comment. The fixtures file shouldn't be included imo.

The thing is it's not just one or a handful of files. There are over 100 test fixtures, 57 of which are PHP files, and clearly the majority already comply with our coding standards. I don't think we should disregard coding standards on arbitrary PHP test fixtures.

Ideally this patch would mostly replace the current ignore comments so that the same files are ignored, rather than significantly broadening the scope of what's ignored.

Thanks for the issue links in #12.2. It doesn't look like any of those issues added the comments to ignore the files though? Edit: What I'm trying to get at is the reasoning behind the decision to ignore them in each case, which presumably is discussed in the issues where we started ignoring them.

jibran’s picture

Sorry, I linked to the original issues in which file we introduced.
These are the issues which added the ignore comment to those files #2572307: Fix 'Generic.PHP.UpperCaseConstant' coding standard and #2572619: Fix 'Drupal.Classes.ClassDeclaration' coding standard.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new19.58 KB

Reroll after #2887052: Ignore Diff component files in phpcs coding standards.

@xjm how would you like to proceed with this?

Status: Needs review » Needs work

The last submitted patch, 16: remove-2891586-16.patch, failed testing. View results

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

quietone’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#3207968: Replace @codingStandards comments with phpcs: comments