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).
Press F2 and then type the new desired name and press Enter. All usages of the symbol will be renamed, across files.
Go variable naming rules: A variable name must start with a letter or an underscore character (_) A variable name cannot start with a digit. A variable name can only contain alpha-numeric characters and underscores ( a-z, A-Z , 0-9 , and _ )
In your code editor, open the JavaScript file you created earlier. All the broken rules will be indicated. If you have the ESLint extension installed you can use CTRL+SHIFT+P to open the Command Palette. Then search for ESLint: Fix all auto-fixable Problems and press ENTER (or RETURN ).
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}$"
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With