Skip to content

Outdated prettier and recent formatter change results in unwanted blank line removal before last comment #1216

@antonc42

Description

@antonc42

Describe the bug

In the recent 1.20.0 version, the #1179 PR came into effect, which enabled formatting for Ansible YAML files.

When the formatting is applied, the blank line before the last comment in my Ansible YAML files is removed. See the expected/current behavior.

I may be incorrect, but I believe this is due to using an old version of prettier. I found the following issue in prettier that seems to describe this behavior: prettier/prettier#10922. The issue was fixed in prettier/prettier#17843 (commit: prettier/prettier@94b9a05). This was apparently first included in the 3.7.0 release.

From what I can tell, this extension has pinned prettier at version 2.2.1, which is now over five years old.

Can the prettier version be updated to fix this issue?

Expected Behavior

The formatter makes no change to this file.

some_var: Some Value


# comment
other_var: Other Value

Current Behavior

The formatter removes the blank line(s) before the last comment.

some_var: Some Value
# comment
other_var: Other Value

Steps to Reproduce

  1. Install extension 1.20.0.
  2. Enable yaml.format.enable setting (the default) and optionally the editor.formatOnSave in VSCode.
  3. Save the file, or manually perform formatting on the Ansible YAML file.
  4. Observe the undesired removal of blank lines before the last comment.

Environment

I only tested on Linux, not on other platforms, so I don't know if it is an issue there, but I suspect it will be.

  • Windows
  • Mac
  • Linux
  • other (please specify)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions