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

feat: predictible json/json5 handling #24612

Merged

Conversation

RahulGautamSingh
Copy link
Collaborator

@RahulGautamSingh RahulGautamSingh commented Sep 23, 2023

Changes

  • Instead of parsing json file with JSON5.parse, first try and parse the file with JSON.parse
  • If the file is not parsable by JSON.parse try parsing with JSON5.parse and if parsed, log a warning message for the user to notify of the inconsistent behaviour
  • If json file isn't parsed by JSON5.parse as well, throw an error

Context

Closes: #24554

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

lib/config/presets/util.ts Outdated Show resolved Hide resolved
lib/util/common.ts Outdated Show resolved Hide resolved
lib/util/common.ts Outdated Show resolved Hide resolved
lib/config/presets/gitea/index.ts Outdated Show resolved Hide resolved
lib/modules/platform/azure/index.ts Outdated Show resolved Hide resolved
@rarkins rarkins changed the title feat: predectible json/json5 handling feat: predictible json/json5 handling Sep 27, 2023
lib/util/common.ts Outdated Show resolved Hide resolved
lib/util/common.ts Outdated Show resolved Hide resolved
Co-authored-by: Rhys Arkins <rhys@arkins.net>
lib/modules/platform/gitea/index.ts Show resolved Hide resolved
lib/modules/platform/gitea/index.ts Outdated Show resolved Hide resolved
lib/modules/platform/github/index.ts Show resolved Hide resolved
lib/modules/platform/github/index.ts Outdated Show resolved Hide resolved
lib/modules/platform/gitlab/index.ts Show resolved Hide resolved
lib/modules/platform/gitlab/index.ts Outdated Show resolved Hide resolved
lib/util/common.ts Outdated Show resolved Hide resolved
lib/util/common.ts Show resolved Hide resolved
lib/util/common.ts Show resolved Hide resolved
@RahulGautamSingh

This comment was marked as outdated.

viceice
viceice previously approved these changes Oct 24, 2023
@viceice viceice added this pull request to the merge queue Nov 6, 2023
Merged via the queue into renovatebot:main with commit 4231b1a Nov 6, 2023
36 checks passed
@renovate-release
Copy link
Collaborator

🎉 This PR is included in version 37.48.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

parsedJson = JSON5.parse(content);
logger.warn(
{ context },
'File contents are invalid JSON but parse using JSON5. Support for this will be removed in a future release so please change to a support .json5 file name or ensure correct JSON syntax.'
Copy link
Collaborator

Choose a reason for hiding this comment

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

This log message is a bit confusing. How about something like this:

File contents are invalid JSON but parse corectly as JSON5. In a future release, Renovate will strictly parse JSON as JSON, and JSON5 as JSON5. To prevent breaking your Renovate config in a upcoming major release: please make sure the file extension matches the content syntax.

In any case, we should be clear about:

  • Current behavior (Renovate silently eats wrong file format)
  • Upcoming behavior (Renovate will parse strictly according to file extension)
  • What the user most do to prevent future breakage (make sure file extension matches file content syntax)

jon4hz pushed a commit to jon4hz/renovate that referenced this pull request Nov 9, 2023
Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consistent, predictable json/json5 handling
5 participants