Skip to content

feat: add bare attribute and empty-value diagnostics#273

Merged
mcanouil merged 5 commits intomainfrom
feat/bare-empty-attribute-diagnostics
Feb 18, 2026
Merged

feat: add bare attribute and empty-value diagnostics#273
mcanouil merged 5 commits intomainfrom
feat/bare-empty-attribute-diagnostics

Conversation

@mcanouil
Copy link
Copy Markdown
Owner

@mcanouil mcanouil commented Feb 18, 2026

Summary

  • Add empty-attribute-value diagnostic (Phase 1, always runs) for key= with no value after =, with quick fix to insert key="".
  • Add schema-bare-attribute diagnostic (Phase 2, schema-dependent) for bare words like {key} that match a known schema attribute name but lack =value.
  • Add findEmptyValueAssignments scanner, extractBareWords helper, and wire both into validateDocument, validateElementBlock, and validateShortcodeBlock.
  • Extend code action provider with a unified addFixActions helper for quick fixes.

Test plan

  • npm run test-compile compiles without errors.
  • npm run test passes (370 passing; 10 pre-existing failures in Activate Utils unrelated to this change).
  • npm run lint passes with no warnings.
  • 3 rounds of iterative code review (converged at round 3 with zero findings).
  • Manual: open a .qmd file with a shortcode schema installed and verify {key}, {key=}, {key=""}, {key="value"}, and {key = value} produce the expected diagnostics.

Detect two new patterns in inline attribute blocks and shortcodes:

- `{key=}` where `=` is present but no value follows (Phase 1
  diagnostic with quick fix to insert `key=""`).
- `{key}` where a bare word matches a known schema attribute name
  (Phase 2 diagnostic suggesting `key="value"`).

Add `findEmptyValueAssignments` scanner, `extractBareWords` and
`findBareWordOffset` helpers, wire both into `validateDocument`,
`validateElementBlock`, and `validateShortcodeBlock`, and extend the
code action provider to offer a quick fix for empty-value assignments.
Round 1 review fixes:

- Widen tab handling in findEmptyValueAssignments backward/forward
  scan from space-only to /[ \t]/, preventing false positives on
  tab-separated attribute content.
- Remove dead `}` guard from the empty-value condition (block.content
  never contains closing braces).
- Guard lone `.`/`#` in extractBareWords so they do not consume the
  next word as a class/id prefix.
- Filter bare `-` tokens that are not valid attribute names.
- Extract common addFixActions helper from duplicate code action
  methods.
- Rename DIAGNOSTIC_CODE to SPACES_AROUND_EQUALS_CODE for clarity.
- Merge Phase 1 and Phase 1b into a single block-iteration loop.
- Fix misleading test name and remove dead-code test.
- Remove unused findBareWordOffset export and its test suite.
- Restore dynamic quick-fix title for empty-value actions (shows
  "Replace with key=\"\"" instead of static label).
- Hoist document.getText() and extractBlocks() outside the per-
  diagnostic loop in provideCodeActions.
- Add JSDoc note that extractBlocks strips delimiters before calling
  findEmptyValueAssignments (no `}` special-casing needed).
- Fix misleading test comment about findSpacesAroundEquals.
- Add tests for tab-before-equals in findEmptyValueAssignments.
@mcanouil mcanouil added the Type: Enhancement 💡 Issues related to enhancements, improvements, new features, or new analyses label Feb 18, 2026
@mcanouil mcanouil self-assigned this Feb 18, 2026
@mcanouil mcanouil enabled auto-merge (squash) February 18, 2026 15:57
@mcanouil mcanouil merged commit 0b9803f into main Feb 18, 2026
7 checks passed
@mcanouil mcanouil deleted the feat/bare-empty-attribute-diagnostics branch February 18, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Enhancement 💡 Issues related to enhancements, improvements, new features, or new analyses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant