feat: add bare attribute and empty-value diagnostics#273
Merged
Conversation
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.
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.
Summary
empty-attribute-valuediagnostic (Phase 1, always runs) forkey=with no value after=, with quick fix to insertkey="".schema-bare-attributediagnostic (Phase 2, schema-dependent) for bare words like{key}that match a known schema attribute name but lack=value.findEmptyValueAssignmentsscanner,extractBareWordshelper, and wire both intovalidateDocument,validateElementBlock, andvalidateShortcodeBlock.addFixActionshelper for quick fixes.Test plan
npm run test-compilecompiles without errors.npm run testpasses (370 passing; 10 pre-existing failures in Activate Utils unrelated to this change).npm run lintpasses with no warnings..qmdfile with a shortcode schema installed and verify{key},{key=},{key=""},{key="value"}, and{key = value}produce the expected diagnostics.