Skip to content

feat(config)!: support jsonc in existing config + preset files - #36141

Merged
rarkins merged 9 commits into
renovatebot:mainfrom
RahulGautamSingh:feat-29535
Jun 19, 2025
Merged

rarkins merged 9 commits into
renovatebot:mainfrom
RahulGautamSingh:feat-29535

Conversation

@RahulGautamSingh

Copy link
Copy Markdown
Collaborator

Changes

  • If json parsing fails, fallback to jsonc parsing and then to json5. There, is no waya tobe sure which format json | jsonc | json5 is present in a file before parsing it.

Context

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@rarkins rarkins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer we just parse with JSONC instead of JSON.parse

@RahulGautamSingh
RahulGautamSingh requested a review from rarkins May 28, 2025 16:10
Comment thread lib/util/common.ts Resolved
@rarkins rarkins changed the title feat(config): support jsonc in config + preset files feat(config)!: support jsonc in config + preset files May 29, 2025
@rarkins rarkins added the breaking Breaking change, requires major version bump label May 29, 2025
@rarkins

rarkins commented May 29, 2025

Copy link
Copy Markdown
Contributor

I don't think this is technically a breaking change, but it's a very notable one so let's include it in v41 so there's a higher chance everyone notices.

@rarkins rarkins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely needs some docs updating!

@RahulGautamSingh

Copy link
Copy Markdown
Collaborator Author

Definitely needs some docs updating!

Where should it be added?

@rarkins

rarkins commented Jun 1, 2025

Copy link
Copy Markdown
Contributor

Probably a few places where we mention coding file types. Alone should recommend using jsonc instead of json5

@reduckted

Copy link
Copy Markdown
Contributor

Is there any chance of .jsonc being added as a valid file extension for Renovate configs here?:

export const configFileNames = [
'renovate.json',
'renovate.json5',
'.github/renovate.json',
'.github/renovate.json5',
'.gitlab/renovate.json',
'.gitlab/renovate.json5',
'.renovaterc',
'.renovaterc.json',
'.renovaterc.json5',
'package.json',
];

@rarkins
rarkins requested review from secustor and viceice June 4, 2025 11:12
viceice
viceice previously approved these changes Jun 4, 2025

@viceice viceice left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really a breaking change?

@viceice viceice added this to the v41 milestone Jun 4, 2025
@RahulGautamSingh
RahulGautamSingh requested a review from rarkins June 4, 2025 23:49
Comment thread docs/usage/config-presets.md Resolved
@rarkins

rarkins commented Jun 5, 2025

Copy link
Copy Markdown
Contributor

@viceice I think it's strictly not a breaking change, but it's a significant one that I'd like to bundle in a major release note so increase the chance of getting more attention. I'd like to recommend jsonc instead of json5 too in future (because we can more easily write migration code)

secustor
secustor previously approved these changes Jun 5, 2025
@rarkins
rarkins requested a review from viceice June 7, 2025 06:42

@viceice viceice left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise LGTM

Comment thread lib/util/common.spec.ts Resolved
@reduckted

Copy link
Copy Markdown
Contributor

Just repeating this in case it was missed:

Is there any chance of .jsonc being added as a valid file extension for Renovate configs here?:

export const configFileNames = [
'renovate.json',
'renovate.json5',
'.github/renovate.json',
'.github/renovate.json5',
'.gitlab/renovate.json',
'.gitlab/renovate.json5',
'.renovaterc',
'.renovaterc.json',
'.renovaterc.json5',
'package.json',
];

VS Code treats a .json file as strictly JSON, so it does not allow comments.
image

To get rid of those errors, I can rename the file to renovate.jsonc, but then (unless I've misunderstood something) Renovate won't automatically find it.

@rarkins

rarkins commented Jun 16, 2025

Copy link
Copy Markdown
Contributor

@reduckted it's not necessary to add in v41.0.0 as it would be a new capability instead of something changed about existing functionality

@RahulGautamSingh
RahulGautamSingh requested review from rarkins, secustor and viceice and removed request for rarkins June 16, 2025 17:21
@reduckted

Copy link
Copy Markdown
Contributor

@reduckted it's not necessary to add in v41.0.0 as it would be a new capability instead of something changed about existing functionality

I don't understand what you mean. What a the point of supporting .jsonc files if Renovate won't automatically find them?

@rarkins

rarkins commented Jun 17, 2025

Copy link
Copy Markdown
Contributor

This not about supporting .jsonc files. It's about using JSONC parsing instead of JSON parsing for JSON files

@karlhorky

karlhorky commented Jun 17, 2025 •

Copy link
Copy Markdown
Contributor

I don't understand what you mean. What a the point of supporting .jsonc files if Renovate won't automatically find them?

This not about supporting .jsonc files. It's about using JSONC parsing instead of JSON parsing for JSON files

Interesting, why would Renovate support the JSONC syntax without supporting the .jsonc file extension?

Seems like that's probably confusing and has bad DX, eg. editors showing errors in the file, other tooling which expects strict JSON in .json files, etc.

I can understand it for "any config files without file extension (e.g. .renovaterc)" mentioned in #29535, but supporting it for .json files seems anti-interop.

@reduckted

Copy link
Copy Markdown
Contributor

Seems like that's probably confusing and has bad DX

Totally agree. I know the issue says "Renovate should support JSONC for .json files", but if I didn't know this and I see that Renovate supports JSONC syntax and then I get error highlighting in my .json file, then I'm very likely going to change the file extension to .jsonc.

I assume that at some point in the future you're going to support .jsonc files, but why not do it as part of this change? It's only four lines that need to be added to that array and it's done, right?

@rarkins rarkins changed the title feat(config)!: support jsonc in config + preset files feat(config)!: support jsonc in existing config + preset files Jun 17, 2025
@rarkins

rarkins commented Jun 17, 2025

Copy link
Copy Markdown
Contributor

We do not want to change more than is necessary in this PR. You're welcome to submit a PR after v41 which adds .jsonc support.

@rarkins
rarkins merged commit 8c7e931 into renovatebot:main Jun 19, 2025
@Erwan-loot Erwan-loot mentioned this pull request Jun 20, 2025
1 of 6 tasks
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

audience:user breaking Breaking change, requires major version bump bucket:predictability rough-edge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support jsonc syntax for JSON config and preset files

7 participants