Skip to content

exclude entities from standard naming linter rule#2793

Merged
turbomam merged 16 commits into
mainfrom
2788-add-exclude-option-to-linters-standard-naming-rule
Jul 30, 2025
Merged

exclude entities from standard naming linter rule#2793
turbomam merged 16 commits into
mainfrom
2788-add-exclude-option-to-linters-standard-naming-rule

Conversation

@turbomam

@turbomam turbomam commented Jul 2, 2025

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings July 2, 2025 18:28
@turbomam turbomam linked an issue Jul 2, 2025 that may be closed by this pull request
@turbomam turbomam requested a review from pkalita-lbl July 2, 2025 18:28

This comment was marked as outdated.

@turbomam turbomam removed the request for review from pkalita-lbl July 2, 2025 18:30
@turbomam turbomam marked this pull request as draft July 2, 2025 18:30
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread linkml/linter/config/datamodel/config.yaml Outdated
@codecov

codecov Bot commented Jul 2, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.98%. Comparing base (e7de145) to head (6297f18).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
linkml/linter/config/datamodel/config.py 87.50% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2793      +/-   ##
==========================================
- Coverage   82.99%   82.98%   -0.02%     
==========================================
  Files         126      126              
  Lines       13993    13994       +1     
  Branches     3908     3903       -5     
==========================================
- Hits        11614    11613       -1     
- Misses       1730     1731       +1     
- Partials      649      650       +1     

☔ 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.

@turbomam turbomam marked this pull request as ready for review July 2, 2025 19:51

@pkalita-lbl pkalita-lbl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

Not necessary for right now, but a thought for later: if we find other rules that might be excludable or includable by element name or type we should think about abstracting the exclude, exclude_type, etc attributes out into mixins.

Comment thread tests/test_linter/test_rule_standard_naming.py
Comment thread linkml/linter/config/datamodel/config.yaml Outdated
Comment thread linkml/linter/config/datamodel/config.py Outdated
messages = [p.message for p in problems]
assert "Class has name 'another_bad_class'" in messages
assert "Slot has name 'AnotherBadSlot'" in messages
assert "Enum has name 'another_bad_enum'" in messages

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It might be easier to do the following for the tests:

expected_messages = {
  "Class has name 'another_bad_class'",
  "Slot has name 'AnotherBadSlot'",
  "Enum has name 'another_bad_enum'",
  "Permissible value of Enum 'GoodEnum' has name 'Extra_Bad_Pv'"
}

assert {p.message for p in problems} == expected_messages

The "not" assertions are automatically tested.

Comment thread linkml/linter/rules.py
@turbomam turbomam force-pushed the 2788-add-exclude-option-to-linters-standard-naming-rule branch from 83ef61b to 6eb611a Compare July 28, 2025 13:09
turbomam and others added 4 commits July 28, 2025 09:24
Added clear examples of names that would fail validation and need exclusion:
- "legacy_class" (class name in snake_case instead of UpperCamel)
- "badSlot" (slot name in camelCase instead of snake_case)
- "bad_enum" (enum name in snake_case instead of UpperCamel)
- "LEGACY_PERMISSIBLE_VALUE" (permissible value in UPPER_SNAKE when snake_case expected)

Addresses feedback from @ialarmedalien requesting concrete examples.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
The config.py file is auto-generated from config.yaml via the Makefile.
Previous manual edits to config.py would have been lost on next generation.
Now properly regenerated to include the updated exclude field documentation.

Addresses feedback from @ialarmedalien about config.py being auto-generated.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Changes based on @ialarmedalien's feedback:
- Added "Extra_Bad_Pv" as additional bad permissible value to test exclusion
- Replaced individual assert statements with cleaner set-based comparison
- The set approach automatically tests both positive and negative cases
- More concise and maintainable test structure

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Pre-commit hooks automatically fixed:
- Deprecated typing.Dict/List imports in auto-generated config.py
- Line length violation in test file (broke long comment into multiple lines)
- Missing newline at end of config.py file

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
turbomam and others added 2 commits July 28, 2025 09:38
Implemented @ialarmedalien's suggested refactoring:
- Consolidated patterns into a dictionary indexed by element type
- Used list comprehensions and generator expressions for cleaner logic
- Eliminated repetitive if/for loops for classes, slots, and enums
- More maintainable and easier to understand code structure
- All tests pass - functionality unchanged

The refactored approach uses data structures and loops instead of
repetitive conditional blocks, making the code much more concise.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Auto-generated linkml/linter/config/datamodel/config.py uses older typing
patterns (Dict/List) that violate UP035 rule. Since this file is generated
by gen-python, the issue is upstream in the LinkML Python generator.

Added UP035 to per-file-ignores to prevent CI failures on generated code.
This is a pragmatic solution until the generator is updated.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

This comment was marked as outdated.

- Replace list comprehensions with generator expressions for better memory efficiency
- Use explicit method mapping dictionary instead of getattr() for better readability
- Chain generators with itertools.chain() instead of extending lists
- Maintain same functionality while improving performance and code clarity

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

This comment was marked as outdated.

- Rename schema_methods to element_extractors for clarity
- Cache method results to avoid repeated function calls during iteration
- Return iter(problems) for consistent generator behavior in both code paths
- Maintain all functionality while improving performance and code clarity

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@turbomam turbomam requested a review from Copilot July 28, 2025 14:28

This comment was marked as outdated.

@turbomam turbomam requested a review from Copilot July 28, 2025 14:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds functionality to exclude specific named entities from the standard naming linter rule by introducing a new exclude configuration option. This allows users to skip naming validation for specific classes, slots, enums, and permissible values by name.

Key changes:

  • Added new exclude configuration parameter to skip named entities from linting
  • Refactored the StandardNamingRule check method to use a more efficient generator-based approach
  • Updated auto-generated configuration files and linter exclusions

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
linkml/linter/config/datamodel/config.yaml Added new exclude field definition to the StandardNamingConfig schema
linkml/linter/config/datamodel/config.py Auto-generated configuration class with new exclude field and validation logic
linkml/linter/rules.py Refactored StandardNamingRule to support entity exclusion by name and improved efficiency
tests/test_linter/test_rule_standard_naming.py Added comprehensive test cases for the new exclude functionality
pyproject.toml Updated linter configuration to exclude auto-generated files and added UP035 rule exception

Comment thread linkml/linter/rules.py
Comment thread pyproject.toml
"linkml/generators/sqlalchemy/sqlalchemy_declarative_template.py" = ["E501"]
"linkml/generators/sqlalchemy/sqlalchemy_imperative_template.py" = ["E501"]
"linkml/linter/config/datamodel/config.py" = ["E501", "F401", "I001"]
"linkml/linter/config/datamodel/config.py" = ["E501", "F401", "I001", "UP035"]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the python generator uses old-style type hints but our linter doesn't like that

@turbomam turbomam merged commit 55ce825 into main Jul 30, 2025
22 checks passed
@turbomam turbomam deleted the 2788-add-exclude-option-to-linters-standard-naming-rule branch July 30, 2025 19:52
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.

add exclude option to linter's standard naming rule

5 participants