Problem/Motivation

Added as a child issue of #2571965: [meta] Fix PHP coding standards in core, stage 1.

Discovered in #3111008: Use native Symfony YamlFileLoader, the core.services.yml has lines that are not consistently indented. It makes it harder for people who may be used to auto-fix functionality in their editor to create patches without unintended changes.

Summary:

  1. Comments starting at the beginning of the line instead of indented for the following services:
    1. password
    2. feed.reader.dublincoreentry
    3. feed.writer.atomrendererfeed
  2. Extra indentation in the tags list for the http_middleware.cors service.
  3. Extra indentation for the class and arguments keys of current_route_match service.

Details:

# Laminas Feed reader plugins. Plugin instances should not be shared.
  feed.reader.dublincoreentry:

# Laminas Feed writer plugins. Plugins should be set as prototype scope.
  feed.writer.atomrendererfeed:
  http_middleware.cors:
     class: Asm89\Stack\Cors
     arguments: ['%cors.config%']
     tags:
       - { name: http_middleware, priority: 250 }
  current_route_match:
     class: Drupal\Core\Routing\CurrentRouteMatch
     arguments: ['@request_stack']
# The argument to the hashing service defined in services.yml, to the
# constructor of PhpassHashedPassword is the log2 number of iterations for
# password stretching.
# @todo increase by 1 every Drupal version in order to counteract increases in
# the speed and power of computers available to crack the hashes. The current
# password hashing method was introduced in Drupal 7 with a log2 count of 15.
  password:

Proposed resolution

Fix the issues found in core.services.yml to keep the scope of the issue small.

Review other yamls to see if there are more issues in core. If there are few, consider changing them all at once rather than creating follow-up issues.

Remaining tasks

  • Look for and document other instances in core and update the issue summary accordingly if they fall in scope of the issue.
  • Write a patch
  • Review patch

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

All YAML files are linted using eslint to ensure that 2 spaces are used for indentation, as per the existing core standards.

Issue fork drupal-3112452

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

mradcliffe created an issue. See original summary.

slootjes’s picture

Thanks for picking this up! It was indeed fixed by my IDE and at first it accidentally ended up in my patches.

cilefen’s picture

longwave’s picture

# Laminas Feed reader plugins. Plugin instances should not be shared.
  feed.reader.dublincoreentry:

# Laminas Feed writer plugins. Plugins should be set as prototype scope.
  feed.writer.atomrendererfeed:

These "headings" are used to refer to multiple services below, not just the first one, which I guess is why they were put at the top level. Maybe we need some line breaks instead to help with this?

quondam’s picture

Agree with @longwave on additional line breaks for added legibility and consistency. Other comments not noted here - particularly those pertaining to deprecations - are particularly confusing without whitespace to help delineate which service(s) they pertain to.

The existing comments for the first few groups of services (cache_context.*) establish a helpful pattern of a line break immediately following the final line of the last service the comment is relevant to.

The attached patch standardizes all comments to that pattern and fixes the indentation concerns noted above in core.services.yml

longwave’s picture

Status: Active » Needs review

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
Issue tags: +Needs reroll

The patch needs first to land in the most current branch. At the moment that is 9.1. For that branch does the current patch not apply. Therefore the current patch need to be rerolled.

leolandotan’s picture

Assigned: Unassigned » leolandotan

I'll work on rerolling the patch :)

himanshu_sindhwani’s picture

Assigned: leolandotan » Unassigned
StatusFileSize
new5.81 KB

Rerolling the patch from #5 for 9.1. Sorry @leolando.tan I have already created the patch.

himanshu_sindhwani’s picture

Status: Needs work » Needs review
jofitz’s picture

Issue tags: -Needs reroll

Remove Needs Reroll tag

quondam’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for re-rolling @himanshu_sindhwani

The updated patch applies cleanly to 9.1.x

quietone’s picture

Status: Reviewed & tested by the community » Needs work

Patch no longer applies, another reroll needed. When a reroll is made remember to add the interdiff, or a diff, if that fails. It makes reviews much easier. See Creating an interdiff

narendra.rajwar27’s picture

Working on patch re-roll. will update asap.

Vidushi Mehta’s picture

Status: Needs work » Needs review
StatusFileSize
new3.86 KB

Patch rerolled. Sorry @narendra.rajwar27 If you are working then you should have assigned this issue to your self.

narendra.rajwar27’s picture

StatusFileSize
new5.89 KB
new3.46 KB

@Vidushi Mehta, thanks for the re-roll, Unfortunately it's not complete re-roll. Patch #16 is missing some changes from #10

So adding updated patch.
Thanks

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.

guilhermevp’s picture

StatusFileSize
new5.89 KB

Re-roll for 9.2.x.

guilhermevp’s picture

StatusFileSize
new6.27 KB
new552 bytes

Small identation error that I missed reviewing the patch.

adalbertov’s picture

Status: Needs review » Reviewed & tested by the community

Hello, i have checked patch #20. I looked into it and din't find any violation of the indention, so I'm moving the issue to RTBC.

anmolgoyal74’s picture

Status: Reviewed & tested by the community » Needs work

Need to rewrap the comment here. comments are extending 80 characters.

916:      # @todo Try to combine those tags together, see https://www.drupal.org/node/2915772.
971:  # password stretching.
972:  # @todo increase by 1 every Drupal version in order to counteract increases in
973:  # the speed and power of computers available to crack the hashes. The current
974:  # password hashing method was introduced in Drupal 7 with a log2 count of 15.
1175:    # list of bundles in the entity parameter, under "bundle" key as a sequence,
1653:    # We use '.' instead of '%app.root%' as the path for non-namespaced template
adalbertov’s picture

Status: Needs work » Needs review
StatusFileSize
new6.28 KB
new1.16 KB

Sorry, for letting it pass. I'm adding a patch with the fix.

guilhermevp’s picture

StatusFileSize
new36.98 KB
new1017 bytes
new6.28 KB

The fix works as intended, but adds whitespace in the process. Sending patch fixing this.

luiscarvalho’s picture

Status: Needs review » Reviewed & tested by the community

Hello everyone, I've just reviewed patch #24 and everything is okay. I'm moving it to RTBC.

catch’s picture

Status: Reviewed & tested by the community » Needs review

For other coding standards issues, we've usually required new coder rules to be added alongside committing the patches.

Currently there's no YAML linting in core, but there is an old issue to add it here. #2591827: Add YAML linting to core coding standards checks

Moving back to needs review for now.

quietone’s picture

Status: Needs review » Postponed
Issue tags: -Novice +Coding standards

Let's postpone on linting being added to core.

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.

quietone’s picture

Status: Postponed » Needs work
mradcliffe’s picture

Status: Needs work » Needs review
StatusFileSize
new6.28 KB
new634 bytes

The patch in #24 no longer applied. I re-rolled the patch by applying with `git apply --index -3` and created a new patch and interdiff.

I ran core/scripts/dev/commit-code-check.sh on a DrupalPod 9.3.x instance and got

----------------------------------------------------------------------------------------------------
Checking core/core.services.yml

PHPCS: core/core.services.yml passed
ESLint: core/core.services.yml passed
core/core.services.yml passed

----------------------------------------------------------------------------------------------------

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.

borisson_’s picture

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

patch no longer applies, we need a patch for 9.x and 10.x

ravi.shankar’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new6.85 KB
new5.5 KB

Added reroll of patch #30 on Drupal 9.5.x. and 10.1.x.

mile23’s picture

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

Neither patch in #34 applies.

Also, edified to learn about the existence of core/scripts/dev/commit-code-check.sh

It sure would be great to have that as a more visible tool.

narendra.rajwar27’s picture

Status: Needs work » Needs review
StatusFileSize
new6.93 KB

Adding re-rolled patch for Drupal 9.5.x.

rodrigoaguilera’s picture

Version: 9.5.x-dev » 10.1.x-dev
Issue tags: -Needs reroll +Novice, +Prague2022

Triaging issues for the Drupalcon Prague 2022 here. This is a good candidate for novice.

Also the fix should go in Drupal 10.1.x first and then backported.

If more work is needed it would be great to open a merge request and continue the changes there.

mile23’s picture

Status: Needs review » Needs work

Setting to NW...

WagnerMelo made their first commit to this issue’s fork.

WagnerMelo’s picture

Hello, sorry fot his merge, i'm working on it to solve the problem.'

WagnerMelo’s picture

Status: Needs work » Needs review

Hi, I managed to solve the MR problem, I made the changes based on the patch sent in #34 by @ravi.shankar, as I ran the phpcs command to see the errors and they didn't show up.
I hope that everything is right.
And i'll move this issue to needs review

Johnny Santos’s picture

Status: Needs review » Reviewed & tested by the community

I Just checked it and the changes on the yml files are looking ok now

alexpott’s picture

Title: Fix indentation consistency in core.services.yml » Fix indentation consistency in core's yaml files.
Status: Reviewed & tested by the community » Needs work

We can now scope this issue to automatically fix all the indentation issues for all of core's yaml files.

We need to add

    "yml/indent": ["error", 2]

to core/.eslintrc.json and then run the fixer. Once we do that we can then introduce new yaml rules to the eslintrc.json and improve all of core's yaml and ensure we don't introduce new errors in the future.

lalitware’s picture

Assigned: Unassigned » lalitware

I am working on the suggestion given by @alexpott.

lalitware’s picture

I have added the "yml/indent": ["error", 2] in the core/.eslintrc.json and created a patch for that. Now as per @alexpott next step is to run the fixer. @alexpott can you please guide how can we run the fixer and which library is required to run that?

alexpott’s picture

@lalitware here's how to do this:

cd core
yarn install
yarn run lint:yaml --fix
nitin shrivastava’s picture

I am working on it.

lalitware’s picture

Thank you very much @alexpott for helping me out. I ran the fixer and all the yaml files are modified. I have created the patch for that.

lalitware’s picture

Thank you very much @alexpott for helping me out. I ran the fixer and all the yaml files are modified. I have created the patch for that. Please ignore patch in #49. I have corrected the comment number on patch.

lalitware’s picture

mile23’s picture

Status: Needs work » Needs review

Setting to needs review so the tests will run.

Status: Needs review » Needs work
alexpott’s picture

Need to copy assets/scaffold/files/default.services.yml to sites/default/default.services.yml to fix the last test fail.

lalitware’s picture

Working on suggestion given by @alexpott in above comment.

lalitware’s picture

Created patch after making 3 changes:

  1. Added the "yml/indent": ["error", 2] in the core/.eslintrc.json
  2. Ran the fixer
  3. Copied assets/scaffold/files/default.services.yml to sites/default/default.services.yml
lalitware’s picture

Assigned: lalitware » Unassigned
Status: Needs work » Needs review
daffie’s picture

Status: Needs review » Reviewed & tested by the community

All code changes look good to me.
The rule has been added to eslint.
The testbot is green.
For me it is RTBC.

alexpott’s picture

Saving issue credit

alexpott’s picture

Version: 10.1.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed b29f980b79 to 10.1.x and a484c5ddd2 to 10.0.x. Thanks!
Committed 3b17df9 and pushed to 9.5.x. Thanks!

diff --git a/core/modules/config_translation/migrations/d7_field_instance_option_translation.yml b/core/modules/config_translation/migrations/d7_field_instance_option_translation.yml
index 656107cd29..984f2c6a57 100644
--- a/core/modules/config_translation/migrations/d7_field_instance_option_translation.yml
+++ b/core/modules/config_translation/migrations/d7_field_instance_option_translation.yml
@@ -19,9 +19,9 @@ process:
     method: getFieldType
   entity_type: entity_type
   field_name: field_name
-  #  # The bundle needs to be statically mapped in order to support comment types
-  #  # that might already exist before this migration is run. See
-  #  # d7_comment_type.yml for more information.
+  # The bundle needs to be statically mapped in order to support comment types
+  # that might already exist before this migration is run. See
+  # d7_comment_type.yml for more information.
   bundle:
     plugin: static_map
     source: bundle
diff --git a/core/modules/file/migrations/d6_file.yml b/core/modules/file/migrations/d6_file.yml
index d58ad93d26..51db2fdc6c 100644
--- a/core/modules/file/migrations/d6_file.yml
+++ b/core/modules/file/migrations/d6_file.yml
@@ -37,8 +37,8 @@ source:
 process:
   # If you are using both this migration and d6_user_picture_file in a custom
   # migration and executing migrations incrementally, it is strongly
-  # recommended that you remove the fid mapping to avoid potential ID
-  # conflicts. For that reason, this mapping is commented out by default.
+  # recommended that you remove the fid mapping to avoid potential ID conflicts.
+  # For that reason, this mapping is commented out by default.
   # fid: fid
   filename: filename
   source_full_path:
diff --git a/core/modules/system/tests/modules/dialog_renderer_test/dialog_renderer_test.services.yml b/core/modules/system/tests/modules/dialog_renderer_test/dialog_renderer_test.services.yml
index 63ce8a894c..332a261c5b 100644
--- a/core/modules/system/tests/modules/dialog_renderer_test/dialog_renderer_test.services.yml
+++ b/core/modules/system/tests/modules/dialog_renderer_test/dialog_renderer_test.services.yml
@@ -1,6 +1,6 @@
 services:
-  # Provide 2 main content renderer services that use the same class but
-  # behave differently depending on the 2nd argument.
+  # Provide 2 main content renderer services that use the same class but behave
+  # differently depending on the 2nd argument.
   main_content_renderer.wide_modal:
     class: Drupal\dialog_renderer_test\Render\MainContent\WideModalRenderer
     arguments: ['@title_resolver', '@renderer', 'wide']

Reflowed some comments on commit.


For 9.5.x made the following fixes using yarn run lint:yaml --fix...
diff --git a/core/core.services.yml b/core/core.services.yml
index 6a6332c7d7..7d83bb12f8 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -1455,7 +1455,8 @@ services:
       - [setStandalone, ['\Laminas\Feed\Writer\StandaloneExtensionManager']]
     arguments: ['feed.writer.']
     deprecated: The "%service_id%" service is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use \Laminas\Feed\Writer\StandaloneExtensionManager or create your own service. See https://www.drupal.org/node/3258440
-# Laminas Feed reader plugins. Plugin instances should not be shared.
+
+  # Laminas Feed reader plugins. Plugin instances should not be shared.
   feed.reader.dublincoreentry:
     class: Laminas\Feed\Reader\Extension\DublinCore\Entry
     shared: false
@@ -1496,7 +1497,8 @@ services:
     class: Laminas\Feed\Reader\Extension\Podcast\Feed
     shared: false
     deprecated: The "%service_id%" service is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. You should use \Drupal::service('feed.bridge.reader')->get('Podcast\Feed') instead. See https://www.drupal.org/node/2979042
-# Laminas Feed writer plugins. Plugins should be set as prototype scope.
+
+  # Laminas Feed writer plugins. Plugins should be set as prototype scope.
   feed.writer.atomrendererfeed:
     class: Laminas\Feed\Writer\Extension\Atom\Renderer\Feed
     shared: false
diff --git a/core/modules/field_ui/field_ui.services.yml b/core/modules/field_ui/field_ui.services.yml
index b4c23ddf6e..0ee8964f38 100644
--- a/core/modules/field_ui/field_ui.services.yml
+++ b/core/modules/field_ui/field_ui.services.yml
@@ -3,7 +3,7 @@ services:
     class: Drupal\field_ui\Routing\RouteSubscriber
     arguments: ['@entity_type.manager']
     tags:
-     - { name: event_subscriber }
+      - { name: event_subscriber }
   field_ui.route_enhancer:
     alias: route_enhancer.entity_bundle
     deprecated: The "%alias_id%" service is deprecated in drupal:9.4.0 and is removed from drupal:10.0.0. Use the "route_enhancer.entity_bundle" service instead. See https://www.drupal.org/node/3245017
diff --git a/core/modules/hal/hal.services.yml b/core/modules/hal/hal.services.yml
index 38ffb22612..156fbc23fc 100644
--- a/core/modules/hal/hal.services.yml
+++ b/core/modules/hal/hal.services.yml
@@ -18,10 +18,10 @@ services:
     tags:
       - { name: normalizer, priority: 20 }
   serializer.normalizer.timestamp_item.hal:
-   class: Drupal\hal\Normalizer\TimestampItemNormalizer
-   tags:
-     # Priority must be higher than serializer.normalizer.field_item.hal.
-     - { name: normalizer, priority: 20 }
+    class: Drupal\hal\Normalizer\TimestampItemNormalizer
+    tags:
+      # Priority must be higher than serializer.normalizer.field_item.hal.
+      - { name: normalizer, priority: 20 }
   serializer.normalizer.entity.hal:
     class: Drupal\hal\Normalizer\ContentEntityNormalizer
     arguments: ['@hal.link_manager', '@entity_type.manager', '@module_handler', '@entity_type.repository', '@entity_field.manager']

  • alexpott committed b29f980 on 10.1.x
    Issue #3112452 by lalitware, guilhermevp, narendra.rajwar27, WagnerMelo...

  • alexpott committed a484c5d on 10.0.x
    Issue #3112452 by lalitware, guilhermevp, narendra.rajwar27, WagnerMelo...

  • alexpott committed 3b17df9 on 9.5.x
    Issue #3112452 by lalitware, guilhermevp, narendra.rajwar27, WagnerMelo...
longwave’s picture

I think this needs a release note as it affects anyone who uses our eslint config.

alexpott’s picture

Issue summary: View changes
alexpott’s picture

Issue tags: -Needs release note

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.