feat: Add allowTrailingCommas option for JSONC #42
+150
−6
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.
Prerequisites checklist
What is the purpose of this pull request?
Add support for trailing commas to the JSONC language.
What changes did you make? (Give an overview)
This pull request introduces support for allowing trailing commas in JSONC files and includes several updates to the codebase and documentation to reflect this new feature. The most important changes include adding a new option to enable trailing commas, updating the
JSONLanguage
class to validate and handle this option, and adding tests to ensure the feature works as expected.New Feature: Allow Trailing Commas in JSONC
allowTrailingCommas
language option.Code Updates
src/languages/json-language.js
:JSONLanguageOptions
to include theallowTrailingCommas
property.validateLanguageOptions
method to check for theallowTrailingCommas
option and ensure it is only used in JSONC mode.parse
method to accept and handle theallowTrailingCommas
option.Dependency Update
@humanwhocodes/momoa
dependency to version^3.3.0
.Tests
tests/languages/json-language.test.js
:validateLanguageOptions
method to ensure it correctly handles theallowTrailingCommas
option.parse
method to verify that trailing commas are correctly parsed or rejected based on theallowTrailingCommas
option.Related Issues
fixes #41
Is there anything you'd like reviewers to focus on?
Right now,
validateLanguageOptions()
throws an error when it findsallowTrailingCommas
in JSON mode (where it cannot be enabled) and JSON5 mode (where it cannot be disabled). Would it be better to check the value ofallowTrailingCommas
before deciding to throw an error? So in JSON mode it would only throw ifallowTrailingCommas
istrue
and in JSON5 mode it would only throw an error ifallowTrailingCommas
isfalse
?