Skip to content

Use json-with-comments or jsonc-parser instead of the Python standard library’s json module so that https://jsonc.org // comments in JSON don't make it trip #1196

@vorburger

Description

@vorburger

On https://github.com/enola-dev/be/blob/321123c73e2984feec3da570510b049a1795f327/.pre-commit-config.yaml :

pre-commit
check for added large files..............................................Passed
check for case conflicts.................................................Passed
check that executables have shebangs.................(no files to check)Skipped
check json...............................................................Failed
- hook id: check-json
- exit code: 1

.vscode/extensions.json: Failed to json decode (Expecting value: line 12 column 5 (char 284))
.vscode/settings.json: Failed to json decode (Expecting property name enclosed in double quotes: line 4 column 5 (char 45))

check for merge conflicts................................................Passed
check that scripts with shebangs are executable..........................Passed
check for broken symlinks............................(no files to check)Skipped
check vcs permalinks.....................................................Passed
check yaml...............................................................Passed
detect destroyed symlinks................................................Passed
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
pretty format json.......................................................Failed
- hook id: pretty-format-json
- exit code: 1

Input File .vscode/extensions.json is not a valid JSON, consider using check-json
Input File .vscode/settings.json is not a valid JSON, consider using check-json

Google (or Palantir) Java Formatter..................(no files to check)Skipped
Pretty format YAML.......................................................Passed
nixfmt-nix...........................................(no files to check)Skipped
Check .editorconfig rules................................................Passed

It's because my .vscode/extensions.json & .vscode/settings.json contain // comments, because VSC's "JSON" is really https://jsonc.org.

Perhaps the check-json and pretty-format-json could be more lenient, and allow this? It could be implemented with https://pypi.org/project/json-with-comments/ (or https://github.com/NickolaiBeloguzov/jsonc-parser, but that one seems less actively maintained; and probably not https://pypi.org/project/commentjson/, as that allows Python style # comments, which is not https://jsonc.org).

Would a PR for this be welcome? Or do you want to be completely "strict", even for this?

I'll also raise an issue at VSC about this.

The work-around is config to ignore.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions