Github Actions, Flake8 and SonarCloud

Hello, I am trying to import a flake8 txt report file into SonarCloud, as part of a Github Actions pipeline, using the following code:

[build.yml]

# Flake8
- name: Lint with flake8
  run: |
		flake8 --exit-zero --output-file=flake8.txt .

[sonar-project.properties]

sonar.python.flake8.reportPaths=/github/workspace/flake8.txt

But when I do so I get the following error:

17:02:21.307 INFO: Sensor Import of Flake8 issues [python]
17:02:21.334 ERROR: No issues information will be saved as the report file '/github/workspace/flake8.txt' can't be read. IllegalArgumentException: -1 is not a valid line offset for a file

And the flake8 info is not coming through to SonarCloud

Are you able to help with what the error means and how to fix it? Many thanks

Hey there.

This would typically imply that some issue in the report is being reported as raised on a the -1st “something” of a file/line (a line number or column). Of course… that doesn’t make much sense. Anything look like this in your report file?

Thanks Colin. We don’t see anything strange with the flake8.txt file - it’s many lines, each with this structure:

path/to/file.py:line:char: RULE description of rule

We were wondering if a blank line at the end of the flake8 report file might be causing the problem, so we tried:

[build.yml]

flake8 --exit-zero --output-file=flake8tmp.txt .
cat flake8tmp.txt| grep ^. > flake8.txt

But still get the same error

I’ve sent you a private message if you’d like to share your Flake8 report

Thanks @Colin for your help with this!

For anyone else having similar problems, in my case the problem lines in flake8.txt were of the form:

./path/to/file.py:21:0: F523 ‘…’.format(…) has unused arguments at position(s): 0

and the problem is the column/character number of 0 in ./path/to/file.py:21:0...

This column number of 0 comes from pyflakes, and results originally from a bug in cpython on Python 3.7, in how it handles column numbers for triple-quoted strings over multiple lines.

Solution for me is to exclude F523 from flake8 - in the longer term, upgrading to Python 3.8 would resolve the issue.

Thanks for the wrap-up @jackg !

On my side, I’ll report. this to see if we want to do anything about it (for example, assume that a column of 0 can be safely corrected to 1).