Problem/Motivation

When configuration is exported, if the last item that is exported is a multiline value the file will not end with a blank line. This causes problems with code validation tools that expect a blank line at the end of the file, e.g. Coder.

Steps to reproduce

Export a configuration item that has a multiline string at the end of the file, e.g. a block definition with visibility rules that has multiple paths entered.

Proposed resolution

Have the configuration system verify that there's a blank line at the end of each file prior to exporting.

Possible workaround is to use the multiline_config module.

Remaining tasks

Provide a patch to fix the error.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Release notes snippet

TBD

Issue fork drupal-3240104

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

DamienMcKenna created an issue. See original summary.

andypost’s picture

Issue tags: +Needs tests

I think core mail templates config could be used for test

geek-merlin’s picture

Can you give an example for this?

> Have the configuration system verify that there's a blank line at the end of each file prior to exporting.

I wonder if that changes the multiline string?

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.

damienmckenna’s picture

You can trigger the problem by exporting a block definition with visibility rules that contain multiple paths.

damienmckenna’s picture

Issue summary: View changes

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.

nvaken’s picture

I can confirm this being a problem, we're encountering this for most projects on `user.mail.yml` although it does not limit itself to that file. All files with the last value being multiline value will have this problem, as described in OP. This is problematic for us since our deployment will check our codebases on coding standards and now fails for most projects and need to manually edit these files.

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

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.

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.

aaronmchale’s picture

Does anyone have a quick fix for this? It's mildly annoying to have to go through each file and manually add a new line after every config export.

Thanks.

damienmckenna’s picture

I've been using multiline_config to work around the problem.

aaronmchale’s picture

@DamienMcKenna thanks, does multiline_config actually have any effect in 9.3 onwards? The project page states that the module is no longer needed in 9.3+, yet obviously the issue of no new line at the end of a file is still a problem, so maybe I'm missing something?

damienmckenna’s picture

It's not technically needed, but it still works and can work around this core bug.

aaronmchale’s picture

Awesome, will give it a try!

jrearick’s picture

Issue summary: View changes

We are affected by this as well. Our linters are calling this out as an error. In our example, we're seeing this in `webform.webform_options.foo.yml` where the `options` key is the last one and multiline. Our workaround was to add extra line breaks in the webform yml editing UI.

joegl’s picture

This is popping up in our PHPCS scans and typically only affects the user.mail.yml configuration after almost every configuration export. Because it does not cause any problems, we've chosen to ignore it in the PHPCS configuration:

<rule ref="Drupal.Files.EndFileNewline.NoneFound">
  <exclude-pattern>*config/sync/user.mail.yml</exclude-pattern>
</rule>

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.

joegl’s picture

Did this get changed recently? The most recent `user.mail.yml` export I did now uses \n and \r characters and keeps it all on one line (and also properly adds a blank line at EOF). This is on Drupal 10.5.8