addToGitIgnore in composer scaffold should add a trailing newline

Created on 21 January 2021, over 3 years ago
Updated 20 October 2023, 8 months ago

The \Drupal\Composer\Plugin\Scaffold\ManageGitIgnore::addToGitIgnore adds additional entries to .gitignore in the project root and starts with a new line if necessary. But it leaves the file with the last entry on the last line of the file without a trailing newline.

My proposal is to also add a newline at the end of the file in case we add some entries. This is for 3 reasons:

  • If any other process adds to gitignore without checking a a leading newline requirement, it will mess up that line by adding its entry to the already existing entry instead of a line of its own
  • Following coding standards, all text files should have a final newline
  • The editorconfig framework forces a newline for each file too which will result in a changed file only if gitignore gets opened in the editor which will then add the missing newline automatically
🐛 Bug report
Status

Needs work

Version

10.0

Component
Composer 

Last updated 3 days ago

No maintainer
Created by

🇩🇪Germany jurgenhaas Gottmadingen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇫🇷France Jérôme Dehorter Lille

    Jérôme Dehorter made their first commit to this issue’s fork.

  • Status changed to RTBC 8 months ago
  • 🇫🇷France Jérôme Dehorter Lille

    Hello,

    This issue can be closed, a trailing is present in the file.

  • Status changed to Needs work 8 months ago
  • 🇬🇧United Kingdom John Cook

    I believe that it is the generated .gitignore file that is missing a trailing new line.
    Imploding the $entries array would not add the final new line character.
    Another $contents.="\n" would be needed to add the character to the string before the string is written to file.

    A set of testing instructions would be good, so that the process can be checked.

    Moving back to “Needs work”.

Production build 0.69.0 2024