Skip to content

Fix region - #48

Open
layfield-ccdc wants to merge 4 commits into
mainfrom
fix-region
Open

layfield-ccdc wants to merge 4 commits into
mainfrom
fix-region

Conversation

@layfield-ccdc

Copy link
Copy Markdown
Contributor

No description provided.

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.

🟡 Changes recommended

Header rewriting can break Python source decoding, duplicate headers after commented using directives, and leave duplicated licence fragments.

4 open issues
What changed in this PR

This PR expands the licence-header checker and fixer to recognise headers throughout leading preambles, including region wrappers, and repair them without unnecessary duplication.

Changes:

  • Adds normalised header matching, preamble classification, and duplicate detection.
  • Repairs damaged headers in place and inserts missing headers into labelled licence regions.
  • Documents detection rules and adds regression tests for regions, formatting, and repeated fixes.
File Description
test/​test_licence_headers.py Adds coverage for preambles, regions, duplicate removal, and stable fixes.
README.md Documents header detection and repair behaviour.
main/​licence_headers.py Implements preamble scanning, flexible matching, and span-based repairs.

Review effort: Balanced

Comment thread main/licence_headers.py
Comment thread main/licence_headers.py Outdated
Comment thread main/licence_headers.py
Comment thread main/licence_headers.py Outdated

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.

Comment thread main/licence_headers.py
return True
matcher = SequenceMatcher(None, actual, expected, autojunk=False)
longest = matcher.find_longest_match(0, len(actual), 0, len(expected)).size
return (longest >= 6 and longest >= len(actual) / 2) or matcher.ratio() >= 0.75
Comment thread main/licence_headers.py
PREAMBLE_DIRECTIVES = {
'.cs': (
re.compile(
r'^\s*(?:global\s+)?using\s+(?:static\s+)?[\w.]+(?:\s*=\s*[\w.<>, ]+)?\s*;'
Comment thread main/licence_headers.py
Comment on lines +365 to +374
index = span.end
while index < len(classified) and _is_padding(classified[index]):
index += 1
if index >= len(classified) or classified[index].kind != 'comment' or _claimed(claimed, index):
return
others = [other for other in claimed if other is not span]
fragment = _confirmed_template_run(classified, index, expected, 1, others)
if fragment is not None:
span.end = _include_trailing_marker(classified, fragment[1], others)
span.valid = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants