Repository navigation
support allowComments & allowTrailingCommas - #179
Conversation
Use the annotations getAnnotations returns instead of rebuilding them, merge the duplicate trailing comma loops, and type the diagnostics. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only the root schema and the subschemas it always applies (allOf, $ref) can allow comments or trailing commas, and any of them setting true is enough. Conditional subschemas (anyOf, oneOf, if/then/else) are ignored even when they match. A comma with no value before it is still an error when trailing commas are allowed. These tests fail until the provider and parser are updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jdesrosiers
left a comment
There was a problem hiding this comment.
Thanks! I pushed two commits: a cleanup of the provider and seven tests that fail until the two issues below are fixed.
To match vscode, only the root schema and the subschemas it always applies (allOf, $ref) should be counted. anyOf, oneOf and if/then/else are ignored even when they match. If the keyword is applied multiple times, any true enables the rule.
[,] and {,} should be considered missing values, not trailing commas, so allowTrailingCommas shouldn't hide them. parseComma should report value-expected. The two "comma-only" tests in parse.test.ts will need updating.
…ding value-expected code
|
Great catches @jdesrosiers ! The CI failed on macos and it's a timeout, Could you re-run this one please? |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The parser no longer reports trailing-comma or comment-not-allowed, so the JSONC provider looks up its messages directly instead of building fake syntax errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Annotation accessors return plain booleans, and the schema isn't validated when there are no comments or trailing commas to report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jdesrosiers
left a comment
There was a problem hiding this comment.
Thanks for the fixes! I pushed a few cleanup commits:
- Removed a duplicate unclosed-comment test and renamed the comma-only tests to say "on the bracket", which is where the error is reported.
skipCommentnow goes throughreportScanError, so unclosed comments are handled in one place.- Added a named
Spantype for comments and trailing commas. - Moved the
trailing-commaandcomment-not-allowedmessages out of the parser'sSyntaxErrorCode. The parser no longer produces them, so the provider uses a newLocalization.getMessage()instead of building fake syntax errors. allowComments()andallowTrailingCommas()now return plain booleans. The provider also skips schema validation when there are no comments or trailing commas to report.- Added support for VS Code's deprecated
allowsTrailingCommasspelling.
I need to correct my last review. I said "any true enables the rule" matches VS Code, but it doesn't. VS Code uses the first boolean it finds: the root first, then allOf in order, with a $ref'd schema taking precedence over its siblings. We're keeping "any true wins" anyway, because matching VS Code would need annotations in order. The current implementation and tests are what we want.
Added support for
allowCommentsandallowTrailingCommas.Comments and trailing commas are now collected by the parser and reported by
JsoncDiagnosticsProviderinstead of as syntax errors. By default, they're errors in.jsonfiles and ignored/warnings in.jsoncfiles. SettingallowComments: trueorallowTrailingCommas: truein the schema suppresses them, while false does not override the defaults. Works through$refandallOf.Closes #169