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

Option to prevent deletion of orphan comments #59

Open
maresb opened this issue May 7, 2023 · 2 comments
Open

Option to prevent deletion of orphan comments #59

maresb opened this issue May 7, 2023 · 2 comments

Comments

@maresb
Copy link

maresb commented May 7, 2023

Hi, in the context of pretty-format-toml I was recently surprised by the disappearance of a multi-paragraph comment. After investigation I discovered that it was interpreted by toml-sort as an orphan comment.

For example,

# paragraph 1

# paragraph 2
[a-section]

and then # paragraph 1 vanishes.

I ended up solving this with

# paragraph 1
#
# paragraph 2
[a-section]

Would it make sense to add an option which changes the behavior so that orphan comments are added to the next section rather than deleted?

@brodybits

This comment was marked as outdated.

@brodybits
Copy link

brodybits commented Oct 6, 2023

My apologies for the incorrect example, just tested this example (now updated to add some wanted & expected spacing):

[a-section]
# this comment is preserved
config1 = 123

# this orphaned part is removed
# config2 = 456

[b-section]
config3 = 789

# seems to be preserved at the end:
# config4 = 901

P.S. adding another case:

[a-config]
list1 = [
  "abc", # first
  # second:
  "def",
  # orphaned part removed:
  # "maybe later",
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants