Postponing on #2464123: Remove the requirement that no blank line follow an inline comment.

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

Approach

We are testing coding standards with PHP CodeSniffer, using the Drupal coding standards from the Coder module. Both of these packages are not installed in Drupal core. We need to do a couple of steps in order to download and configure them so we can run a coding standards check.

Step 1: Add the coding standard to the whitelist

Every coding standard is identified by a "sniff". For example, an imaginary coding standard that would require all llamas to be placed inside a square bracket fence would be called the "Drupal.AnimalControlStructure.BracketedFence sniff". There are dozens of such coding standards, and to make the work easier we have started by only whitelisting the sniffs that pass. For the moment all coding standards that are not yet fixed are simply skipped during the test.

Open the file core/phpcs.xml.dist and add a line for the sniff of this ticket. The sniff name is in the issue title. Make sure your patch will include the addition of this line.

Step 2: Install PHP CodeSniffer and the ruleset from the Coder module

Both of these packages are not installed by default in Drupal core, so we need to download them. This can be done with Composer, from the root folder of your Drupal installation:

$ composer require drupal/coder squizlabs/php_codesniffer
$ ./vendor/bin/phpcs --config-set installed_paths ../../drupal/coder/coder_sniffer

Once you have installed the phpcs package, you can list all the sniffs available to you like this:

$ ./vendor/bin/phpcs --standard=Drupal -e

This will give you a big list of sniffs, and the Drupal-based ones should be present.

Step 3: Prepare the phpcs.xml file

To speed up the testing you should make a copy of the file phpcs.xml.dist (in the core/ folder) and save it as phpcs.xml. This is the configuration file for PHP CodeSniffer.

We only want this phpcs.xml file to specify the sniff we're interested in. So we need to remove all the rule items, and add only our own sniff's rule. Rule items look like this:

<rule ref="Drupal.Commenting.InlineComment.SpacingAfter"/>

Remove all of them, and add only the sniff from this issue title. This will make sure that our tests run quickly, and are not going to contain any output from unrelated sniffs.

Step 4: Run the test

Now you are ready to run the test! From within the core/ folder, run the following command to launch the test:

$ cd core/
$ ../vendor/bin/phpcs -p

This takes a couple of minutes. The -p flag shows the progress, so you have a bunch of nice dots to look at while it is running.

Step 5: Fix the failures

When the test is complete it will present you a list of all the files that contain violations of your sniff, and the line numbers where the violations occur. You could fix all of these manually, but thankfully phpcbf can fix many of them. You can call phpcbf like this:

$ ../vendor/bin/phpcbf

This will fix the errors in place. You can then make a diff of the changes using git. You can also re-run the test with phpcs and determine if that fixed all of them.

Comments

attiks created an issue. See original summary.

attiks’s picture

Title: Fix 'Drupal.Commenting.HookComment' coding standard » Fix 'InlineComment' coding standard
Issue summary: View changes
StatusFileSize
new500.84 KB

Status: Needs review » Needs work

The last submitted patch, 2: Drupal.Commenting.InlineComment.patch, failed testing.

The last submitted patch, 2: Drupal.Commenting.InlineComment.patch, failed testing.

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.

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.

mile23’s picture

Title: Fix 'InlineComment' coding standard » Fix 'Drupal.Commenting.InlineComment' coding standard
Assigned: Unassigned » mile23
Issue summary: View changes

Updated title and summary. Working on a patch.

mile23’s picture

StatusFileSize
new534.18 KB

Automated patch generated by phpcbf. It's basically un-reviewable....

I suggest we split this up into a bunch of patches: core/lib, core/includes, core/modules, and core/tests.

Should we make other issues or knock them down one at a time here?

mile23’s picture

Assigned: mile23 » Unassigned
jhedstrom’s picture

I spent a few minutes reviewing the mega patch, and didn't get very far, so +1 for smaller issues I think.

I found a lot in a short bit:

  1. +++ b/core/lib/Drupal/Core/Extension/module.api.php
    @@ -618,8 +618,7 @@ function hook_install_tasks_alter(&$tasks, $install_state) {
    +  // function hook_update_N() {.
    

    This doesn't look quite right :)

  2. +++ b/core/lib/Drupal/Core/Form/FormBuilder.php
    @@ -334,7 +334,7 @@ public function buildForm($form_id, FormStateInterface &$form_state) {
    +    // .
    
    @@ -513,7 +513,7 @@ public function retrieveForm($form_id, FormStateInterface &$form_state) {
    +    // .
    

    Or these.

  3. +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
    @@ -184,11 +184,11 @@ protected function doGenerate(array $variables, array $defaults, array $tokens,
    +    // [ [ 0 => 'text', 1 => '/admin/config' ] ].
    

    Many of these would probably benefit from being wrapped in @code blocks, but that seems out of scope here.

  4. +++ b/core/lib/Drupal/Core/StreamWrapper/LocalStream.php
    @@ -242,7 +242,7 @@ public function stream_eof() {
    +    // Fseek returns 0 on success and -1 on a failure.
    

    False positive. Should probably be "`fseek`"?

  5. +++ b/core/modules/big_pipe/src/Tests/BigPipePlaceholderTestCases.php
    @@ -49,7 +49,7 @@ public static function cases(ContainerInterface $container = NULL, AccountInterf
    +      [], // ['#type' => 'status_messages'],.
    

    More false positives.

pfrenssen’s picture

Yeah we definitely need to chunk this, it's not realistic to sign off on a humongous patch like this. Splitting by path will probably still be too large.

Shall we do it in chunks of 20kb max? That would be easy to review + commit. We can iterate here, and once we get to the final chunk we update the ruleset.

mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new10.11 KB

Concentrating on core/lib/Drupal/Component.

phpcbf does pretty well as a starting point, but does require review.

Code that's obviously been commented out gets deleted. :-)

The sniffer misses the finer points of grammar (adding a period in the wrong place).

phpcs also gives some false positives on inline /** @var */ comments. See: #2305593: [policy] Set a standard for @var inline variable type declarations

We see a forbidden use of var in DiffFormatter: http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Component/Diff/Di...

...which triggers of a bunch of other issues including seeing that property's docblock as an inline comment.

So either I change it here so it's not a var, or we put this off until properties are properly declared. Ahh, scope, you cruel mistress.

mile23’s picture

pfrenssen’s picture

Patch from #13 looks good.

dawehner’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Component/Utility/Unicode.php
@@ -607,7 +607,7 @@ public static function strcasecmp($str1 , $str2) {
-      $chunk_size = 47; // floor((75 - strlen("=?UTF-8?B??=")) * 0.75);

We should not drop this comment, this has helpful information in there.

dawehner’s picture

Title: Fix 'Drupal.Commenting.InlineComment' coding standard » Fix 'Drupal.Commenting.InlineComment' coding standard in Drupal\Component
mile23’s picture

Status: Needs work » Needs review
StatusFileSize
new10.18 KB
new569 bytes

Thanks.

Added that comment back, as a proper inline comment, which is a bit ugly. Please suggest a better replacement.

pfrenssen’s picture

Status: Needs review » Reviewed & tested by the community

It's not the most beautiful line of documentation encountered by mankind, but it is very clear and legible :) Back to RTBC, thanks!

The last submitted patch, 9: 2572659_9.patch, failed testing.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/lib/Drupal/Component/Utility/Tags.php
    @@ -20,7 +20,9 @@ class Tags {
         // This regexp allows the following types of user input:
    +    // @code
         // this, "somecompany, llc", "and ""this"" w,o.rks", foo bar
    +    // @endcode
    

    Is user input code? Tricky.

  2. +++ b/core/lib/Drupal/Component/Utility/Unicode.php
    @@ -607,7 +607,8 @@ public static function strcasecmp($str1 , $str2) {
    +      // Chunk size: floor((75 - strlen("=?UTF-8?B??=")) * 0.75); .
    

    Looks odd

  3. +++ b/core/lib/Drupal/Component/Utility/UserAgent.php
    @@ -40,10 +40,15 @@ public static function getBestMatchingLangcode($http_accept_language, $langcodes
    +    // @code
         //   Accept-Language = "Accept-Language" ":"
         //                  1#( language-range [ ";" "q" "=" qvalue ] )
         //   language-range  = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )
    -    // Samples: "hu, en-us;q=0.66, en;q=0.33", "hu,en-us;q=0.5"
    +    // @endcode
    ...
    +    // @code
    +    //   "hu, en-us;q=0.66, en;q=0.33", "hu,en-us;q=0.5"
    +    // @endcode
    

    I don't think code should be indented and is this code?

Also how many fails are there to fix if we apply this rule to all of core... and maybe it'd be better to fix by sub -sniff in core entirely?

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new544.85 KB

Auto fix for all core phpcbf --sniffs=Drupal.Commenting.InlineComment core

Status: Needs review » Needs work

The last submitted patch, 22: fix-2572659-1.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new544.46 KB

drop is moving

Status: Needs review » Needs work

The last submitted patch, 24: fix-2572659-2.patch, failed testing.

mile23’s picture

We really should limit scope here because, for instance, we have to review the patch in #24 and find things like this:

+++ b/core/includes/batch.inc
@@ -118,7 +118,6 @@ function _batch_progress_page() {
   else {
     // This is one of the later requests; do some processing first.
-
     // Error handling: if PHP dies due to a fatal error (e.g. a nonexistent
     // function), it will output whatever is in the output buffer, followed by

That's a fix that introduces another error: Word wrap at 80.

But as for #21, I really wish we had some better direction on what change is needed for:

+      // Chunk size: floor((75 - strlen("=?UTF-8?B??=")) * 0.75); .

The last submitted patch, 24: fix-2572659-2.patch, failed testing.

andypost’s picture

suppose we need to split the issue into parts (tests and code)
it really pita to review such size of patches

alexpott’s picture

So what we can do is not enable the entire rule. See #2707641-7: Ensure core compliance to Drupal.Commenting.FunctionComment.ParamCommentIndentation (part 2) For an example of how we can break this rule up into small amounts of work by excluding specific errors from the rule.

alexpott’s picture

Title: Fix 'Drupal.Commenting.InlineComment' coding standard in Drupal\Component » Fix 'Drupal.Commenting.InlineComment.SpacingAfter' coding standard
Status: Needs work » Needs review
StatusFileSize
new140.74 KB

So let's do Drupal.Commenting.InlineComment.SpacingAfter

Status: Needs review » Needs work

The last submitted patch, 30: 2572659-30.patch, failed testing.

alexpott’s picture

Version: 8.1.x-dev » 8.2.x-dev
  1. +++ b/core/includes/batch.inc
    @@ -118,7 +118,6 @@ function _batch_progress_page() {
         // This is one of the later requests; do some processing first.
    -
         // Error handling: if PHP dies due to a fatal error (e.g. a nonexistent
    
    +++ b/core/includes/pager.inc
    @@ -199,7 +199,6 @@ function template_preprocess_pager(&$variables) {
       // End of marker calculations.
    -
       // Prepare for generation loop.
    

    There are plenty of examples like this where we break wrapping... hmmm tricky.

  2. +++ b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
    @@ -66,7 +66,6 @@ public function load($file)
             // Not supported.
             //$this->container->addResource(new FileResource($path));
    -
             // empty file
             if (null === $content) {
                 return;
    @@ -75,7 +74,6 @@ public function load($file)
    
    @@ -75,7 +74,6 @@ public function load($file)
             // imports
             // Not supported.
             //$this->parseImports($content, $file);
    -
             // parameters
             if (isset($content['parameters'])) {
                 if (!is_array($content['parameters'])) {
    @@ -90,7 +88,6 @@ public function load($file)
    
    @@ -90,7 +88,6 @@ public function load($file)
             // extensions
             // Not supported.
             //$this->loadFromExtensions($content);
    -
             // services
             $this->parseDefinitions($content, $file);
    

    Not our standards so perhaps we should mark this file to be ignored?

alexpott’s picture

Let's do this against 8.2.x first.

mile23’s picture

Just a heads-up that I made a little script to help figure out how to work on some of these things: #2571965-63: [meta] Fix PHP coding standards in core, stage 1

andypost’s picture

pfrenssen’s picture

Issue summary: View changes
andypost’s picture

+++ b/core/phpcs.xml.dist
@@ -18,6 +18,14 @@
+  <rule ref="Drupal.Commenting.InlineComment">
+    <exclude name="Drupal.Commenting.InlineComment.DocBlock"/>
+    <exclude name="Drupal.Commenting.InlineComment.InvalidEndChar"/>
+    <exclude name="Drupal.Commenting.InlineComment.NoSpaceBefore"/>
+    <exclude name="Drupal.Commenting.InlineComment.NotCapital"/>
+    <exclude name="Drupal.Commenting.InlineComment.SpacingBefore"/>
+    <exclude name="Drupal.Commenting.InlineComment.WrongStyle"/>
+  </rule>

This fixes only SpacingAfter

      1 Drupal.Commenting.InlineComment.WrongStyle
     53 Drupal.Commenting.InlineComment.NoSpaceBefore
     99 Drupal.Commenting.InlineComment.SpacingBefore
    114 Drupal.Commenting.InlineComment.DocBlock
    151 Drupal.Commenting.InlineComment.NotCapital
    269 Drupal.Commenting.InlineComment.SpacingAfter
    703 Drupal.Commenting.InlineComment.InvalidEndChar
rasikap’s picture

Assigned: Unassigned » rasikap

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.

rasikap’s picture

Assigned: rasikap » Unassigned
Status: Needs work » Needs review
StatusFileSize
new151 KB

Status: Needs review » Needs work

The last submitted patch, 41: 2572659-41.patch, failed testing.

rasikap’s picture

Assigned: Unassigned » rasikap
rasikap’s picture

Assigned: rasikap » Unassigned
Status: Needs work » Needs review
StatusFileSize
new9.91 KB
dawehner’s picture

Status: Needs review » Needs work

The latest patch no longer contains a phpcs.xml.dist change. The issue summary describes how to fix CS issues.

rasikap’s picture

Assigned: Unassigned » rasikap
rasikap’s picture

Assigned: rasikap » Unassigned
Status: Needs work » Needs review
StatusFileSize
new866 bytes

Added phpcs.xml file

tstoeckler’s picture

Status: Needs review » Needs work

@rasikap We shouldn't add a new phpcs.xml file but instead amend the existing phpcs.xml.dist.

rasikap’s picture

Assigned: Unassigned » rasikap
rasikap’s picture

Assigned: rasikap » Unassigned
StatusFileSize
new261 bytes

@tstoeckler, added the ruleset in phpcs.xml.dist itself.

rasikap’s picture

Status: Needs work » Needs review

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

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now 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.

klausi’s picture

Status: Needs review » Needs work

The change in phpcs.xml.dist is on the wrong line, please insert it alphabetically with the other Durpal standard sniffs.

Then the fixes for the newly added sniff are missing? The patch should include those. While running this sniff I found a false positive, opened a Coder issue: #2851518: False positives in Drupal.Commenting.InlineComment.SpacingBefore for multi line comments.

Drupal 8.4.x currently does not even pass its own configured rules so I also filed #2851510: Fix phpcs regressions by running phpcbf.

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.

mfernea’s picture

Status: Closed (outdated) » Needs work

I was wrong. #2716685: Part 2: Fix several errors in the 'Drupal.Commenting.DocComment' coding standard fixed Drupal.Commenting.DocComment.SpacingAfter and this one targets Drupal.Commenting.InlineComment.SpacingAfter.

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new146.54 KB

Started again from scratch.

mfernea’s picture

Status: Needs review » Needs work

If I look at the test results there is still one issue to be solved.

jofitz’s picture

Status: Needs work » Needs review
StatusFileSize
new653 bytes
new147.18 KB

I don't know how that one slipped through. Fixed.

mfernea’s picture

While the patch is correct from the technical point of view, I have some mixed feelings about some type of changes like:

  1. +++ b/core/includes/batch.inc
    @@ -331,7 +330,6 @@ function _batch_process() {
         // Gather progress information.
    -
         // Reporting 100% progress will cause the whole batch to be considered
    
    +++ b/core/includes/errors.inc
    @@ -230,7 +230,6 @@ function _drupal_log_error($error, $fatal = FALSE) {
             // Without verbose logging, use a simple message.
    -
             // We call SafeMarkup::format() directly here, rather than use t() since
    

    Title like comments.

  2. +++ b/core/includes/pager.inc
    @@ -199,7 +199,6 @@ function template_preprocess_pager(&$variables) {
       // End of marker calculations.
    -
       // Prepare for generation loop.
    
    @@ -213,7 +212,6 @@ function template_preprocess_pager(&$variables) {
       // End of generation loop preparation.
    -
       // Create the "first" and "previous" links if we are not on the first page.
    

    Comment for end of code section.

Maybe it's best to remove the comments for the end of code sections. I'm not sure.

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.

idebr’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

#60 While I agree with your line of thought, for these type of issues it is typically best to leave the code as is and make the smallest change possible. Once you start refactoring, the issue will quickly escalate and become hard to actually get committed :)

Patch no longer applies to 8.6.x, so it will need to be rerolled.

savkaviktor16@gmail.com’s picture

Issue tags: -Needs reroll
StatusFileSize
new144.87 KB

Re-rolled

savkaviktor16@gmail.com’s picture

Status: Needs work » Needs review
nkoporec’s picture

Tested the #64, it applies cleanly and I think the comments look good now.

idebr’s picture

Status: Needs review » Needs work
+++ b/core/phpcs.xml.dist
@@ -82,6 +82,7 @@
+    <exclude name="Drupal.Commenting.InlineComment.WrongStyle"/>

The change in phpcs.xml.dist should make it stricter. This change removes a sniff instead.

The correct change to phpcs.xml.dist was in #59:

<rule ref="../vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/InlineCommentSniff.php">
  <!-- Sniff for: SpacingAfter -->
  <exclude name="Drupal.Commenting.InlineComment.DocBlock"/>
  <exclude name="Drupal.Commenting.InlineComment.InvalidEndChar"/>
  <exclude name="Drupal.Commenting.InlineComment.NoSpaceBefore"/>
  <exclude name="Drupal.Commenting.InlineComment.NotCapital"/>
  <exclude name="Drupal.Commenting.InlineComment.SpacingBefore"/>
  <exclude name="Drupal.Commenting.InlineComment.WrongStyle"/>
</rule>

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.

Shivalik’s picture

StatusFileSize
new233.39 KB

Review the patch.

idebr’s picture

Status: Needs work » Needs review
klausi’s picture

Status: Needs review » Needs work
+++ b/lib/Drupal/Component/DependencyInjection/Container.php
@@ -416,7 +416,7 @@ class Container implements ContainerInterface {
-   * @param array|\stdClass $arguments
+   * @param array|object $arguments

We should only fix Drupal.Commenting.InlineComment.SpacingAfter, not other things.

Please provide patches that only fix this rule and nothing else here.

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.

nginex’s picture

Issue tags: +LutskGCW20

Tagging for Drupal Global Contribution Weekend

jungle’s picture

Status: Needs work » Needs review
StatusFileSize
new166.5 KB

No interdiff as #69 did unexpected changes. it‘s meaningless to provide interdiff

jungle’s picture

BTW, all fixed by phpcbf, no manual changes.

foxtrotcharlie’s picture

Status: Needs review » Reviewed & tested by the community

I looked through the diff and it seems to remove all empty lines after inline comments, which is what was required.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/ban/tests/src/Functional/IpAddressBlockingTest.php
    @@ -81,7 +81,6 @@ public function testIPAddressValidation() {
         // $edit['ip'] = \Drupal::request()->getClientIP();
         // $this->drupalPostForm('admin/config/people/ban', $edit, t('Save'));
         // $this->assertText(t('You may not ban your own IP address.'));
    -
         // Test duplicate ip address are not present in the 'blocked_ips' table.
    

    This removal is odd because the commented out code is wrong - we need to find out why the code is commented out and resolve that.

  2. +++ b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
    @@ -160,7 +160,6 @@ public function testBigPipe() {
         // @see performMetaRefresh()
    -
         $this->drupalGet(Url::fromRoute('big_pipe_test'));
    

    Removals like this are good.

  3. +++ b/core/modules/editor/editor.module
    @@ -512,7 +512,6 @@ function editor_file_download($uri) {
       // about them.
       // @see file_file_download()
    -
       // Find out if any editor-backed field contains the file.
    

    Changes like this look wrong to me. The spacing here has meaning. The comments are not connected. I think that the rule needs fixing to allow a space between two inline comments.

  4. +++ b/core/modules/editor/tests/src/Kernel/EditorManagerTest.php
    @@ -31,7 +31,6 @@ protected function setUp() {
         // Install the Filter module.
    

    The filter module is already installed. This comment should be removed.

  5. +++ b/core/modules/editor/tests/src/Unit/EditorXssFilter/StandardTest.php
    @@ -56,7 +56,6 @@ public function providerTestFilterXss() {
         // All cases listed on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
    -
         // No Filter Evasion.
         // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#No_Filter_Evasion
         $data[] = ['<SCRIPT SRC=http://ha.ckers.org/xss.js></SCRIPT>', ''];
    

    This is a common pattern where the space has meaning. The first comment is about the entire coming section. and the next comment is specific to the following line of code. The new line has meaning and should not be removed.

tldr; personally I think we need to check whether this coding standard is actually a coding standard. As far as I can see it is not - https://www.drupal.org/node/1354

jungle’s picture

Thanks @alexpott for reviewing.

+++ b/core/modules/editor/editor.module
@@ -512,7 +512,6 @@ function editor_file_download($uri) {
   // about them.
   // @see file_file_download()
-
   // Find out if any editor-backed field contains the file.

Changes like this look wrong to me. The spacing here has meaning. The comments are not connected. I think that the rule needs fixing to allow a space between two inline comments.

I think the first comment could be moved out as a part of the comment of the function/method.

+++ b/core/modules/editor/tests/src/Unit/EditorXssFilter/StandardTest.php
@@ -56,7 +56,6 @@ public function providerTestFilterXss() {
     // All cases listed on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
-
     // No Filter Evasion.
     // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#No_Filter_Evasion
     $data[] = ['<SCRIPT SRC=http://ha.ckers.org/xss.js></SCRIPT>', ''];

This is a common pattern where the space has meaning. The first comment is about the entire coming section. and the next comment is specific to the following line of code. The new line has meaning and should not be removed.

The same, the first could be moved out as a part of the function/method comment. if one function/method has multiple sections, maybe it's a code smell. One way is to split it into small functions/methods. It's better that one function does one thing. Maybe, to move the inline comments of all sections out to the description of the function/method is reasonable. Code should be self-explained. It's untrue that the more comments, the better.

So about #77.3 and 5, my suggestion is to move out the first comment to the description of the function/method or to refactor the code itself.

alexpott’s picture

@jungle the more I think about it the more I think this coding standard is incorrect - at least in implementation. Sure the following case could be flagged:

     // @see performMetaRefresh()
-
     $this->drupalGet(Url::fromRoute('big_pipe_test'));

But doing something like

     // All cases listed on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
-
     // No Filter Evasion.
     // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#No_Filter_Evasion
     $data[] = ['<SCRIPT SRC=http://ha.ckers.org/xss.js></SCRIPT>', ''];

Is wrong. Space has meaning and that's a good thing. I think we should file an issue issue to either fix the coder coder so that we only flag this is the after the blank line there's code - or we file an issue to remove the rule from coder.

prabha1997’s picture

Assigned: Unassigned » prabha1997
prabha1997’s picture

Assigned: prabha1997 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new166.53 KB
new483 bytes

+++ b/core/modules/editor/tests/src/Kernel/EditorManagerTest.php
@@ -31,7 +31,6 @@ protected function setUp() {
// Install the Filter module.

I removed this comment. Plz review patch

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

+1 For the comment #79 from @alexpott. A lot of changes from the patch look wrong.

nikitagupta’s picture

Assigned: Unassigned » nikitagupta
nikitagupta’s picture

Status: Needs work » Needs review
StatusFileSize
new151.17 KB
nikitagupta’s picture

StatusFileSize
new149.87 KB

Reroll the patch and worked on #79

nikitagupta’s picture

Assigned: nikitagupta » Unassigned

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.

andypost’s picture

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

Assigned: Unassigned » ayushmishra206

Working on this.

ayushmishra206’s picture

Assigned: ayushmishra206 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new127.95 KB

Rerolled the patch for 9.2.x.

andypost’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs reroll

Latest patches missing Step 3 from issue summary - update default sniffers in core/phpcs.xml.dist with <rule ref="Drupal.Commenting.InlineComment.SpacingAfter"/>

See https://git.drupalcode.org/project/drupal/-/blob/9.2.x/core/phpcs.xml.di...

PS: updated IS with valid sniff name

longwave’s picture

I am in agreement with #60/#77.3/#77.5/#79 in that sometimes these blank lines are useful for readability and to split up groups of comments, so just removing them all is not the right answer and perhaps this isn't and shouldn't be a standard for us to follow, at least not with the sniff in it's current form.

quietone’s picture

Issue summary: View changes
Status: Needs work » Needs review

I came here to review. It is not helpful that these coding standard issue do not have a Remaining Task section in the IS. It just makes it harder for a reviewer.

I thought I would apply the latest patch and have a look. It does not have changes to phpcs.xml. I then searched backwards and found that it it does not appear to be in patch form #85 onwards.

Now, reading the comments from the top everything look like typical work on an issue. However, in #77-#79 there are serious questions raised about using this sniff. Despite those concerns prabha1997, nikitagupta, ayushmishra206 made patches which are not helping to advance the issue (and do not have a phpcs.xml file as mentioned).

Going back to the serious questions. In #79 alexpott states

tldr; personally I think we need to check whether this coding standard is actually a coding standard. As far as I can see it is not - https://www.drupal.org/node/1354

I agree, Drupal standards for in-line code comments states "Comments should be on a separate line immediately before the code line or block they reference. For example:" So, there isn't a strict requirement.

My two cents, when writing some tests I recall spending extra time to make in line comments that would pass this Drupal Practice standard. It was frustrating at the time but in the end I think the result was better readability. So, even though this sniff isn't a strict requirement I would be OK with it. Now, having that said that I will go with the consensus.

And the consensus seems to be to modify the sniff. Where does that work happen?

Setting to NR because the patch does not need work.

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

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new126.47 KB
new69.07 KB

Just re-rolled the patch in #91, thanks!

daffie’s picture

Status: Needs review » Needs work

The comment #92, #93 and #94 still need to be addressed.

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.

ayush.khare’s picture

StatusFileSize
new113.93 KB
new116.93 KB

10.1.x Reroll for #97

nikhil_110’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

#102 appears to be missing a number of changes from #97 can it be documented why?

Also the interdiff is the same size of the patch?

quietone’s picture

Thanks for the interest in this work. However, as pointed out in several comments the work here is to address comments #92, #93, #94. And #93 suggests that we don't implement this sniff at all!

I am changing the status to active so emphasize that the work here is to resolve #92, #93, #94. Also, updating credit per How is credit granted for Drupal core issues.

quietone’s picture

Status: Needs work » Active

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.

nikolay shapovalov’s picture

I checked #94 and I totally agree that we need to update code sniff rule Drupal.Commenting.InlineComment.SpacingAfter to work with examples provided in #79.
Do we have issue for that?

Do I understand it right, before we have agreement or code sniff rule will be update, no further patches should be attached to this issue?
Do we need to update IS?

quietone’s picture

Issue summary: View changes
Status: Active » Postponed
Related issues: +#2464123: Remove the requirement that no blank line follow an inline comment

@zniki.ru, thanks for the interest in coding standard issues! For some background, there is a Coding Standards project where the community discusses changes to the Drupal Coding standards. Changes agreed to there usually require a change to the Coder project to implement a new sniff or create a new one. Once, that is done, then we have issues it the core queue to implement the change. There is also the #coding_standards channel in Drupal Slack where coding standards are also discussed.

There is an issue in the Coding Standards project discussing changing this standard, #2464123: Remove the requirement that no blank line follow an inline comment. That issue is being worked on so maybe we should postpone this on that issue. I do want to avoid double work. I am adding that as a relating issue and postponing this on that issue.

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.