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

linters: allow "categories" for subfiltering #4077

Merged
merged 2 commits into from
Mar 23, 2023

Conversation

tigarmo
Copy link
Contributor

@tigarmo tigarmo commented Mar 17, 2023

This commit adds the notion of "categories" for Linter subclasses. For linters that perform multiple different "types" of linting, this lets the author ignore specific paths for specific types of linting issues, with a finer granularity than ignoring the whole linter wholesale.

Currently the only Linter type that supports this is the LibraryLinter, which provides the "unused-library" and "missing-library" categories to disable checking for unused or missing libraries.

CRAFT-1642

  • Have you followed the guidelines for contributing?
  • Have you signed the CLA?
  • Have you successfully run make lint?
  • Have you successfully run pytest tests/unit?

First commit has the general linter changes, second commit has the update of the ros extension.

@codecov-commenter
Copy link

codecov-commenter commented Mar 17, 2023

Codecov Report

Merging #4077 (729462a) into main (dcd59d8) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 729462a differs from pull request most recent head 4ac70be. Consider uploading reports for the commit 4ac70be to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #4077      +/-   ##
==========================================
- Coverage   94.60%   94.60%   -0.01%     
==========================================
  Files         641      641              
  Lines       51842    51822      -20     
==========================================
- Hits        49045    49026      -19     
+ Misses       2797     2796       -1     
Impacted Files Coverage Δ
snapcraft/extensions/ros2_humble.py 96.96% <ø> (ø)
tests/unit/parts/extensions/test_ros2_humble.py 95.65% <ø> (ø)
snapcraft/linters/base.py 98.43% <100.00%> (+0.28%) ⬆️
snapcraft/linters/library_linter.py 87.95% <100.00%> (+1.87%) ⬆️
snapcraft/linters/linters.py 97.67% <100.00%> (+0.08%) ⬆️
tests/unit/linters/test_library_linter.py 100.00% <100.00%> (ø)
tests/unit/linters/test_linters.py 100.00% <100.00%> (ø)

... and 9 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tigarmo tigarmo force-pushed the CRAFT-1642-disable-unused-linter branch 2 times, most recently from 0d86b74 to f9b9ac8 Compare March 17, 2023 20:53
@tigarmo tigarmo marked this pull request as ready for review March 17, 2023 21:00
@tigarmo tigarmo requested review from cmatsuoka and sergiusens March 17, 2023 21:00
Copy link
Collaborator

@sergiusens sergiusens left a comment

Choose a reason for hiding this comment

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

Looks good, nice and clean.
Can we extend the ros related spread test that uses the extension to verify this is working as expected too?
Additionally, can we have a spread test that declares linter entries?

@tigarmo
Copy link
Contributor Author

tigarmo commented Mar 20, 2023

Can we extend the ros related spread test that uses the extension to verify this is working as expected too?

Do you mean by e.g. checking the snapcraft output and verifying that no linter issues are emitted? Sure

Additionally, can we have a spread test that declares linter entries?

Yes. I'll do both in a little bit.

@tigarmo
Copy link
Contributor Author

tigarmo commented Mar 21, 2023

@sergiusens thank you for the suggestion, it pointed out an unexpected interaction. First, I added a new spread test that uses the ros2-humble extension and verifies that no linter warnings are generated. This worked as expected.

Then I tried to add a new spread with a "user-provided" lint ignore like:

lint:
  ignore:
    - unused-library:
      - usr/lib/*/libpng16.so*

... the resulting behavior is that this new unused-library entry "overrides" the extension-provided one, so the snap generates all the ros-related unused library warnings. I think it would be quite straightforward to update this behavior to have the user-generated lint ignores "add" to the extension-provided ones, but I also think we should do that in a separate task/PR.

What do you think?

@tigarmo tigarmo force-pushed the CRAFT-1642-disable-unused-linter branch from 2c8cc94 to 729462a Compare March 22, 2023 11:22
tigarmo added 2 commits March 22, 2023 18:28
This commit adds the notion of "categories" for Linter subclasses. For
linters that perform multiple different "types" of linting, this lets
the author ignore specific paths for specific types of linting issues,
with a finer granularity than ignoring the whole linter wholesale.

Currently the only Linter type that supports this is the LibraryLinter,
which provides the "unused-library" and "missing-library" categories to
disable checking for unused or missing libraries.
This lets us ignore the many (40+) "unused library" warnings that the
linter emits for the libraries in opt/ros/ and related.
@tigarmo tigarmo force-pushed the CRAFT-1642-disable-unused-linter branch from 729462a to 4ac70be Compare March 22, 2023 21:28
@sergiusens
Copy link
Collaborator

@tigarmo let's ask that question during the demo

@sergiusens sergiusens merged commit e966ab9 into canonical:main Mar 23, 2023
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.

4 participants