-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Consistent, predictable json/json5 handling #24554
Comments
sounds good to me |
An alternative: allow VSCode-style JSONC for .json files: https://github.com/microsoft/node-jsonc-parser But some context: microsoft/vscode#100688 |
interesting library. maybe it allows us to migrate config files with less changes |
It's all quite a mess - there's also an argument for saying if you want JSONC then use .jsonc. I think these days we can support almost unlimited json/jsonc/json5 extensions for each file name anyway. |
export function parseJsonWithFallback(content: string): any {
let parsedJson: any;
try {
parsedJson = JSON.parse(content);
} catch (err) {
try {
parsedJson = JSON5.parse(content);
logger.warn('JSON5.parse was used to parse the JSON data. Please check your json file');
} catch (err) {
return null;
}
}
return parsedJson;
} This should work, I think. |
Yes, this looks good, although we maybe want to log if both parsing fails too |
I think throwing an error will be better, incase the content isn't parsable as that is current behaviour wherever parsing is performed. |
Sounds reasonable to require JSON in I assume that |
We should use the |
Describe the proposed change(s).
Files with extension
.json
should useJSON.parse()
, files with extension.json5
or without extension such as.renovaterc
should useJSON5.parse()
.Where we are allowing JSON5 for
.json
files today, we should change so that we warn if a.json
file parses with JSON5 but not with JSON.Then after sufficient time has passed, perhaps 2 major releases, we should remove JSON5 parsing of
.json
files, which will result in a Config Validation error.We should do the same with presets too.
The text was updated successfully, but these errors were encountered: