Skip to content

Fix YAML slash comments with colons - #1278

Merged
alecthomas merged 1 commit into
alecthomas:masterfrom
cyphercodes:fix-yaml-slash-comments-1271
May 30, 2026
Merged

alecthomas merged 1 commit into
alecthomas:masterfrom
cyphercodes:fix-yaml-slash-comments-1271

Conversation

@cyphercodes

Copy link
Copy Markdown
Contributor

Fixes #1271.

Summary

  • Treat // inline comment text as Comment in YAML highlighting.
  • Keep key matching from running through // comment text before a later colon.
  • Add YAML lexer fixture coverage for // comments with colon text.

Tests

  • PATH=/root/sdk/go1.26.2/bin:$PATH go test ./lexers -run 'TestLexers/YAML' -count=1
  • PATH=/root/sdk/go1.26.2/bin:$PATH go test ./... -count=1
  • git diff --check

@alecthomas
alecthomas enabled auto-merge (squash) May 30, 2026 04:24
@alecthomas
alecthomas merged commit e10d532 into alecthomas:master May 30, 2026
2 checks passed
@alecthomas

Copy link
Copy Markdown
Owner

Thanks!

alecthomas pushed a commit that referenced this pull request Oct 16, 2026
Addresses #1333.

YAML uses `#` for comments ([YAML 1.2.2
§6.6](https://yaml.org/spec/1.2.2/#66-comments)). The `//` rules added
in #1278 instead consume valid plain scalars and prevent
slash-containing keys from matching:

```yaml
path: //server/share
proto: //cdn.example.com/lib.js
text: prefix // suffix
//key: value
```

Remove both slash-comment rules and their exclusions in the key
patterns. Keep the `#` exclusions from #1289 and leave the numeric
changes in #1372 separate.

The fixture replaces the invalid trailing-`//` comment examples with
valid quoted strings, plain scalars, keys, sequence items, and a real
`#` comment containing a colon. The new expectations fail with the
original lexer and pass with this change.

### Validation

Using the repository's Hermit toolchain (Go 1.26.6):

- `go test -count=1 ./...`
- `go test -race -count=1 ./...`
- `just check-generated` — no generated changes
- `golangci-lint run`
- `git diff --check`

Also checked actual CLI output for 25 parser-valid examples: 14
regressions are corrected and 11 controls are unchanged. HTML output
keeps real hash comments while rendering slash values and keys with
their scalar/key classes.

An additional plain `go vet ./...` check reports the same existing
unkeyed-composite diagnostics on master and this branch; the
repository-configured lint passes. No Go source or dependency files are
changed.
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.

Fix highlight for YAML inline comments with a colon

2 participants

⌂ 换网址