Repository navigation
Report hex colors of invalid length with hexColorLength - #580
Open
Usman Tahir Qureshi (UsmanQT) wants to merge 1 commit into
Open
Usman Tahir Qureshi (UsmanQT) wants to merge 1 commit into
Usman Tahir Qureshi (UsmanQT) wants to merge 1 commit into
Conversation
`_parseHexColor` only accepted hashes with 3, 4, 6 or 8 hex digits, so a value like `microsoft#12` was never a HexColorValue. CSS and SCSS reported generic parse errors instead, LESS reported nothing, and the hexColorLength lint rule could never fire. Accept any `#` followed by hex digits as a hex color and let the lint rule report the invalid lengths. `colorFromHex` already returns null for those, so no color decorator is shown for them. Fixes microsoft/vscode#81808 Co-Authored-By: Claude <noreply@anthropic.com>
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.
Fixes microsoft/vscode#81808
The
css.lint.hexColorLengthrule (and its SCSS/LESS counterparts) never fires, because a hex color with an invalid number of digits never reaches the linter.at-rule or selector expectedandproperty value expected. LESS reports nothing.Hex colors must consist of three, four, six or eight hex numbers(hexColorLength) on#12.Cause
_parseHexColoronly accepted hash tokens with exactly 3, 4, 6 or 8 hex digits. Any other length was not parsed as aHexColorValue, soLintVisitor.visitHexColorValuenever saw it.Change
_parseHexColornow accepts any#followed by hex digits, as suggested in the issue, and the existing lint rule reports the invalid lengths. Hashes with non-hex characters (e.g.#12Y) are still not hex colors.I checked the other consumers of
HexColorValue:colorFromHexalready returnsnullfor lengths other than 4/5/7/9, sofindDocumentColorsshows no color decorator for invalid values, and the completion collectors only reuse the node text.Tests
parser.test.ts(hexcolor): hex colors with 1, 2, 5 and 9 digits parse as hex colors,#FFGdoes not, anda { color: #12; }parses without errors.lint.test.ts(newhex color length): valid lengths produce no entry, and invalid lengths producehexColorLengthfor the CSS, SCSS and LESS parsers.cssParser.tsand pass with it.npm test(compile, lint and tests): 423 passing, 0 failing.🤖 Generated with Claude Code