How to modify a variable naming convention for pylint in Visual Studio Code
Asked Answered
G

1

6

I keep getting C0103 warnings from pylint in Visual Studio, because I am trying to use 2-character variables names like hp and gp. The warning is described here: link.

The convention is described as [a-z_][a-z0-9_]{2,30}$ for variable-rgx. I don't actually know how to read this regex thing or what it means, but it looks like the {2,30} part describes the possible length range, so (correct me if I'm wrong) why isn't character length two allowed? Or would there be some other reason why a variable name such as gp would give an error?

When this question is asked, people often link to PEP-8, but I don't remember reading that variable names specifically must have a minimum length of 3 characters. Anyway, I get this is probably bad form, but I don't want to follow this convention. In the context of my program it is abundantly clear what 2-character variable names such as gp and hp would mean, and this feels like way to much of a restriction on coding style.

So in any case, what I want to do is specifically override this warning. I don't want to just disable C0103. I would instead prefer to change this within my text editor (Visual Studio Code), like in the setting where for example you can change pylint args with "python.linting.pylintArgs": [...]. So what would the correct change be if I wanted to override the convention to allow 2-character variable names? Or would I have to write a new lintrc file (not sure how to do that, and I would prefer a lighter solution where I only change it in VSCode).

Gass answered 5/10, 2017 at 17:52 Comment(2)
You are correct that The {2,30} means at least 2 and no more than 30 characters but it only modifies the last [a-z0-9_] part of the regex. So you need one a-z character followed by at least two other characters, which can now include numbers. So can you just the 2 to a 1? I don't have pylint installed so I don't know its linting args.Bridgman
Ok I see how it works, thanks. The problem is I don't know how to (and where) to change the 1 to a 2. It would be useful if I could somehow override it from the VSCode settings.Gass
A
10

Open user settings (Ctrl + ,), input in the search bar pylintArgs, hover the mouse over the "python.linting.pylintArgs": [] and select edit. It will be copied to either User Settings or Workspace Settings on the right side. There input the required parameter:

"python.linting.pylintArgs": [
    "--variable-rgx=[a-z_][a-z0-9_]{1,30}$"
]
Adlee answered 16/4, 2018 at 14:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.