[GH-ISSUE #687] "Cannot read or parse config file" using .jsonc with comments #2357

Closed
opened 2026-03-07 20:07:01 +03:00 by kerem · 2 comments
Owner

Originally created by @aguynamedben on GitHub (Dec 21, 2022).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/687

Hi, I'm new to this library and think I've found a bug where parsing the .jsonc config file breaks if comments are present in the .jsonc file.

If .markdownlint.jsonc is:

// wat
{
  "MD024": {
    "siblings_only": true,
  },
}

I get

Cannot read or parse config file '.markdownlint.jsonc': Unable to parse '.markdownlint.jsonc'; Parser 0: Unexpected token } in JSON at position 45; Parser 1: end of the stream or a document separator is expected (3:10)
image

but if comments are removed from .markdownlint.jsonc, and it's

{
  "MD024": {
    "siblings_only": true,
  },
}

Things work as expected, without the JSON parsing error
image

Isn't the whole point of .jsonc to allow comments?

Versions:
image

Originally created by @aguynamedben on GitHub (Dec 21, 2022). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/687 Hi, I'm new to this library and think I've found a bug where parsing the .jsonc config file breaks if comments are present in the .jsonc file. If .markdownlint.jsonc is: ```jsonc // wat { "MD024": { "siblings_only": true, }, } ``` I get ``` Cannot read or parse config file '.markdownlint.jsonc': Unable to parse '.markdownlint.jsonc'; Parser 0: Unexpected token } in JSON at position 45; Parser 1: end of the stream or a document separator is expected (3:10) ``` <img width="1778" alt="image" src="https://user-images.githubusercontent.com/107841/208996323-fce65246-cc2a-449c-ba1d-f8698a5c22af.png"> but if comments are removed from .markdownlint.jsonc, and it's ```jsonc { "MD024": { "siblings_only": true, }, } ``` Things work as expected, without the JSON parsing error <img width="1148" alt="image" src="https://user-images.githubusercontent.com/107841/208996522-e5f3a659-a929-4f73-abdb-32d0cf2f1862.png"> Isn't the whole point of .jsonc to allow comments? Versions: <img width="971" alt="image" src="https://user-images.githubusercontent.com/107841/208996779-ef7c2046-9651-490f-939c-44d1368e424a.png">
kerem closed this issue 2026-03-07 20:07:01 +03:00
Author
Owner

@aguynamedben commented on GitHub (Dec 21, 2022):

Hmm... okay the problem seems to be the trailing commas. This works:

{
  // MD024/no-duplicate-heading/no-duplicate-header - Multiple headings with the same content
  "MD024": {
    // Only check sibling headings
    "siblings_only": true
  }
}

I still find the output surprising. Trailing commas cause a seemingly "bad lint result" instead of just a "couldn't lint because your config file isn't right!" message. Maybe an improvement would be to just stop altogether if the config file isn't parsed correctly. Right now it seems to attempt to continue and dump a bunch of output to stdout. I'd be less surprised if the parsing just stopped at the JSON parse problem.

<!-- gh-comment-id:1362060271 --> @aguynamedben commented on GitHub (Dec 21, 2022): Hmm... okay the problem seems to be the trailing commas. This works: ```json { // MD024/no-duplicate-heading/no-duplicate-header - Multiple headings with the same content "MD024": { // Only check sibling headings "siblings_only": true } } ``` I still find the output surprising. Trailing commas cause a seemingly "bad lint result" instead of just a "couldn't lint because your config file isn't right!" message. Maybe an improvement would be to just stop altogether if the config file isn't parsed correctly. Right now it seems to attempt to continue and dump a bunch of output to stdout. I'd be less surprised if the parsing just stopped at the JSON parse problem.
Author
Owner

@DavidAnson commented on GitHub (Dec 22, 2022):

As you note, the original example was invalid due to the trailing comma. For the unexpected CLI behavior, please open an issue in the corresponding repo if there isn't already something relevant: https://github.com/igorshubovych/markdownlint-cli

<!-- gh-comment-id:1362242119 --> @DavidAnson commented on GitHub (Dec 22, 2022): As you note, the original example was invalid due to the trailing comma. For the unexpected CLI behavior, please open an issue in the corresponding repo if there isn't already something relevant: https://github.com/igorshubovych/markdownlint-cli
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#2357
No description provided.