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

Keep comments from style files in generated files #406

Open
a666 opened this issue Oct 1, 2021 · 3 comments
Open

Keep comments from style files in generated files #406

a666 opened this issue Oct 1, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@a666
Copy link

a666 commented Oct 1, 2021

As you are probably well aware of, a part of the reason for picking TOML and YAML as configuration languages, is the ability to comment these files.

Problem

Nitpick parses its toml style files and strips the comments of the generated files, ence making the devs having to go to the source nitpick styles to know why a configuration option was set.

Example:

# flakehell.toml
["pyproject.toml".tool.flakehell.plugins]
# E203: See https://github.com/PyCQA/pycodestyle/issues/373
pycodestyle = ["+*", "-E203",]

Generated pyproject.toml:

# pyproject.toml
[tool.flakehell.plugins] 
pycodestyle = [ "+*", "-E203",]

Possible solution

Keep comments from the style files.

The alternative (that we currently use) is adding a

#flakehell.toml
[comments.flakehell]
pycodestyle = """
-E203: See https://github.com/PyCQA/pycodestyle/issues/373
"""

which makes us return to the dark ages of doing the same in the composer.json or package.json files, 😄 .

@a666 a666 added the enhancement New feature or request label Oct 1, 2021
@andreoliwa
Copy link
Owner

Thanks for your suggestion, it's definitely useful. 🙂

I think this is possible indeed.
I don't remember exactly how sdispater/tomlkit identifies comments, if this is configurable or not...

A certain convention should be used though. In your example:

# Comment above a section belongs to the section
["pyproject.toml".tool.flakehell.plugins]
# Comment inside a section belongs to the value below:
pycodestyle = ["+*", "-E203",]

# Comments at the end of the file would be ignored because there is nothing below

@a666
Copy link
Author

a666 commented Oct 26, 2021

Could be.
What about multiline comments?

@andreoliwa
Copy link
Owner

What about multiline comments?

I would say to consider them as a block, a single comment, and copy all the lines.
This also depends on the implementation of tomlkit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Upvoted / Requests
Development

No branches or pull requests

2 participants