Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip comments before parsing JSON config files #10

Merged
merged 1 commit into from
Dec 30, 2023
Merged

Conversation

mbland
Copy link
Owner

@mbland mbland commented Dec 30, 2023

Also contains minor tweaks to analyzeArgv() and adds comments to the JSON files under test/fixtures/analyzeArgv. Added a new "Development" section to README.md including instructions on configuring Vim, Visual Studio Code, and IntelliJ IDEA to recognize JSON comments.

From the function comment for the new stripJsonComments():

Replaces rather than removes characters so that any JSON.parse() errors line up with the original. Preserves all existing whitespace as is, including newlines, carriage returns, and horizontal tabs.

This function is necessary because the jsdoc command depends upon the extremely popular strip-json-comments npm. Otherwise analyzeArgs() would choke on config.json files containing comments.

This implementation was inspired by strip-json-comments, but is a completely original implementation to avoid adding any dependencies. It may become its own separate package one day, likely scoped to avoid conflicts with strip-json-comments.

Also contains minor tweaks to analyzeArgv() and adds comments to the
JSON files under test/fixtures/analyzeArgv. Added a new "Development"
section to README.md including instructions on configuring Vim, Visual
Studio Code, and IntelliJ IDEA to recognize JSON comments.

From the function comment for the new stripJsonComments():

Replaces rather than removes characters so that any JSON.parse() errors
line up with the original. Preserves all existing whitespace as is,
including newlines, carriage returns, and horizontal tabs.

This function is necessary because the `jsdoc` command depends upon the
extremely popular strip-json-comments npm. Otherwise analyzeArgs() would
choke on config.json files containing comments.

This implementation was inspired by strip-json-comments, but is a
completely original implementation to avoid adding any dependencies. It
may become its own separate package one day, likely scoped to avoid
conflicts with strip-json-comments.
@mbland mbland self-assigned this Dec 30, 2023
@coveralls
Copy link

Pull Request Test Coverage Report for Build 7362155295

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 7359274828: 0.0%
Covered Lines: 248
Relevant Lines: 248

💛 - Coveralls

@mbland mbland merged commit 9763aa7 into main Dec 30, 2023
3 checks passed
@mbland mbland deleted the strip-json-comments branch December 30, 2023 05:00
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.

2 participants