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

Add linting support #147

Merged
merged 5 commits into from
Oct 18, 2023
Merged

Add linting support #147

merged 5 commits into from
Oct 18, 2023

Conversation

mpagot
Copy link
Contributor

@mpagot mpagot commented Oct 17, 2023

Include flake8 and pylint as dev dependency.
Add configuration file for pylint and flake8, for the moment all
warnings currently present in the HEAD are disabled.
Add lint targets to the make project.
This commit also result in the github action to run the linter.
Fix simplest warnings.

Verification: https://github.com/openSUSE/qem-bot/actions/runs/6553300955/job/17798390468?pr=147#step:5:1

@codecov-commenter
Copy link

codecov-commenter commented Oct 17, 2023

Codecov Report

Attention: 30 lines in your changes are missing coverage. Please review.

Comparison is base (5142125) 66.13% compared to head (d244842) 66.34%.
Report is 13 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #147      +/-   ##
==========================================
+ Coverage   66.13%   66.34%   +0.21%     
==========================================
  Files          24       24              
  Lines        1680     1682       +2     
==========================================
+ Hits         1111     1116       +5     
+ Misses        569      566       -3     
Files Coverage Δ
openqabot/approver.py 94.87% <100.00%> (ø)
openqabot/loader/config.py 95.77% <100.00%> (ø)
openqabot/loader/repohash.py 97.43% <100.00%> (-0.07%) ⬇️
openqabot/openqabot.py 94.44% <100.00%> (-0.11%) ⬇️
openqabot/syncres.py 97.95% <100.00%> (ø)
openqabot/types/aggregate.py 86.84% <ø> (ø)
openqabot/types/baseconf.py 89.47% <100.00%> (+2.80%) ⬆️
openqabot/types/incident.py 96.15% <100.00%> (ø)
openqabot/utils.py 100.00% <100.00%> (ø)
openqabot/main.py 42.85% <0.00%> (ø)
... and 7 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Include flake8 and pylint as dev dependency.
Add configuration file for pylint and flake8, for the moment all
warnings currently present in the HEAD are disabled.
Add lint targets to the make project.
Add lint stage in github pipeline.
Enable most of the flake8 tests.
Fix simple problems from flake8 report.
Remove logging lint warning disabling
Add lazy formatting where needed
Fix warning about unused code
Fix warning about imports
Fix warning about too complex if/else
openqabot/approver.py Show resolved Hide resolved
openqabot/loader/qem.py Show resolved Hide resolved
openqabot/openqa.py Show resolved Hide resolved
openqabot/openqabot.py Show resolved Hide resolved
openqabot/smeltsync.py Show resolved Hide resolved
openqabot/smeltsync.py Show resolved Hide resolved
openqabot/smeltsync.py Show resolved Hide resolved
openqabot/utils.py Show resolved Hide resolved
@mpagot mpagot marked this pull request as ready for review October 17, 2023 23:40
Copy link
Member

@okurz okurz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all code changes look fine to me. Just some minor notes about the Makefile

Makefile Outdated Show resolved Hide resolved
openqabot/approver.py Show resolved Hide resolved
openqabot/loader/qem.py Show resolved Hide resolved
openqabot/openqa.py Show resolved Hide resolved
openqabot/openqabot.py Show resolved Hide resolved
openqabot/smeltsync.py Show resolved Hide resolved
openqabot/smeltsync.py Show resolved Hide resolved
openqabot/smeltsync.py Show resolved Hide resolved
openqabot/smeltsync.py Show resolved Hide resolved
openqabot/utils.py Show resolved Hide resolved
Copy link
Contributor

@Martchus Martchus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good to me, including the if-else changes. (I suppose the linter just doesn't like unnecessary elif/else branches when the if branch always returns.)

@mpagot
Copy link
Contributor Author

mpagot commented Oct 18, 2023

Looks all good to me, including the if-else changes. (I suppose the linter just doesn't like unnecessary elif/else branches when the if branch always returns.)

Yes they are from pylint, in Refactory category: specifically the one I addressed are and named

 R1703, # simplifiable-if-statement
 R1705, # no-else-return

Makefile Outdated Show resolved Hide resolved
Comment on lines 16 to 21
- name: Linting
run: make lint
- name: Run tests + cov report
run: make test-with-coverage
- name: Check style
run: make checkstyle
run: make black
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would combine those style checks so

      - name: Run tests + cov report
        run: make test-with-coverage
      - name: Check style
        run: make checkstyle

so effectively just leave it as is as you added lint+flake8 to checkstyle

Copy link
Contributor Author

@mpagot mpagot Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it make sense for the user to have output from black separated from the one from (pylint and flake8)

pylint and flake8 also have some warning about formatting and indentation that black will detect as error too.

But the part I like the user perceive as lint is all the warning not about indentation like: unused variables, duplicated code, too complex code, ...

In order of importance the code should pass:

  • static analysis (pylind flake8)
  • runtime analysis (pytest, coverage)
  • code formatting (black)

@okurz what do you think about this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I guess the both of us had a similar idea. In #148 I actually used flake8-black which avoids having to call multiple tools and instead integrates them

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pylint and flake8 also have some warning about formatting and indentation that black will detect as error too.

You mean part of the checks are redundant? That's certainly true. But I don't understand why then you would need to separate.

In order of importance the code should pass …

hm, I consider black always part of "static analysis". Another reason why I suggest to just call the meta-target checkstyle in CI as well is to make sure the target actually works to prevent errors like in #147 (comment) :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok good for me to so :-)

@mpagot mpagot force-pushed the linter branch 2 times, most recently from 9eb1c68 to 3e03e61 Compare October 18, 2023 13:43
Rename target name for black execution from checkstyle to black
Add aggregate lint and black under checkstyle target
@mergify mergify bot merged commit 70551f9 into openSUSE:master Oct 18, 2023
3 checks passed
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

Successfully merging this pull request may close these issues.

5 participants