Issue
I have been trying to configure my .pylintrc
file to enforce the use of single quotes and disable the newline at the end of the file. I have read through the available documentation and attempted to find solutions on Stack Overflow, but I couldn't locate a clear answer.
Error:
When I run with the configuration provided below, I encounter the following error.
.pylintrc:1:0: E0015: Unrecognized option found: quotes, missing-final-newline (unrecognized-option)
Code:
Below is the snippet of my current .pylintrc
file:
[FORMAT]
# Attempt to set single quotes (this causes errors)
quotes = single
# Attempt to disable newline at the end of the file (this causes errors)
missing-final-newline = False
I am not sure it right configurations.
Environment:
- Operating System: Windows 10
- Pylint version: 3.0.3
- Python version: 3.11.4
Expected Output:
I expect Pylint to enforce the use of single quotes and not insert newline at the end of file in my code.
Additional Information:
I have tried to find information in the Pylint documentation but couldn't locate details on the .pylintrc
file for these specific settings. I have also searched on Stack Overflow and tried to resolve the issue through interactions with ChatGPT.
Solution
The easiest way to get a valid .pylintrc
is to have it generated by pylint <your options> --generate-pylintrc > .pylintrc
. The linked documentation states that it's better to rely on the defaults and put only your non-default options in there. That's what you should do.
You can edit the file and remove all the lines you don't want. Or generate a default config and diff
with yours.
This should give you an idea of the syntax to use in .pylintrc
. You'll see that all the command line options can be used without the leading hyphens. So --disable=foo
on the command line becomes disable=foo
in the file.
Speaking of disable
, that's one line you want to have in your .pylintrc
to disable the check for a missing newline at the end of a file. (Note: it will not remove the newline, or complain if there is one. It will just not-complain when it's not there.)
I couldn't find anything to force single quotes, the closest option seems to be --check-quote-consistency
which is a Boolean option. It will complain if single and double-quoted strings are used in the same file.
It seems every pylintrc
needs at least one section to put options in but otherwise, it gets ignored. I couldn't find anything on it. Either stick with the section names from the default or create your own.
Putting it all together, we get a .pylintrc
like this one:
[MY OPTIONS]
check-quote-consistency=yes
disable=missing-final-newline
Answered By - Friedrich
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.