Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment on the last line is moved on the line above #277

Closed
gixlg opened this issue May 27, 2021 · 2 comments · Fixed by #278
Closed

Comment on the last line is moved on the line above #277

gixlg opened this issue May 27, 2021 · 2 comments · Fixed by #278
Labels
bug Something isn't working

Comments

@gixlg
Copy link

gixlg commented May 27, 2021

Considering this yml input

environment:
  ### SESSION START ###
  A: "true"
  B: "true"
  ### SESSION END ###

if the document is parsed and then printed out the result is not the same, but the comment goes on the same line as 'B'.

const file = fs.readFileSync('./test/input/config.yml', 'utf8')
const doc = YAML.parseDocument(file)
doc.toString()

output

environment:
  ### SESSION START ###
  A: "true"
  B: "true" ### SESSION END ###

Expected behaviour
I would like to preserve the positioning of the comment. There is a way to achieve it?

Versions:

  • Environment:
  • Node.js: v12.14.0
  • yaml: 2.0.0-5
@gixlg gixlg added the bug Something isn't working label May 27, 2021
@eemeli
Copy link
Owner

eemeli commented May 27, 2021

Are you sure that this is happening with the example that you posted above? I'm not able to replicate this behaviour:

const doc = YAML.parseDocument(`environment:
  ### SESSION START ###
  A: "true"
  B: "true"
  ### SESSION END ###
`)

doc.toString()
> 'environment:\n' +
  '  ### SESSION START ###\n' +
  '  A: "true"\n' +
  '  B: "true"\n' +
  '  ### SESSION END ###\n'

I don't doubt that end-comment placement is problematic, so this may well be a dupe of #244.

@gixlg
Copy link
Author

gixlg commented May 28, 2021

Oh yeah, my bad I haven't reported an important detail apparently: The empty line at the end of the input.

const doc = YAML.parseDocument(`environment:
  ### SESSION START ###
  A: "true"
  B: "true"
  ### SESSION END ###

`);

doc.toString()
> 'environment:\n' +
  '  ### SESSION START ###\n' +
  '  A: "true"\n' +
  '  B: "true" ### SESSION END ###\n'

Here the project to reproduce it: https://stackblitz.com/edit/test-yml

This use case is useful for me when there are ymls more complex and space and line comment can be used to gain more clarity.

environment:
  ### SESSION START ###
  A: "true"
  B: "true"
  ### SESSION END ###

  ### ANOTHER SESSION START ###
  C: "true"
  D: "true"
  ### ANOTHER SESSION END ###
  

like this example above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants