Postponed on #3054969: Add sniff for \Drupal vs Drupal

Problem/Motivation

The leading \ for class names is not used consistently. This issue started out fixing all the occurrences in core. That changed in #7 to fixing only the *.api.php files.

Original Issue Summary

Let's fix it.

Steps to reproduce

Proposed resolution

Reroll the patch to save any changes that may be useful to another issue
Make a new patch with only the change to *.api.php files

Remaining tasks

Does Drupal Code Builder somehow parse them to do the code generation? See #30
What exactly is the bug that's being caused is and does this fix it. See #30
New sniff #3054969: Add sniff for \Drupal vs Drupal
Review
Commit

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#29 2859992-28.patch15.34 KBquietone
#28 2859992-27.patch32.56 KBquietone
#13 2859992-12.patch54.03 KBpk188
#11 2859992-11.patch54.1 KBpk188
#2 2859992-2.patch55.18 KBAnonymous (not verified)

Comments

Anonymous’s picture

vaplas created an issue. See original summary.

Anonymous’s picture

Status: Active » Needs review
StatusFileSize
new55.18 KB
opensense’s picture

Patch applies cleanly and the changes work well.

opensense’s picture

Status: Needs review » Reviewed & tested by the community
opensense’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Closed (won't fix)
+++ b/core/includes/update.inc
@@ -9,6 +9,8 @@
+use Drupal\Core\Language\Language;
+use Drupal\Core\Language\LanguageInterface;

This suggests that update_language_list() should just be removed. Instead of adding these use statements here - can we file a separate issue to remove this method - it is obviously not working. It'd error immediately. It was added without usage in #1754246: Languages should be configuration entities.

The rest of the patch is a mixture of different types of coding standards for example:

+++ b/core/lib/Drupal/Component/Gettext/PoHeader.php
@@ -188,7 +188,7 @@ public function __toString() {
-   * @throws Exception
+   * @throws \Exception

+++ b/core/lib/Drupal/Component/Gettext/PoItem.php
@@ -104,7 +104,7 @@ public function getSource() {
-   * @param string or array $source
+   * @param string|array $source

+++ b/core/lib/Drupal/Core/Archiver/ArchiveTar.php
@@ -632,7 +632,8 @@ public function extractModify($p_path, $p_remove_path, $p_preserve = false)
+     * @return string|null $v_result
+     *   A string with the file content or NULL.

@throws, @param and @return. These should be addressed by the coding standards project. One at a time and by enabling coding standards rules in phpcs.xml.dist so that we don't introduce regressions.

In order to fix core coding standards in a maintainable way, all our coding standards issues should be done on a per-rule basis across all of core, rather than fixing standards in individual modules or files. We should also separate fixes where we need to write new documentation from fixes where we need to correct existing standards. This all should be done as part of #2571965: [meta] Fix PHP coding standards in core, stage 1. A good place to start is the child issues of #2572645: [Meta] Fix 'Drupal.Commenting.FunctionComment' coding standard.

For background information on why we usually will not commit coding standards fixes that aren't scoped in that way, see the core issue scope guidelines, especially the note about coding standards cleanups. That document also includes numerous suggestions for scoping issues including documentation coding standards cleanups.

Contributing to the overall plan above will help ensure that your fixes for core's coding standards remain in core the long term.

alexpott’s picture

Status: Closed (won't fix) » Needs work
Issue tags: +Needs followup

@xjm pointed out that I closed this prematurely.

  • We agreed that the fixes to *.api.php are good and could be in-scope for this issue if we change the issue summary that way.
  • We need to ensure that issues already exist to implement coder rules (if missing) and apply to them to core to fix the coding standards related changes (@param, @throws, @return, @var)
  • We need a separate issue filed about update_language_list()
+++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
@@ -6,6 +6,7 @@
+use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;

@@ -34,7 +35,7 @@ public function __construct(ParameterBagInterface $parameterBag = NULL) {
-   * @return InstantiatorInterface
+   * @return \Symfony\Component\DependencyInjection\LazyProxy\Instantiator\RealServiceInstantiator

This is another reason why doing this via coding standards is good. This file intentionally follows Synfony's coding standards where this @return is valid.

alexpott’s picture

@vidhatanand thank you for reviewing this issue!

The automated testing infrastructure tells us whether the patch applies, so we do not need people to review that. It is also not sufficient criteria for the issue to be marked "Reviewed and Tested by the Community".

What we do need people to review is whether the issue has a correct scope, whether it passes the core gates, whether the solution completely fixes the problem without introducing other problems, and whether it's the best solution we can come up with. See the patch review guide for more information.

When you do post a review, be sure to describe what you reviewed and how. This helps other reviewers understand why you considered the issue RTBC (and is considered for issue credit).

Anonymous’s picture

Issue tags: +php-novice, +Novice

@alexpott, many thanks for such a detailed explanation!

We need a separate issue filed about update_language_list()

Done. #2860277: update_language_list() should be removed

I am also very grateful to @xjm for taking care of the bit right part of the patch, and to @vidhatanand for interest in this idea!

ashishdalvi’s picture

Issue tags: +dcm2017
pk188’s picture

Status: Needs work » Needs review
StatusFileSize
new54.1 KB

Re rolled because last one failed to apply.

Status: Needs review » Needs work

The last submitted patch, 11: 2859992-11.patch, failed testing.

pk188’s picture

Status: Needs work » Needs review
StatusFileSize
new54.03 KB
vegantriathlete’s picture

Issue tags: +dcco2017
mile23’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

This seems like a lot of different types of cleanups. I think they're all probably decent changes. But we're about to have 8.4-alpha, so some might be allowed changes and some might not by the time this gets reviewed. See the list of allowed changes here: https://www.drupal.org/core/d8-allowed-changes#alpha

Check out the links from #8 and maybe split this up into different issues depending on whether you think they'd be allowed in alpha.

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.

michaellenahan’s picture

Issue tags: -dcm2017, -dcco2017 +Vienna2017
ivan berezhnov’s picture

Issue tags: +CSKyiv18
arunkumark’s picture

Assigned: Unassigned » arunkumark
arunkumark’s picture

Assigned: arunkumark » Unassigned

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

Title: Drupal core contains several bad namespace » [PP - 1] Consistent use of leading \ in class names in *.api.php files
Issue summary: View changes
Issue tags: -, -Novice, -Needs issue summary update
Parent issue: » #3188974: [Meta] Consistent use of leading \ for class names

Patch 12 contained changes for 73 files and this reroll has changes for 43. Nice to know that many of these fixes has already happened.

The patch remains a mixture of fixing different coding standards and no tests are being run on it. #7 says this should be about the *.api.php files and I'll do a patch for that next.

quietone’s picture

StatusFileSize
new32.56 KB

forgot to upload the patch. This is the reroll mentioned above.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new15.34 KB

This patch is just the changes for *.api.php files plus the patch from #3089634: missing initial backslash on parameter interface typehints in entity.api.php.

Changing to NR to run tests.

quietone credited robindh.

quietone’s picture

Category: Bug report » Task
Issue summary: View changes
Status: Needs review » Postponed
Related issues: +#3089634: missing initial backslash on parameter interface typehints in entity.api.php

There is 3089634#15 from xjm in #3089634: missing initial backslash on parameter interface typehints in entity.api.php that is worth duplicating here.

xjm pointed out that *.api.php are just documentation and asked if Drupal Code Builder somehow parse them to do the code generation?
I personally would want to ensure this was fixed at least in all *.api.php either way. A sniff has still not been created yet and other *.api.php are also wrong, including in hook signatures and the like.

If we could get clarity on what exactly the bug that's being caused is, that'd make it easier to make sure we're fixing that bug completely (here and/or elsewhere).

This issue now covers all *.api.php file.

Closed #3089634: missing initial backslash on parameter interface typehints in entity.api.php as a duplicate and added credit here.

quietone’s picture

#7.3 Add the follow made as a related issue #2860277: update_language_list() should be removed

quietone’s picture

Title: [PP - 1] Consistent use of leading \ in class names in *.api.php files » [PP - 1] Consistent use of leading \ for class names in *.api.php files
quietone’s picture

Title: [PP - 1] Consistent use of leading \ for class names in *.api.php files » [PP-1] Consistent use of leading \ for class names in *.api.php files

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.