-
-
Notifications
You must be signed in to change notification settings - Fork 327
Support hyphens in error codes #1568
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
Comments
It sounds like this feature request is rejected, so rather than continue the discussion on the PR I thought I'd try to plead my case here. I'd like to understand the reasons for rejecting this, and wanted to dig in a little deeper to the reasons I think it's a good idea. I don't think HYPHENATED-CODES should replace SRT123 codes but there's room for both to exist. (I also understand that there's no obligation for the maintainers to continue this conversation, and if that's the case, so be it, no worries). Firstly, the rest of flake8 and the ecosystem of plugins already works without incident with HYPHENATED-CODES. There is code out there in the wild producing error codes that don't match the form SRT123. I could only find the config parser with the original constraints (and a pycodestyle regex that enforces A123 type codes). Second, ignoring rules using short-codes impairs readability, as you usually have to go search for what a code means or add comments into the config file to understand what they're used for. Eg Similarly, adding NOQA lines with HYPHENATED-CODES can read a bit nicer:
Coming up with unique SHR123 codes can also be a bit of a hassle. You need to make sure you're not clashing with existing prefixes that other plugins have defined. Then you need some kind of numbering scheme so that similar rules are within the same range. Finally, supporting arbitrary length codes with hyphens doesn't seem to cause any issues either. I hope you can reconsider, thanks |
this isn't the first time this has come up. I encourage you to search the tracker and find the duplicates where this has been decided |
Thanks for the pointer (I did a cursory search prior but searching for code and regex wasn't the easiest search I've ever had to perform). #325 seems to be one of the most relevant issues. It seems to boil down to being able to differentiate between codes and files, and playing nice with other tooling. Fair enough, cheers! |
fwiw, you generally want |
flake8 has always expected codes to use formats like 'E123' or 'W451'. More complex codes like 'COMPANY-UNIT-TESTS-FILEPATH' have traditionally worked everywhere *except* in flake8 configuration files, and attempts to change this have been rejected [1]. The upcoming version of flake8 now enforced this practice everywhere, which is resulting in the following error message when attempting to use 'flake8-logging-format' with master of 'flake8' [2]: There was a critical error during execution of Flake8: plugin code for `flake8-logging-format[logging-format]` does not match ^[A-Z]{1,3}[0-9]{0,3}$ The resolution here is change our code to something that matches this pattern. We use 'LF' since it should be fairly unique and _somewhat_ descriptive. [1] PyCQA/flake8#1568 [2] PyCQA/flake8#325 Signed-off-by: Stephen Finucane <stephen@that.guru>
flake8 has always expected codes to use formats like 'E123' or 'W451'. More complex codes like 'COMPANY-UNIT-TESTS-FILEPATH' have traditionally worked everywhere *except* in flake8 configuration files, and attempts to change this have been rejected [1]. The upcoming version of flake8 now enforced this practice everywhere, which is resulting in the following error message when attempting to use 'flake8-logging-format' with master of 'flake8' [2]: There was a critical error during execution of Flake8: plugin code for `flake8-logging-format[logging-format]` does not match ^[A-Z]{1,3}[0-9]{0,3}$ The resolution here is change our code to something that matches this pattern. We use 'G' as this matches the codes provided by this plugin. [1] PyCQA/flake8#1568 [2] PyCQA/flake8#325 Signed-off-by: Stephen Finucane <stephen@that.guru>
flake8 has always expected codes to use formats like 'E123' or 'W451'. More complex codes like 'COMPANY-UNIT-TESTS-FILEPATH' have traditionally worked everywhere *except* in flake8 configuration files, and attempts to change this have been rejected [1]. The upcoming version of flake8 now enforced this practice everywhere, which is resulting in the following error message when attempting to use 'flake8-logging-format' with master of 'flake8' [2]: There was a critical error during execution of Flake8: plugin code for `flake8-logging-format[logging-format]` does not match ^[A-Z]{1,3}[0-9]{0,3}$ The resolution here is change our code to something that matches this pattern. We use 'G' as this matches the codes provided by this plugin. [1] PyCQA/flake8#1568 [2] PyCQA/flake8#325 Signed-off-by: Stephen Finucane <stephen@that.guru>
describe the request
I'd like to be able to use hyphens in error codes so that I can have readable error codes that are name-spaced. For example, here's a list of some error codes we're currently using:
COMPANY-UNIT-TESTS-FILEPATH
COMPANY-FUNCTIONAL-TESTS-FILEPATH
COMPANY-PRINT-STATEMENTS
COMPANY-MOCK-ASSERT-METHODS
These codes work fine with
noqa
directives. The only place they don't seem to work is in flake8 configuration files (such as setup.cfg). That is, the following config file crashes flake8:With the error:
I believe it comes down to this line:
flake8/src/flake8/utils.py
Line 59 in 94ed800
The fix could be a simple update of the regex. I will put a patch together shortly to demonstrate a potential fix.
The text was updated successfully, but these errors were encountered: