Skip to content
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

Flake8 plugins custom errors are not supported #6

Open
Cjkjvfnby opened this issue Jul 11, 2020 · 6 comments
Open

Flake8 plugins custom errors are not supported #6

Cjkjvfnby opened this issue Jul 11, 2020 · 6 comments

Comments

@Cjkjvfnby
Copy link

I use flake8 plugins and they produce output that is not parsed by actions.

Thye use own letters for messages
D : flake8-docstrings==1.5.0
I: flake8-import-order==0.18.1
B: flake8-bandit==2.1.2

Here is an example:

foo.py:36:1: D400 First line should end with a period
foo:119:1: I100 Import statements are in the wrong order ...

I would like them to be annotated too.

I will just put some idea, I don't know if they are implementable:

  • Add a new problemMatcher for extra errors (always enabled).
  • Same as prev but has different version @v1 - > @x2
  • Add a new problemMatcher[s] and an option[s] to enable.
  • Add new option to specify the list of new error prefixes: 'BID' (I don't if it easy to do in the current infrastructure.)

The alternative solution is to write a new plugin for flake8 that will change the output. Like a plugin for TeamCity CI.

My use case is not very common, so won't fix is an option too.

@Cjkjvfnby
Copy link
Author

I end up with a simple solution via flake8 --format argument. Any reported item is a blocker in my case.

- name: Lint with flake8
        run: |
          flake8 default/python --count --format="::error file=%(path)s,line=%(row)d,col=%(col)d::%(path)s:%(row)d:%(col)d: %(code)s %(text)s" --config=default/python/tox.ini

PS. I tried to use working-directory: default/python an flake8 . --format="::error file=default/python/%(path)s, but github error does not set comment with paths like default/python/./file.py. The plugin does not catch such cases as well.

@rbialon
Copy link
Owner

rbialon commented Aug 18, 2020

Thank your for your suggestions!

The annotations are generated by Githubs own annotator. Searching for warnings/errors is configured via regex in a static configuration file for the problemMatcher. It would very well be possible to include further annotations generated by flake8 plugins.
The regex for warnings is "^([^:]+):(\\d+):(\\d+):\\s+([CFNW]\\d+\\s+.+)$" right now. C, F, N and W are valid prefixes for warnings recognized for annotations. This can be extended for additional prefixes, or simply defined as a negation of error prefixes (only E right now, so [^E]).

If it's fine to classify additional plugins output as warnings only, I would prefer the second option, otherwise plugin outputs have to be categorized in warning and error level each. But it's definitely doable.

@Cjkjvfnby
Copy link
Author

Some plugins use long prefixes, for example, ANN001 in https://pypi.org/project/flake8-annotations/

@Cjkjvfnby
Copy link
Author

If it's fine to classify additional plugins output as warnings only

In the CI context, I prefer to treat anything reported by flake8 as errors. If something is reported it should be fixed, suppressed, or disabled. It does not matter for me which annotation will highlight these errors.

@philosofool
Copy link

Thank your for your suggestions!

The annotations are generated by Githubs own annotator. Searching for warnings/errors is configured via regex in a static configuration file for the problemMatcher. It would very well be possible to include further annotations generated by flake8 plugins.
The regex for warnings is "^([^:]+):(\\d+):(\\d+):\\s+([CFNW]\\d+\\s+.+)$" right now. C, F, N and W are valid prefixes for warnings recognized for annotations. This can be extended for additional prefixes, or simply defined as a negation of error prefixes (only E right now, so [^E]).

If it's fine to classify additional plugins output as warnings only, I would prefer the second option, otherwise plugin outputs have to be categorized in warning and error level each. But it's definitely doable.

I tried coping the two problem-matcher.json files to my local .github and editing to include 'D' in the warning regex to add docstring violations to the annotations, but it does not appear to have worked. I'm a new two github actions---it there something else I have to reference to change this functionality?

@philosofool
Copy link

Thank your for your suggestions!
The annotations are generated by Githubs own annotator. Searching for warnings/errors is configured via regex in a static configuration file for the problemMatcher. It would very well be possible to include further annotations generated by flake8 plugins.
The regex for warnings is "^([^:]+):(\\d+):(\\d+):\\s+([CFNW]\\d+\\s+.+)$" right now. C, F, N and W are valid prefixes for warnings recognized for annotations. This can be extended for additional prefixes, or simply defined as a negation of error prefixes (only E right now, so [^E]).
If it's fine to classify additional plugins output as warnings only, I would prefer the second option, otherwise plugin outputs have to be categorized in warning and error level each. But it's definitely doable.

I tried coping the two problem-matcher.json files to my local .github and editing to include 'D' in the warning regex to add docstring violations to the annotations, but it does not appear to have worked. I'm a new two github actions---it there something else I have to reference to change this functionality?

If figured out that if I add to my workflow

run: |
  echo "::add-matcher::.github/flake8-error-problem-matcher.json"
  echo "::add-matcher::.github/flake8-warning-problem-matcher.json"

and those files are in my .github directory, it runs correctly. The files can then be edited.

silasary added a commit to silasary/flake8-annotations that referenced this issue Dec 31, 2021
See rbialon#6
Adds support for flake8-annotations, flake8-bandit, flake8-docstrings and flake8-import-order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants