Skip to content

Fix audit-ignore rule scoping - #777

Merged
moritz-gross merged 4 commits into
daisy:mainfrom
Kostenkov-2021:main
Sep 20, 2026
Merged

moritz-gross merged 4 commits into
daisy:mainfrom
Kostenkov-2021:main

Conversation

@Kostenkov-2021

@Kostenkov-2021 Kostenkov-2021 commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Adjust the audit-translations parser so # audit-ignore markers immediately above a rule apply to that rule, while still supporting existing inline markers inside a rule block. This also clarifies the documented behavior and adds regression tests for leading, inline, and first-item ignore cases.
• Closes #742

Adjust the audit-translations parser so `# audit-ignore` markers immediately above a rule apply to that rule, while still supporting existing inline markers inside a rule block. This also clarifies the documented behavior and adds regression tests for leading, inline, and first-item ignore cases.
@moritz-gross

Copy link
Copy Markdown
Collaborator

logic looks correct, tests make sense and cover the important parts.
if we make the changes easier to follow, then we're good to go in my opinion

@moritz-gross

Copy link
Copy Markdown
Collaborator
>         content = """- name: first
>   tag: mo
>   match: "."
> 
> # audit-ignore: the following placeholder intentionally differs
> # from the source-language rule.
> - name: second
>   tag: mi
>   match: "false()"
> """

on a side-note, I'm not really happy with how the formatting of the first vs. second line of these YAML strings looks.
As I've used the same ugly style myself, it would be unfair to criticize that here.
When I worked on it, I didn't want to immediately do a full line break after """ at the start, but I think this would be visually the best option.

Or is there anything else I'm missing here?
Again, only semi-related to the PR, this only brought it up to my attention again.

@yasumorishima

Copy link
Copy Markdown
Contributor

Numbers for the trailing-comment case, measured on main (49de6d67) over Rules/Languages.

There are 1,140 comment runs between consecutive rules. Splitting them by whether a blank line sits above the run:

shape count audit-ignore markers
blank line above the run (leading comment for the next rule) 995 2 (both ru)
directly under the item's own - line 39 0
touching the previous rule's last content line 106 0

The middle group is worth calling out: data.lc.item(idx) reports the name: line, so for

- # intervals are controlled by a ClearSpeak Preference ...
  name: ClearSpeak-intervals

main attributes those comment lines to the previous rule even though they are textually inside this item. This PR fixes 39 of those as a side effect.

The third group is the one flagged in #742. A predicate that keeps it with the previous rule, while still fixing the other two, is three branches when walking up from starts[idx]: stop and take the run if a blank line is above it; also absorb the item's own - line (a line matching ^\s*-\s*(#.*)?$) and stop; otherwise hand the run back to the previous block.

I ran that over the tree and it yields exactly the same set of ignored rules as this PR — 0 differences — both differing from main only by the two ru placeholders (296 in rule files, plus the 2 in hu/unicode.yaml, which is parsed by the unicode path, = 298).

One more shape, whichever way this goes: a marker written on the dash line itself (- # audit-ignore) still lands on the previous rule, because the upward walk stops at the dash. 146 dash lines carry a comment today and none of them carry a marker, so this is a README line rather than a bug.

This change fixes how audit_translations YAML blocks are split when comments or blank lines appear around list items. It keeps introductory comments with the correct rule, preserves explicit audit-ignore markers inside a rule, and avoids incorrectly attaching comment-only lines to neighboring items.
Comment thread PythonScripts/audit_translations/parsers.py Outdated
Comment thread PythonScripts/audit_translations/parsers.py Outdated
@moritz-gross

Copy link
Copy Markdown
Collaborator

thanks for your work. merged!

@moritz-gross
moritz-gross merged commit 374ea58 into daisy:main Sep 20, 2026
10 checks passed
@github-project-automation github-project-automation Bot moved this from Triage to Done in MathCAT Project Board Sep 20, 2026
@yasumorishima

Copy link
Copy Markdown
Contributor

Thanks for merging. I measured the merged main (374ea588) against the merge base (5c8117e9) afterwards, since I had the numbers half-collected; posting them here in case they are useful as a record. Nothing below asks for a change.

The corpus is the 174 non-definitions.yaml files under Rules/Languages, 172 of which parse into rules (el/unicode.yaml still raises DuplicateKeyError, one file has no rules). The Rules tree is byte-identical on both sides, so the comparison is like for like.

The attribution moves by exactly one pair, and it moves where it should. Rules whose block satisfies has_audit_ignore, counted through parse_yaml_file: 298 before, 298 after; the corpus holds 298 # audit-ignore lines. The two sets differ only in Rules/Languages/ru/navigate.yaml:

marker suppressed before suppressed now
lines 1369-1370 move-next-none, tag: none (line 1348) move-next-none, tag: [none, mprescripts] (line 1371)
lines 1398-1399 move-previous-none, tag: none (line 1377) move-previous-none, tag: [none, mprescripts] (line 1400)

The marker itself reads "parity placeholder for English tag list without changing the existing Russian none-specific rule above", so the rule below it is the one it was written for. End to end, audit-translations ru --file navigate.yaml goes from 214 to 206 rule issues (rule differences 34 to 26): the eight issues raised against the two placeholders disappear, and diffing the two reports shows removals only, nothing newly reported.

The dash-line form is fixed as well. With the marker on the item's own dash line

- # audit-ignore
  name: second

the merge base attributes it to the preceding rule and main now attributes it to second. A comment run separated by a blank line lands on the following rule, and a run touching the preceding rule's body stays with that rule, as intended.

One boundary worth writing down, with no action needed today: a marker on an indented line under the dash line, with no blank above it, still goes to the preceding rule.

-
  # audit-ignore
  name: second

(the same if the dash line already carries a comment). In Rules/Languages today, 144 rules have their name: directly under a dash line and 37 have indented comments between the dash line and name:; neither group contains an audit-ignore marker, which is why the 298 counts above are unchanged. The README documents the blank-line form; the dash-line form now works too, if it is ever worth a sentence there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: parsers.py can misattribute the #audit-ignore comment

3 participants