10000 Verify plugin validation codes follow expected alphanumeric style · Issue #325 · PyCQA/flake8 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Verify plugin validation codes follow expected alphanumeric style #325

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

Closed
asottile opened this issue Apr 3, 2021 · 7 comments · Fixed by #1579
Closed

Verify plugin validation codes follow expected alphanumeric style #325

asottile opened this issue Apr 3, 2021 · 7 comments · Fixed by #1579
Milestone

Comments

@asottile
Copy link
Member
asottile commented Apr 3, 2021

In GitLab by @pjacock on Nov 27, 2019, 06:10

Spin out from discussion on https://gitlab.com/pycqa/flake8/merge_requests/385

https://gitlab.com/pycqa/flake8/blob/e571167161a42a5da052eaf247ab13ac0c56b7c6/src/flake8/defaults.py#L39 defines a REGEX which implicitly limits the allowed pattern for violation codes:

NOQA_INLINE_REGEXP = re.compile(
    # We're looking for items that look like this:
    # ``# noqa``
    # ``# noqa: E123``
    # ``# noqa: E123,W451,F921``
    # ``# noqa:E123,W451,F921``
    # ``# NoQA: E123,W451,F921``
    # ``# NOQA: E123,W451,F921``
    # ``# NOQA:E123,W451,F921``
    # We do not want to capture the ``: `` that follows ``noqa``
    # We do not care about the casing of ``noqa``
    # We want a comma-separated list of errors
    # https://regex101.com/r/4XUuax/2 full explenation of the regex
    r"# noqa(?::[\s]?(?P<codes>([A-Z]+[0-9]+(?:[,\s]+)?)+))?",
    re.IGNORECASE,
)

There should be a separate pattern for the violation codes (NOQA_INLINE_REGEXP could be defined using this), and this can be used to validate messages from plugins match this (and if not raise an error) before reporting them to the user.

@asottile
Copy link
Member Author
asottile commented Apr 3, 2021

In GitLab by @pjacock on Nov 27, 2019, 06:13

mentioned in merge request !385

@asottile
Copy link
Member Author
asottile commented Apr 3, 2021

In GitLab by @keisheiled on Nov 27, 2019, 09:52

I really prefer named error codes like eslint and pylint, perhaps this regex could instead be expanded

@asottile
Copy link
Member Author
asottile commented Apr 3, 2021

In GitLab by @asottile on Nov 27, 2019, 09:58

it's unfortunately not that simple, especially when you consider the format for per-file-ignores requires us to differentiate between codes and filenames, as soon as you have lower-cased-dashed codes it's going to be hard / impossible to differentiate

flake8 has always had this style of codes and I don't think that's going to change any time soon (even it if kind of accidentally sort-of works in some cases)

@asottile
Copy link
Member Author
asottile commented Apr 3, 2021

In GitLab by @sigmavirus24 on Nov 27, 2019, 12:36

@keisheiled We're already trying not to step on pylint's toes and vice-versa as users run both flake8 and pylint against their codebase. Adding those error codes would only be more confusing and introduce more potential for problems.

In other words, that makes me a hard "no"

@stephenfin
Copy link
Contributor

Assuming I've understood this correctly, it looks like this is happening now. If I look at a plugin that does not follow this pattern, I now get the following errors on master:

$ git clone https://github.com/PyCQA/flake8
$ virtualenv .venv --python=python3.10
$ source .venv/bin/activate
$ pip install flake8-logging-format
$ pip install -e .
$ flake8 src/
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}$

Should this be closed as fixed? Alternatively, should the error be turned to a warning for now to allow some time for developers of flake8 plugins to switch over?

@stephenfin
Copy link
Contributor

I should say, closed as either fixed or won't fix: I think the original ask here was to allow more complex codes which we're clearly not going to do now.

8000
stephenfin added a commit to stephenfin/flake8-logging-format that referenced this issue Jun 15, 2022
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>
stephenfin added a commit to stephenfin/flake8-logging-format that referenced this issue Jun 15, 2022
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>
@asottile asottile added this to the 5.0.0 milestone Jul 30, 2022
sethisernhagen pushed a commit to globality-corp/flake8-logging-format that referenced this issue Aug 5, 2022
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>
@domdfcoding
Copy link

What exactly was the issue with codes with more than 3 letters or numbers (like ABCD1234)? I haven't encountered any issues with plugins that use that format; noqa comments and the per-file-ignores option worked fine (until now, when the plugins are completely non-functional with 5.x)

If I make the plugin's entry point be "ABC" but keep the error codes as "ABCD1234" everything still seems to work fine with flake8 5.x. You can even do --select ABCD to get errors that start with ABCD. So I'm really not sure why the entry point naming requirements have to be so strict now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
43DE
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0