Permit .json and .ini suffixes on config files
Ghnuberath opened this issue ยท 6 comments
rc
is awesome!
It's a tiny thing, but it would be great if the config file logic would permit .json
and .ini
extensions. In other words, looking for .${appname}rc
, .${appname}rc.json
or .${appname}rc.ini
in all the usual places.
Definitely helps with triggering syntax highlighting in your editor of choice.
This idea was mentioned in #71, but since the scope of this feature request is far smaller in scope, I've opened it as a separate issue.
It would be nice if YAML is supported as well - just like with .eslintrc
!
I think file extentions is reasonable. I do not want to add yaml, but you can already use a custom parser (see the docs) already.
Currently, rc
will attempt to parse .{appname}rc
as both ini
and json
but if we have a .json file in ini format should be an error, obviously.
Perhaps the way to do this would be to put an object {ini: INI.parse, json: JSON.parse, yml: YAML.parse}
in the place of the custom parser, and that will try exactly those extentions, with those parsers. Then you can have yaml. If you want only one parser (which is reasonable) then use only one.
Looking back I think that parsing one file as a variety of formats was a mistake. And the worst part, is I don't even know how many people are using ini! but I would if you had to explicitly set it, because I'd be able to look at the code of modules that depend on rc
. principle 2. explicit is better than implicit
if you want to have backwards support for a default parser, use empty string as a key: {"": function (str) { try { return JSON.parse(str) } catch (_) { return INI.parse(str) } }}
(we'd have to handle that case specially, without adding the .
but that would give us backwards compat.
I made a pull request for the solution you were talking about @dominictarr, #85.
Since this has appeared inactive, I have rewritten this module from the ground up as my own rc2. The loaders are fully configurable, and asynchronous. I plan on maintaining this module and reviewing PRs as well.
Hey @dominictarr, how are this issue and #85 PR going?
It should accept the file extensions for syntax highlighting or LSPs.