feat!: needextend effects must be local - #689
Open
AlexanderLanin wants to merge 1 commit into
Open
Conversation
AlexanderLanin
requested review from
MaximilianSoerenPollak,
dcalavrezo-qorix and
nradakovic
as code owners
August 4, 2026 22:16
Contributor
License Check Results🚀 The license check job ran with the Bazel command: bazel run --lockfile_mode=error //src:license-checkStatus: Click to expand output |
There was a problem hiding this comment.
Pull request overview
This PR activates and refactors the SCORE “needextend must be local to the current document” policy enforcement, updates documentation to reflect the now-active constraint, and adds/adjusts tests so warnings can be asserted for both needs and needextend directives.
Changes:
- Refactors
check_needs_extendsinto smaller helpers and enforces explicitc.this_doc()usage plus cross-document match detection. - Adds unit tests for cross-document needextend matches and updates the file-based RST test case to expect the new policy warning.
- Extends the file-based warning expectation runner to read
:expect:/:expect_not:annotations from needextend directives (via modifications).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/extensions/score_metamodel/tests/test_rules_file_based.py | Adds helper to read expectations from needextend modifications and uses it in warning checks. |
| src/extensions/score_metamodel/tests/test_check_needs_extends.py | New mocked unit tests verifying cross-document matching produces the expected warning. |
| src/extensions/score_metamodel/tests/rst/options/test_need_extends.rst | Activates an RST-level expectation for missing c.this_doc() on a needextend filter. |
| src/extensions/score_metamodel/checks/check_needs_extends.py | Refactors and strengthens the needextend policy checks (explicit c.this_doc() + cross-document match detection). |
| docs/how-to/write_docs.rst | Updates documentation note to reflect the now-enforced local-only needextend rule. |
Comment on lines
+97
to
+107
| try: | ||
| return filter_needs_mutable( | ||
| all_needs, | ||
| needs_config, | ||
| need_filter, | ||
| location=location, | ||
| origin_docname=location[0], | ||
| ) | ||
| except Exception as e: | ||
| _warn(f"Invalid filter {need_filter!r}: {e}", location) | ||
| return [] |
Comment on lines
+76
to
+84
| need_id = needextend["filter"] | ||
| try: | ||
| return [all_needs[need_id]] | ||
| except KeyError: | ||
| _warn( | ||
| f"Provided id {need_id!r} for needextend does not exist.", | ||
| location, | ||
| ) | ||
| return [] |
Comment on lines
246
to
+249
|
|
||
| line_nr = need.get("lineno") | ||
|
|
||
| for raw in cast("list[str]", need.get("expect") or []): | ||
| for raw in _get_expectations(need, "expect"): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We wanted to ensure local needextend for a while, but it seems we forgot to actually activate the check. Besides activating, this PR also improves and fixes the check itself.
Downstream PRs: