Skip to content

Preserve unlocatable extracts as instance excerpts in nuVal and nuVnu (fixes #38) - #79

Open
wittjeff wants to merge 1 commit into
jrpool:mainfrom
wittjeff:fix/nuval-extract-excerpt
Open

Preserve unlocatable extracts as instance excerpts in nuVal and nuVnu (fixes #38)#79
wittjeff wants to merge 1 commit into
jrpool:mainfrom
wittjeff:fix/nuval-extract-excerpt

Conversation

@wittjeff

Copy link
Copy Markdown
Collaborator

Fixes #38.

Problem

nuVal and nuVnu use a message's extract only to obtain a data-xpath attribute for the element catalog, then discard it. For messages whose extract is not annotated HTML — notably CSS: Parse Error., whose extract is the erroneous CSS itself — getAttributeXPath falls back to /html, so the standard instance is anchored to the page root and the only informative content of the violation is lost. A report consumer sees CSS: Parse Error. with no indication of what failed to parse or where.

Fix

A new shared helper, getExtractExcerpt in procs/nu.js, returns the extract as an excerpt for the standard instance only when the extract contains no data-xpath attribute — exactly the complement of the case the catalog already handles. So:

  • DOM-anchored messages are unchanged: they keep their lean {ruleID, what, ordinalSeverity, count, catalogIndex} shape, with element details normalized in the catalog.
  • Unlocatable messages (CSS parse errors and other non-DOM findings) now carry their extract inline as excerpt, truncated at 400 characters (CSS extracts can be whole minified stylesheets).

Both tests/nuVal.js and tests/nuVnu.js use the helper, keeping the two engines' standardization identical.

Verification

  • node --check passes on all three files.
  • Unit assertions on the helper: CSS extract returned verbatim; data-xpath-annotated extract returns null; missing/empty extract returns null without throwing (e.g. the Nu checker's Too many messages. fatal, which has no extract); >400-char extract truncated with an ellipsis.
  • End-to-end run of the nuVal reporter with a stubbed validator response containing one CSS: Parse Error. and one ordinary HTML message:
[
  {
    "ruleID": "CSS: Parse Error.",
    "what": "CSS: Parse Error.",
    "ordinalSeverity": 3,
    "count": 1,
    "catalogIndex": "0",
    "excerpt": ".hero { colr: #fff, }"
  },
  {
    "ruleID": "Bad value  for attribute role on element div.",
    "what": "Bad value  for attribute role on element div.",
    "ordinalSeverity": 3,
    "count": 1,
    "catalogIndex": "1"
  }
]

If you would rather surface the extract on all nuVal/nuVnu instances (not only unlocatable ones), I'm happy to adjust — this version keeps report size flat for the common DOM case.

🤖 Generated with Claude Code

…fixes jrpool#38)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

Stop hiding extracts of nuVal and nuVnu tests for CSS: Parse Error rule

1 participant