Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ialarmedalien
Copy link
Collaborator

Adding linter rules to enforce rules that ensure that identifier and key only appear once per class

@ialarmedalien ialarmedalien self-assigned this Sep 30, 2025
@ialarmedalien ialarmedalien added enhancement New feature or request linting labels Sep 30, 2025
Each attribute of this class represents a rule that can be enabled and possibly
configured by a configuration file.
attributes:
canonical_prefixes:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I put these in alphabetical order, hence the large diff in this and the generated file.

Comment on lines -48 to -49
validator = validator_cls(meta_json_schema, format_checker=validator_cls.FORMAT_CHECKER)
return validator
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No need to create a variable if you return it immediately.

Comment on lines +322 to +323
class OnePerClass(LinterRule):
"""Ensures that there is only one slot with the specified attribute per class."""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Both checks are very similar so can create a more generic function to test.

@codecov
Copy link

codecov bot commented Sep 30, 2025

Codecov Report

❌ Patch coverage is 92.13483% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.82%. Comparing base (5863045) to head (090477d).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
linkml/linter/config/datamodel/config.py 90.27% 0 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2921      +/-   ##
==========================================
+ Coverage   80.41%   83.82%   +3.41%     
==========================================
  Files         140      140              
  Lines       15588    15611      +23     
  Branches     3167     3171       +4     
==========================================
+ Hits        12535    13086     +551     
+ Misses       2399     1833     -566     
- Partials      654      692      +38     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ialarmedalien ialarmedalien force-pushed the linter_enforce_single_elements branch from a9d3dc5 to d49ef03 Compare September 30, 2025 21:58
Copy link
Member

@dalito dalito left a comment

Choose a reason for hiding this comment

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

The test function is quite complex and difficult to review without running it. I have another look tomorrow.

@ialarmedalien
Copy link
Collaborator Author

LMK if there is extra documentation or more comments that I can add to the tests to make it clearer how I'm generating the schemas. It makes perfect sense when you're writing the code but isn't always easy to decode when reading it.

@ialarmedalien ialarmedalien force-pushed the linter_enforce_single_elements branch from 88a233a to 55b7a7e Compare October 1, 2025 15:08
- id_slot_false
- key_slot_false
This allows the testing of a large number of combinations without having to generate them all manually.
Copy link
Member

@dalito dalito Oct 1, 2025

Choose a reason for hiding this comment

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

To help grasp the pytest trick you could be explicit: "This and the stacked parametrize decorators allow testing of all combinations (2**6=64) ..."

Copy link
Member

@dalito dalito left a comment

Choose a reason for hiding this comment

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

Thanks for adding the additional comments. They helped to understand what will happen in the test. I first read the code and then ran it with some print-statements to verify my understanding.

@ialarmedalien ialarmedalien merged commit 44b0b32 into main Oct 1, 2025
35 of 36 checks passed
@ialarmedalien ialarmedalien deleted the linter_enforce_single_elements branch October 1, 2025 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request linting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants