Problem/Motivation

Part of #2571965: [meta] Fix PHP coding standards in core, stage 1.

Steps to reproduce

Proposed resolution

Commented out code often exceeds the line length. For these, keep the code as is and and ignore lines around the code. See #2742881: Can inline comments end with semicolons and #2607574: Don't add dot with inline comments containing code with semicolon.

  • Tests - postpone. Some tests use @testWith with very long lines..

Completed

This issue will enable the sniff and fix any remaining problems.

Find issues in each group by

  1. Add <rule ref="Drupal.Files.LineLength"/> to phpcs.xml.dist
  2. Run phpcs --standard=core/phpcs.xml.dist --report-width=250 --report=code > a.txt
  3. Grep the results as needed

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-2572709

Command icon 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:

Comments

attiks created an issue. See original summary.

Status: Needs review » Needs work

The last submitted patch, Drupal.Files_.LineLength.patch, failed testing.

attiks’s picture

Status: Needs work » Needs review

Empty patch

duaelfr’s picture

Issue tags: -Novice

As agreed between the mentors at Drupalcon, according to issues to avoid for novices, I am untagging this issue as "Beginner". This issue contains changes across a very wide range of files and might create too many other patches to need to be rerolled at this particular time. This patch has an automated way to be rerolled later so better to implement it after Drupalcon.

attiks’s picture

Status: Needs review » Closed (won't fix)

Closing since it is not blacklisted in phpcs.xml

attiks’s picture

Status: Closed (won't fix) » Needs work

Closed the wrong one, this needs a manual patch probably

pfrenssen’s picture

Issue summary: View changes

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

vprocessor’s picture

Assigned: Unassigned » vprocessor
vprocessor’s picture

Assigned: vprocessor » Unassigned
Status: Needs work » Needs review
StatusFileSize
new489 bytes

all is ok there after phpcbf work

output:
----------------------------------------------------
No fixable errors were found
Time: 4 mins, 10.39 secs; Memory: 125.25Mb

alexpott’s picture

Status: Needs review » Needs work

@vprocessor this is because phpcbf can't fix these errors. If you run phpcs you will see a lot of warnings about lines being too long.

vprocessor’s picture

Assigned: Unassigned » vprocessor
pfrenssen’s picture

Issue summary: View changes
pfrenssen’s picture

Issue summary: View changes
andypost’s picture

Version: 8.1.x-dev » 8.2.x-dev

Looks the sniffer does not work cos "phpcs" returns nothing

pfrenssen’s picture

Issue summary: View changes
andypost’s picture

1197 Drupal.Files.LineLength.TooLong

vprocessor’s picture

Assigned: vprocessor » Unassigned
Status: Needs work » Needs review
dawehner’s picture

Status: Needs review » Needs work

Given #17 this is needs work

mile23’s picture

Issue summary: View changes

Patch in #10 no longer applies. Not marking as 'needs reroll' because whoever works on this should just re-do the work.

I'd wager that the rule in question here can't fix the errors it finds through phpcfb, which is why no errors were found in #10.

Updating instructions.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new26.06 KB

Here's a patch which only covers core/lib/Drupal/Component.

Pretty tedious work, also tedious to review. Should we split it up by directory? By module?

Also: The sniff doesn't count multibyte chars properly, so you end up with an error in core/lib/Drupal/Component/Utility/Html.php comments.

alexpott’s picture

The sniff doesn't count multibyte chars properly, so you end up with an error in core/lib/Drupal/Component/Utility/Html.php comments.

We need to fix the sniff then.

mile23’s picture

Status: Needs review » Postponed

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mile23’s picture

Version: 8.3.x-dev » 8.2.x-dev
Status: Postponed » Needs review
StatusFileSize
new27.09 KB
new2.83 KB

From #2761027: False positive for Drupal.Files.LineLength for multibyte characters it turns out we need to do this:

@klausi: Make sure to set <arg name="encoding" value="utf-8"/> in your phpcs.xml file.

So here's a patch against 8.2.x since it's docs-only changes, for the Component namespace.

I experimentally removed the LineLength rule and left the UTF-8 encoding. phpcs didn't burp on anything, so it looks safe to add it.

dawehner’s picture

Is it on purpose that we just fix the component bits?

mile23’s picture

Because there's no automated fix, and we're changing the line length of comments by hand. And then we have to review the changes. See #21.

Everett Zufelt’s picture

I tested the patch in #2572709-25: [meta] Fix 'Drupal.Files.LineLength' coding standard there are no warnings for core/lib/Drupal/Component .

Is the plan to have one large patch, or to break this in to sections?

Everett Zufelt’s picture

I find it interesting that some of the first warnings in core are permissible in the coding standards, but not caught by the sniff. Perhaps it is worth identifying these so that the sniff can be updated prior to attempting to correct all of the files?

E.g.

FILE: .../core/core.api.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
----------------------------------------------------------------------
68 | WARNING | Line exceeds 80 characters; contains 93 characters
...

* - @link https://www.drupal.org/project/examples Examples project (sample modules) @endlink

The sniff appears to account for @link exceeding 80 chars, but not when it is in a list.

mile23’s picture

@Everett Zufelt Could you please file an issue about that in the coder project?

alexpott’s picture

@Everett Zufelt the plan with these issue is to get the coder sniff fixed and then apply it in one go to core and the enforce the rule on all following patches to prevent regression.

Everett Zufelt’s picture

Everett Zufelt’s picture

StatusFileSize
new14.48 KB
new41.57 KB

Added corrections for

/core/core.api.php
/core/includes

Based on Coder 8.x-2.x, the 8.x-2.9 release does not include the fix mentioned in comment #33.

Everett Zufelt’s picture

In /core/lib/Drupal/Core/Cache/Cache.php line 99 @deprocated is used. followed by a Use comment.

   * @deprecated
   *   Use assert('\Drupal\Component\Assertion\Inspector::assertAllStrings($tags)');

There are no examples of @deprocated in the comment standards. Is there a better way for this to be presented (perhaps using @code) or should this be allowed to exceed 80 chars?

dawehner’s picture

+++ b/core/includes/bootstrap.inc
@@ -726,7 +726,7 @@ function drupal_installation_attempted() {
  *
- * @return string|null $profile
+ * @return string|null

unrelated change

Everett Zufelt’s picture

@dawehner, I agree it is not directly related. It is however not permitted in the commenting standards, and is identified as an error by Coder 8.x-2.x.

mile23’s picture

Status: Needs review » Needs work

Thanks, but the scope of this issue is for Drupal.Files.LineLength only. There are other issues for other rules: #2571965: [meta] Fix PHP coding standards in core, stage 1 That way the process of fixing these things is more manageable and consistent.

Also, we're normalizing on coder 8.2.8 for now: #2744463: Add phpcs, coder 8.2.8 as --dev requirements for drupal/core

dawehner’s picture

@Mile23
Thank you for making that clear!

I hope one day we establish a culture of not considering to even think about out of scope changes.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.

andypost’s picture

Version: 8.4.x-dev » 8.5.x-dev
Related issues: +#2923670: The one-line summary of ImageEffectInterface::getDerivativeExtension() is too long
ivan berezhnov’s picture

Issue tags: +CSKyiv18

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.

izus’s picture

Assigned: Unassigned » izus

working on this

izus’s picture

StatusFileSize
new134.68 KB

Hi,
this one is an eyes killer, so i'll stop it for today
the final patch promesses to be huge
here i attach a patch for my progress on this but the work stills in progress
will upload WIP patches as i progress on this

izus’s picture

StatusFileSize
new134.05 KB

Patch #47 no longer applies
here is a reroll of it
Thanks

izus’s picture

StatusFileSize
new137.69 KB

progressed on this but it stills WIP

izus’s picture

StatusFileSize
new143.29 KB

more progress

izus’s picture

Assigned: izus » Unassigned
Status: Needs work » Needs review
StatusFileSize
new144.1 KB

And here it is ready for review

izus’s picture

yay, it's green :)

alexpott’s picture

@izus thank you for picking this up and working on it. Here is the start of a review. Unfortunately it is a really big job to get core to comply with our own standards :(

  1. +++ b/core/modules/block_content/block_content.install
    @@ -42,7 +42,8 @@ function block_content_update_8002() {
     /**
    - * Add 'revision_created' and 'revision_user' fields to 'block_content' entities.
    + * Add 'revision_created' and 'revision_user' fields to 'block_content'
    + * entities.
      */
     function block_content_update_8003() {
    

    This displayed to a user and we have a rule that the first line must be on one line for a method.

  2. +++ b/core/modules/block_content/src/BlockContentInterface.php
    @@ -20,7 +20,8 @@
    +   *   \Drupal\Core\Entity\RevisionLogInterface::getRevisionLogMessage()
    +   * instead.
    
    @@ -45,7 +46,8 @@ public function setInfo($info);
    +   *   \Drupal\Core\Entity\RevisionLogInterface::setRevisionLogMessage()
    +   * instead.
    

    The instead should be indented.

  3. +++ b/core/modules/block_content/tests/src/Functional/Views/RevisionRelationshipsTest.php
    @@ -9,7 +9,8 @@
    - * Tests the integration of block_content_revision table of block_content module.
    + * Tests the integration of block_content_revision table of block_content
    + * module.
    

    The one line method rule

  4. +++ b/core/modules/book/src/BookManagerInterface.php
    @@ -275,7 +275,8 @@ public function bookTreeCheckAccess(&$tree, $node_links = []);
    +   *   A subtree of book links in an array, in the order they should be
    +   * rendered.
    

    Should be indented

  5. +++ b/core/modules/ckeditor/tests/modules/src/Plugin/CKEditorPlugin/LlamaButton.php
    @@ -5,7 +5,8 @@
    - * Defines a "LlamaButton" plugin, with a toolbar builder-enabled "llama" feature.
    + * Defines a "LlamaButton" plugin, with a toolbar builder-enabled "llama"
    + * feature.
      *
    

    One line rule.

  6. +++ b/core/modules/ckeditor/tests/src/Functional/CKEditorLoadingTest.php
    @@ -77,7 +77,8 @@ protected function setUp() {
    +    // - doesn't have access to the filtered_html text format, so: no text
    +    // editor.
    

    The second line of a list should be indented.

  7. +++ b/core/modules/comment/comment.tokens.inc
    @@ -151,8 +151,8 @@ function comment_tokens($type, $tokens, array $data, array $options, BubbleableM
    +          // Add the user cacheability metadata in case the author of the
    +          //  comment is not the anonymous user.
    

    Indentation

  8. +++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
    @@ -630,7 +630,8 @@ public function testViewsTranslationUI() {
    -   * Test the number of source elements for plural strings in config translation forms.
    +   * Test the number of source elements for plural strings in config translation
    +   * forms.
    

    One line rule.

  9. +++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
    @@ -1167,7 +1169,8 @@ protected function assertDisabledTextarea($id) {
    -   * Helper function that returns a .po file with a given number of plural forms.
    +   * Helper function that returns a .po file with a given number of plural
    +   * forms.
    
    +++ b/core/modules/config_translation/tests/src/Kernel/Migrate/d6/MigrateSystemMaintenanceTranslationTest.php
    @@ -28,7 +28,8 @@ protected function setUp() {
    -   * Tests migration of system (maintenance) variables to system.maintenance.yml.
    +   * Tests migration of system (maintenance) variables to
    +   * system.maintenance.yml.
    

    One line rule

  10. +++ b/core/modules/content_translation/content_translation.module
    @@ -531,7 +531,8 @@ function content_translation_language_configuration_element_process(array $eleme
    - * Form validation handler for element added with content_translation_language_configuration_element_process().
    + * Form validation handler for element added with
    + * content_translation_language_configuration_element_process().
    
    @@ -554,7 +555,8 @@ function content_translation_language_configuration_element_validate($element, F
    - * Form submission handler for element added with content_translation_language_configuration_element_process().
    + * Form submission handler for element added with
    + * content_translation_language_configuration_element_process().
    

    More one line rule.

It looks like there is plenty to do because we don't have all the other rules implemented yet. I think before we tackle this one we should try to fix Drupal.Commenting.DocComment.ShortSingleLine first. It should be a sub-issue of #2572635: Fix 'Drupal.Commenting.DocComment.LongFullStop' coding standard as doing that will help us not introduce more instances of that here.

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.

daffie’s picture

Status: Needs review » Needs work

The remarks of @alexpott from comment #53 still need to be addressed.

narendra.rajwar27’s picture

Assigned: Unassigned » narendra.rajwar27
narendra.rajwar27’s picture

StatusFileSize
new125.47 KB

Re-created the patch using comment #51 patch. Also made changes as per comment #53.
There are some files which are either not available in d9 or they have already fix applied for line exceeding 80 chars issue.
Here i am mentioning those files:

core/modules/block_content/block_content.install
core/modules/block_content/src/BlockContentInterface.php
core/modules/block_content/tests/src/Kernel/Views/RevisionRelationshipsTest.php
core/modules/comment/tests/src/Kernel/CommentUninstallTest.php
core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php
core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
core/modules/rest/src/Tests/RESTTestBase.php
core/modules/rest/tests/fixtures/update/rest-export-with-authentication-correction.php
core/modules/rest/tests/src/Functional/EntityResource/BlockContent/BlockContentResourceTestBase.php
core/modules/rest/tests/src/Functional/EntityResource/BlockContentType/BlockContentTypeResourceTestBase.php
core/modules/rest/tests/src/Functional/EntityResource/ConfigTest/ConfigTestResourceTestBase.php
core/modules/rest/tests/src/Functional/EntityResource/ContentLanguageSettings/ContentLanguageSettingsResourceTestBase.php
core/modules/rest/tests/src/Functional/EntityResource/EntityTest/EntityTestResourceTestBase.php
core/modules/rest/tests/src/Functional/EntityResource/EntityTestBundle/EntityTestBundleResourceTestBase.php
core/modules/rest/tests/src/Functional/EntityResource/EntityTestLabel/EntityTestLabelResourceTestBase.php
core/modules/rest/tests/src/Functional/EntityResource/RestResourceConfig/RestResourceConfigResourceTestBase.php
core/modules/taxonomy/src/TermForm.php
core/modules/tracker/tracker.module

So it will be great if someone can review and share feedback, if this needs more work.

narendra.rajwar27’s picture

Assigned: narendra.rajwar27 » Unassigned
Status: Needs work » Needs review
daffie’s picture

Status: Needs review » Needs work

The testbot returns 900 coding standard violations for the current patch. See: https://www.drupal.org/pift-ci-job/1710079.

narendra.rajwar27’s picture

Assigned: Unassigned » narendra.rajwar27
narendra.rajwar27’s picture

Assigned: narendra.rajwar27 » Unassigned

Probably pick this again once get the ample time to fix this. Meanwhile Please feel free to fix as i am unassigning this.

sanjayk’s picture

Assigned: Unassigned » sanjayk
sanjayk’s picture

Assigned: sanjayk » Unassigned
Status: Needs work » Needs review

I have create a new issue for coding standard issues here https://www.drupal.org/project/drupal/issues/3156059.

pasqualle’s picture

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.

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.

daffie’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
ankithashetty’s picture

Assigned: Unassigned » ankithashetty

Working on the reroll, thanks!

ankithashetty’s picture

Assigned: ankithashetty » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new118.79 KB
new89.69 KB

Re-rolled the patch in #59, thank you!

daffie’s picture

Status: Needs review » Needs work

Far too many style guide violations to review.

jonathan1055’s picture

Shouldn't this work be halted until #3173782: Increase line length limit to 120 is decided? If the length is increased, even to 100 chars, then a huge number of these current failings will no longer be a problem.

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.

rifas-ali-pbi made their first commit to this issue’s fork.

quietone’s picture

Issue summary: View changes
Status: Needs work » Postponed

@rifas-ali-pbi, credit for creating a fork has been removed per How is credit granted for Drupal core issues.

Yes, let's postpone.

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.

quietone’s picture

Title: Fix 'Drupal.Files.LineLength' coding standard » [meta] Fix 'Drupal.Files.LineLength' coding standard
Issue summary: View changes
Status: Postponed » Active

I've been taking a closer look at this over the holiday period. I am un-postponing this because most new code is wrapped at 80 columns and while there are a lot of files to change, it is a small percentage. And even increasing the line length will not fix wrapping.

quietone’s picture

Issue summary: View changes
quietone’s picture

Issue summary: View changes
quietone’s picture

Issue summary: View changes
nod_’s picture

Should this meta add the phpcs rule, or we leave that to a child issue?

quietone’s picture

Issue summary: View changes
quietone’s picture

Issue summary: View changes
quietone’s picture

Issue summary: View changes
quietone’s picture

Issue summary: View changes
quietone’s picture

Issue summary: View changes
quietone’s picture

Issue summary: View changes
quietone’s picture

Issue summary: View changes

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.