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:
- Comments starting at the beginning of the line instead of indented for the following services:
- password
- feed.reader.dublincoreentry
- feed.writer.atomrendererfeed
- Extra indentation in the tags list for the http_middleware.cors service.
- 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
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:
- 3112452-fix-indentation-consistency
changes, plain diff MR !2815
Comments
Comment #2
slootjes commentedThanks for picking this up! It was indeed fixed by my IDE and at first it accidentally ended up in my patches.
Comment #3
cilefen commentedIt seems like this would be automated in #2591827: Add YAML linting to core coding standards checks.
Comment #4
longwaveThese "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?
Comment #5
quondam commentedAgree 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
Comment #6
longwaveComment #8
daffie commentedThe 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.
Comment #9
leolandotan commentedI'll work on rerolling the patch :)
Comment #10
himanshu_sindhwani commentedRerolling the patch from #5 for 9.1. Sorry @leolando.tan I have already created the patch.
Comment #11
himanshu_sindhwani commentedComment #12
jofitzRemove Needs Reroll tag
Comment #13
quondam commentedThanks for re-rolling @himanshu_sindhwani
The updated patch applies cleanly to 9.1.x
Comment #14
quietone commentedPatch 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
Comment #15
narendra.rajwar27Working on patch re-roll. will update asap.
Comment #16
Vidushi Mehta commentedPatch rerolled. Sorry @narendra.rajwar27 If you are working then you should have assigned this issue to your self.
Comment #17
narendra.rajwar27@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
Comment #19
guilhermevp commentedRe-roll for 9.2.x.
Comment #20
guilhermevp commentedSmall identation error that I missed reviewing the patch.
Comment #21
adalbertov commentedHello, 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.
Comment #22
anmolgoyal74 commentedNeed to rewrap the comment here. comments are extending 80 characters.
Comment #23
adalbertov commentedSorry, for letting it pass. I'm adding a patch with the fix.
Comment #24
guilhermevp commentedThe fix works as intended, but adds whitespace in the process. Sending patch fixing this.
Comment #25
luiscarvalho commentedHello everyone, I've just reviewed patch #24 and everything is okay. I'm moving it to RTBC.
Comment #26
catchFor 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.
Comment #27
quietone commentedLet's postpone on linting being added to core.
Comment #29
quietone commentedNo longer postponed, #2591827: Add YAML linting to core coding standards checks was comitted.
Comment #30
mradcliffeThe 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.shon a DrupalPod 9.3.x instance and gotComment #33
borisson_patch no longer applies, we need a patch for 9.x and 10.x
Comment #34
ravi.shankar commentedAdded reroll of patch #30 on Drupal 9.5.x. and 10.1.x.
Comment #35
mile23Neither patch in #34 applies.
Also, edified to learn about the existence of
core/scripts/dev/commit-code-check.shIt sure would be great to have that as a more visible tool.
Comment #36
narendra.rajwar27Adding re-rolled patch for Drupal 9.5.x.
Comment #37
rodrigoaguileraTriaging 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.
Comment #38
mile23Setting to NW...
Comment #41
WagnerMelo commentedHello, sorry fot his merge, i'm working on it to solve the problem.'
Comment #42
WagnerMelo commentedHi, 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
Comment #43
Johnny Santos commentedI Just checked it and the changes on the yml files are looking ok now
Comment #44
alexpottWe can now scope this issue to automatically fix all the indentation issues for all of core's yaml files.
We need to add
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.
Comment #45
lalitware commentedI am working on the suggestion given by @alexpott.
Comment #46
lalitware commentedI 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?
Comment #47
alexpott@lalitware here's how to do this:
Comment #48
nitin shrivastava commentedI am working on it.
Comment #49
lalitware commentedThank 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.
Comment #50
lalitware commentedThank 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.
Comment #51
lalitware commentedComment #52
mile23Setting to needs review so the tests will run.
Comment #54
alexpottNeed to copy assets/scaffold/files/default.services.yml to sites/default/default.services.yml to fix the last test fail.
Comment #55
lalitware commentedWorking on suggestion given by @alexpott in above comment.
Comment #56
lalitware commentedCreated patch after making 3 changes:
Comment #57
lalitware commentedComment #58
daffie commentedAll code changes look good to me.
The rule has been added to eslint.
The testbot is green.
For me it is RTBC.
Comment #59
alexpottSaving issue credit
Comment #60
alexpottCommitted and pushed b29f980b79 to 10.1.x and a484c5ddd2 to 10.0.x. Thanks!
Committed 3b17df9 and pushed to 9.5.x. Thanks!
Reflowed some comments on commit.
For 9.5.x made the following fixes using
yarn run lint:yaml --fix...Comment #64
longwaveI think this needs a release note as it affects anyone who uses our eslint config.
Comment #65
alexpottComment #66
alexpott