Problem/Motivation
While evaluating and researching core modules, it was noticed that are a few inconsistencies in .info.yml files, specifically, the use of single and double quotes around titles and descriptions.
Analysis:
Modules with one word titles (with no quotes): 41
Modules with one word titles (with single quotes): 2
Modules with multiple word titles (with single quotes): 22
Modules with multiple word titles (with no quotes): 9
Description (with single quotes): 67
Description (with no quotes): 3
Description (with double quotes): 1
Proposed resolution
Update modules to have the following:
Standards proposal for name and description values:
- The first character in the name value is a letter or underscore.
- Name and description have to be resolved to strings by Yaml.
- Single quoting of values is allowed in some cases. (see below)
- Double quoting of values is not allowed.
- The value mapping indicator (:) should be followed by a single space.
In the following cases, use single quoting:
- Value contains a
: followed by a <space>or a# preceded by a <space>. - Value contains any of the following characters with or without a preceding colon:
{ } [ ] <comma> - Values matches completely with any of these:
true false yes no y n on off null ~ - Value starts with any of these characters:
! & * { } [ ] , # | > @ ` " \ ' <space> % - Value starts with a
?, : or -followed by a<space>.
See also https://www.drupal.org/docs/creating-custom-modules/let-drupal-know-abou...
Remaining tasks
Create an issue in the Coding Standards project to decide what the standard format should be.
Create patchReview patch- Clarify what the standards are.
- Write tests to prevent issue from occurring in the future as new or experimental modules are added to core.
- Edit Drupal documentation pages to explain standards.
User interface changes
None
API changes
None
Data model changes
None
| Comment | File | Size | Author |
|---|---|---|---|
| #88 | reroll_diff_82-88.txt | 5.62 KB | ravi.shankar |
| #88 | 2994928-88.patch | 251.52 KB | ravi.shankar |
| #82 | interdiff_80-82.txt | 1.25 KB | ravi.shankar |
| #82 | 2994928-82.patch | 251.37 KB | ravi.shankar |
| #80 | reroll_diff_76-80.txt | 19.8 KB | ravi.shankar |
Issue fork drupal-2994928
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
Comment #2
volkswagenchickI have uploaded a file with an audit of all the core modules.
Comment #3
volkswagenchickI have uploaded a patch that standardizes the .info.yml files in core modules to have the following:
1. Modules with one word title should use no quotes around the title.
2. Modules with multiple word title should use single quotes around the title.
3. Module descriptions should use single quotes around the description.
Modules with one word titles (with single quotes) - removed quotes
* Hal
* Workflows
Modules with multiple word titles (with no quotes) - added single quotes
* Place Blocks - block_place
* Internal Dynamic Page Cache - dynamic_page_cache
* Inline Form Errors - inline_form_errors
* Menu UI - menu_ui
* Migrate Drupal - migrate_drupal
* Internal Page Cache - page_cache
* Quick Edit - quick_edit
* Responsive Image - responsive_image
* Activity Tracker - tracker
Description (with no quotes) - added single quotes
* Datetime - datetime
* Serialization - serialization
* Tour - tour
Description (with double quotes) - removed double quotes and added single quotes
* CKEditor
Comment #4
dani3lr0se commentedI have compared the patch to the audit file and all the changes look appropriate.
Two modules that had one word titles now have no quotes: HAL and Workflow, now have no quotes.
Nine modules that had Multiple word titles now have single quotes: Place Blocks, Internal Dynamic Page Cache, Inline Form Errors, Menu UI, Migrate Drupal, Internal Page Cache, Quick Edit, Responsive Image, and Activity Tracker.
Three modules that either had no quotes or double quotes around the description now have single quotes: Serialization, Tour, and CKEditor.
I didn't see Datetime changes in the patch however. Going to set this to needs work.
Thanks for bringing this up and making time for a patch. This is a great initiative that will help with consistency amongst all core modules and will also hopefully provide a standard for other contrib modules to follow.
Comment #5
volkswagenchickOoops! Good catch! I will work on this later this afternoon, so am assigning it back to myself.
I also welcome any community feedback.
Comment #6
volkswagenchicki uploaded another patch that makes that changes and included an interdiff for easy review. Thanks
Comment #7
volkswagenchickI would like to attribute @Kristen Pol for helping with the review and audit process.
And @loopduplicate for initial discovery and roadmap of TODOS.
Thanks!
Comment #8
dani3lr0se commentedI now see the Datetime changes and the single quotes around the description. Thanks for making the change and interdiff! The patch also applies successfully with Simplytest. Thanks again for doing this. I'm hoping others agree with your findings.
Comment #9
loopduplicate commentedLooking good :)
Comment #10
nerdsteinI am also confirming the RTBC on this. I went through each change on the "Extend" page to verify the module names and descriptions worked for each change.
I also like this paradigm for use in contrib as well. It would be a welcomed convention to know when to use quotes and when not to. This could be a separate issue to discuss.
Comment #11
volkswagenchickComment #12
kristen polGood stuff. Thanks!
One comment on the issue summary which has:
"Write tests to prevent issue from occurring in the future as new or experimental modules are added to core."
This is an interesting idea. I don't know if we have any *tests* that check for code formatting. We use Code Sniffer when checking our Drupal code for coding standards, but it would be interesting to write tests to check formats. Curious if anyone knows if this exists anywhere.
Comment #13
quietone commentedThis is a confusing, these are yml files and quotes are not needed. Why add such a requirement?
Comment #14
volkswagenchickWhile looking at all the .info.yml files in the core modules, I noticed the usage of quotes was inconsistent.
I am chose this route because it seems most core modules aligned to these patterns.
Comment #15
wim leersThis inconsistency has been triggering my OCD for years :P Thanks @volkswagenchick! :)
Comment #16
volkswagenchickTagging for training session at Drupal Corn 2018
Comment #17
ultimikeI love this idea of making things consistent. Whatever is decided should probably be documented in our coding standards. A good place to start would be to add a new issue to the Coding Standards issue queue.
Some additional info about strings in .yml files:
tl;dr It seems that the prevailing "best practice" is to not use any quotes unless you need them.
-mike
Comment #19
volkswagenchickI reviewed the results of the failed testing. It doesn't look like a true failure. The text reads:
6 Oct 2018 at 06:50 PDT
PHP 7 & MySQL 5.5 Build Successful
I am going to mark this as RTBC again, thanks!
Comment #20
larowlanLet's add a test to ensure this never comes back, could be done with coder (linting) or an actual test.
Comment #21
quietone commented@volkswagenchick, thanks for the response. I understand that going with what people do in practice is very useful information but I still question it when that practice is unnecessary.
+1. I agree with ultimike
I can't help but reread the goals in the YAML specification. The first goal of YAML is "YAML is easily readable by humans". For me adding quotes reduces readability by adding clutter and it even looks ugly. I don't say that lightly. Although limited to migration yml files I work with yml every day.
Comment #22
volkswagenchickThanks for the feedback. I will review some more documentation next week, as I am at a conference until then.
Comment #23
volkswagenchickI uploaded a patch that removes ALL quotes from core module's .info.yml file. Set against 8.7.x branch.
Comment #24
volkswagenchickComment #26
damienmckennaI've set the tests to run again, this time against the 8.7.x branch.
Comment #27
damienmckennaMaybe it'd be worth looking at opening a Coding Standards issue to find a linter that follows the format we want to use, and then getting that set up on the testing infrastructure?
Comment #28
longwaveComment #29
quietone commented@volkswagenchick, thanks for reviewing some more documentation (#22).
Wish I had time to do a proper review now :-(
Comment #31
chi commentedWhat is the rationale behind such a decision? Strings with multiple words in YML files work fine. This might be a bit confusing because some IDEs (i.e. PhpStorm) highlight quoted strings differently.
Also wonder why this issue is limited to module info files?
Comment #34
kristen polNeeds a reroll for 9.1.x. Note that some files no longer existing, e.g.
core/modules/block_place/block_place.info.yml.Comment #35
volkswagenchickComment #36
hardik_patel_12 commentedRe-rolling a patch against 9.1.x , kindly review a patch.
Comment #37
volkswagenchickPatch installed locally on 9.1.x. ALL quotes from core module's .info.yml file have been removed
Comment #38
kristen pol@volkswagenchick Did you want to mark RTBC?
Comment #39
volkswagenchickShoot. Yes. Thanks Kristen. Marked RTBC
Comment #41
hardik_patel_12 commentedRandom failure , setting back to RTBC.
Comment #45
quietone commentedI am pleased to see the progress here.
I applied that patch and found that not all .info.yml files have been fixed.
I also noticed that many files have two spaces after the ':', whereas only one character is necessary.
The tags show that this needs a reroll and that it needs tests. The reroll seems to have happened but not the test. The test was asked for in #20.
The Issue Summary proposed resolution does not match with what is done in the patch.
Setting to NW for the above.
Closed #2116897: Adopt identical YAML formatting for info.yml files as a duplicate, adding credit.
Comment #46
s_bhandari commentedHi, @quietone,
Working on the observations you have shared. Will update as soon as possible.
Thanks.
Comment #47
s_bhandari commentedHi, @quietone,
I have addressed the observations in this patch that you have shared in #45. Please review the same and let me know for any observation. And, if this looks good we can go ahead for writing the test cases asked in #20. Also, just to highlight the issue summary needs to get updated, as the first two points are strike-through, but we are still working on the patch.
Thanks.
Comment #48
tvb commentedThis is a stab at creating tests.
It is placed under core/tests/Drupal/Tests/Core/Discovery. Not sure whether this is the right location.
Test results after applying the patch from #47:
$ phpunit -c /app/phpunit.xml core/tests/Drupal/Tests/Core/Discovery/YamlConsistencyTest.phpPHPUnit 8.5.8 by Sebastian Bergmann and contributors.
Testing Drupal\Tests\Core\Discovery\YamlConsistencyTest
................................................................. 65 / 80 ( 81%)
............... 80 / 80 (100%)
Time: 280 ms, Memory: 6.00 MB
OK (80 tests, 240 assertions)
Comment #49
tvb commentedReworked YamlConsistencyTest.
Plus added @group annotation.
Comment #50
tvb commentedWrong extension for interdiff in #49.
Comment #51
quietone commentedNice to have a test! Thx,
Not used
Not needed
What about the info.yml files in test modules in Core modules?
Why are double quotes not tested for?
Comment #52
tvb commented#51.1: removed
#51.2: removed
#51.3: see glob($this->root . '/core/modules/*/tests/modules/*/*.info.yml')
#51.4: see additional assertion
Grep results:
Comment #53
longwaveComment #55
Pooja Ganjage commentedHi,
I have found more info.yml file having inconsistencies quotes and even I have removed quotes from this aggregator_display_configurable_test.info.yml file which makes fail test.
I am creating patch for this.
Please review the patch.
Let me know for any recommendations.
Thanks.
Comment #56
Pooja Ganjage commentedComment #57
quietone commented@Pooja Ganjage, thanks for making a patch. The patch in #55 is 274KB which is significantly larger than the previous patch. That may be because you picked up on files that are currently not tested, see comment below, but that is hard to know without an interdiff. An interdiff really makes life easier for a reviewer. If you haven't already seen them instructions are available for creating an interdiff.
This is still limiting the directories being searched. This returns 369 files but a find,
find core/modules -iname \*.info.yml | grep -v themes | nl, returns 419. I think this needs something more generic to recurse the directory tree.I presume the grep results are after the patch and before the patch. Since the after results return 0 for all the greps but the test fails, I wonder where the error is?
Also, a reminder that the issue summary needs an update.
Cheers
Comment #58
tvb commentedAll grep results in #52 are after the patch. They were included to illustrate the 'needs work' status (which remained unchanged in #52).
The test in #52 failed because of an assertion that allows no quotes at all.
Since there is no interdiff in #55, this patch builds on #52.
Modifications in .info files:
grep -rl \' core/modules/*/tests/modules/*/*.info.yml | xargs sed -i "s/version: '\(.*\)'/version: \1/"Special cases meaning:
* Quotes around properties. (quotes removed)
* Quotes inside description. (4 files still have quotes, but not around the value for description)
* Double single quotes (e.g. ''install'' --> changed to 'install')
* Quotes around the value for dependencies. (quotes removed)
Modifications in testing:
Covers this case:
description: Tests the 'active' migrate stateIs it too strict? Given the case in the preceding bullet and also the comment in #17 "to not use any quotes unless you need them".
The current assertion fails because some .info files do not have a description. Are descriptions required or not?
Clarifying the standards around .info file consistency would benefit further development of the assertions.
Regarding recursing the directory tree: to do
Comment #59
tvb commentedNow with .patch extension.
Comment #60
tvb commentedChange of tack for the test:
The patch contains another solution to recurse the folders search for .info.yml files. (if finds 419 files, see #57)
Comment #61
tvb commentedSome module names were not properly (un)quoted.
Comment #63
shaktikfixed test case kindly check.
Comment #65
martin107 commentedThe test fails with a deprecation notice .. highlighting that relying on Symfony's
Symfony\Component\Yaml\Escaper
class is flawed, because Symfony considers it internal and is subject to change, by them at any time.
I think the best way forward is to copy and modify the Escaper into Drupal's namespace
I don't like that fact that we take on the maintenance of someone else's code but on the good side it is small and self contained
Comment #67
longwaveThe copied Symfony class doesn't match our coding standards, so work needed to clean that up.
Alternatively should we just use the Symfony class for the double-quoting rules and a custom method on the test itself for the single-quoting rules? That would save us copying the class at all; we only use it in this one place anyway.
Finally, should we have unit tests for the failure cases in the test?
Comment #68
ravi.shankar commentedComment #69
ravi.shankar commentedComment #70
tvb commentedFixed coding standards in the copied Symfony class.
Comment #71
tvb commentedThe alternative solution suggested in 67.2.
Comment #72
volkswagenchickTagging novice
Comment #73
tvb commentedComment #74
tvb commentedComment #75
tvb commentedRerolled patch.
'Needs work' because it does not comply with the standards proposal.
Comment #76
tvb commentedA reworked patch.
The test no longer uses the Symfony Escaper class.
It follows the standards proposal in the issue summary.
These sample values for description pass the consistency test:
can also use " quotes ' and $ a % lot /&?+ of other ~ @ <> stuffno need to escape backslash \this is a link https://www.drupal.org'& starts with a special character, needs quotes''to express one single quote inside a quoted string, use '' two of them'Comment #79
ressaThanks for working on this, I just created #3278144: Remove quotes from olivero.info.yml.
The suggested guideline in this issue is "Standards proposal for name and description values: The first character in the name value is a letter or underscore." which I agree with, since you don't need to quote a YAML string, as long as the first character is not a special character.
In the Issue Summary, only titles and descriptions are mentioned, but what about other strings, for example under
regionsin a theme, oralt text? Shouldn't we be consistent, and don't quote any string at all by default, except for special cases? (The rules under "In the following cases, use single quoting").For more, see:
So I agree with @ultimike's proposal (4 October 2018):
I also agree with Chi (21 March 2019):
Also, this comment by @Chi is interesting, and makes sense to me:
... as well as @ultimike's observation:
I agree, it would be great to document YAML coding standards, for example for quoting. Perhaps the "Proposed resolution" for quoting as seen in the Issue Summary could be added to YAML Configuration files?
Or should an issue be created under https://www.drupal.org/project/issues/coding_standards for discussion?
Comment #80
ravi.shankar commentedAdded reroll of path #76 on Drupal 9.4.x.
Comment #81
quietone commentedThe process for changing coding standards is documented on the project page for the Coding Standards project. It starts with making an issue in that project. My search turned up one issue referring to YAML, #2823463: Devise an extensible way to document extensible data structures.
Comment #82
ravi.shankar commentedFixed Drupal CS issue of patch #80.
Comment #85
bklineWas it an intentional sadistic joke that for Boolean values in Drupal YAML files quotes MUST be present in some uses and MUST NOT be present in other uses?
Comment #86
chi commentedIf I am not mistaken in the value
_access: 'TRUE'is actually treated as strings.Real boolean in YML are never quoted.
Comment #87
bklineAm I the only one who thinks this is a confusing and bizarre thing to do (use 'TRUE' as a string)?
Comment #88
ravi.shankar commentedAdded reroll of patch #82 on Drupal 9.5.x and tried to fix failed test of patch #82 as well.
Comment #91
quietone commentedThere is no patch here to review. What needs to be done here now is to make a coding standards issue to decide on the style to use.