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

[docs] Explain how to make the linter know that a file is of INI format #501

Open
webknjaz opened this issue Sep 5, 2022 · 2 comments
Open
Labels
bug Something isn't working

Comments

@webknjaz
Copy link

webknjaz commented Sep 5, 2022

I've been staring at the docs that mention that one could lint INI-files here https://nitpick.readthedocs.io/en/latest/plugins.html#ini-files with a few hardcoded examples of such files. I tried applying it to .flake8 and .pylintrc and it worked. But when I did the same for .isort.cfg, nitpick just spit out this:

nitpick-style.toml:1: NIP001  has an incorrect style. Invalid config:
".isort.cfg".settings: Unknown configuration. See https://nitpick.rtfd.io/en/latest/plugins.html#text-files.

I wondered why it'd identify this file as just a text file when it's clearly parseable with cfgparser. Grepping for hardcoded file names recognized as INI didn't help but staring at https://github.com/andreoliwa/nitpick/blob/develop/src/nitpick/plugins/ini.py did. I was lucky to notice identify in the var names even though it wasn't directly imported in that module. This is because I happen to know what that project is.

I quickly confirmed my suspicion with

$ identify-cli .flake8
["file", "flake8", "ini", "non-executable", "text"]
$ identify-cli .isort.cfg 
["file", "non-executable", "text"]

So I've gone ahead and submitted this PR upstream at pre-commit/identify#323.

While that patch will address the immediate problem, I felt like this issue needed to be filed anyway because this situation reveals problems in nitpick itself too.

I think that there are 2 possible action items (non-exclusive):

  • mention that identify is used in the docs and suggest the users to submit PRs there to add new file classifications
  • implement a config setting in nitpick itself allowing the end-users to specify that some specific file is of a specific (known to them) type and should be linted with a certain plugin

I hope this story provides all the necessary details to be actionable :)

@webknjaz webknjaz added the bug Something isn't working label Sep 5, 2022
@webknjaz
Copy link
Author

webknjaz commented Sep 5, 2022

  • implement a config setting in nitpick itself allowing the end-users to specify that some specific file is of a specific (known to them) type and should be linted with a certain plugin

I've faced a similar issue with another file name — .importlinter (https://import-linter.readthedocs.io/en/stable/usage.html#configuration-file-location). But Anthony doesn't seem keen to make identify aware of it (pre-commit/identify#324 (comment)).

So I'd say that this action item would be important to implement. Plus, since the identify upstream isn't always open to accepting improvements, sending the users there would be rather useless.

I think nitpick could attempt to monkey-patch https://github.com/pre-commit/identify/blob/207d5f7/identify/extensions.py#L260 when adding more files or just let the users specify the file types for things that aren't there or need to be overridden.

@andreoliwa andreoliwa added this to Triage in Nitpick Roadmap Sep 18, 2022
@andreoliwa
Copy link
Owner

I think nitpick could attempt to monkey-patch https://github.com/pre-commit/identify/blob/207d5f7/identify/extensions.py#L260 when adding more files or just let the users specify the file types for things that aren't there or need to be overridden.

Either one of these solutions should work.
Whichever is easier and cleaner to implement.

Duly noted, thanks for yet another bug report. 🙏🏻

@andreoliwa andreoliwa moved this from Triage to Upvoted / Requests in Nitpick Roadmap Sep 19, 2022
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
Status: Upvoted / Requests
Nitpick Roadmap
  
Upvoted / Requests
Development

No branches or pull requests

2 participants