fix(config): support jsonc

This commit is contained in:
Jan De Dobbeleer 2024-03-11 18:00:50 +01:00 committed by Jan De Dobbeleer
parent 414581cf68
commit 9686b32ffa

View file

@ -132,7 +132,6 @@ func loadConfig(env platform.Environment) *Config {
cfg.Format = strings.TrimPrefix(filepath.Ext(configFile), ".")
cfg.env = env
// read the data
data, err := os.ReadFile(configFile)
if err != nil {
env.DebugF("error reading config file: %s", err)
@ -144,13 +143,13 @@ func loadConfig(env platform.Environment) *Config {
cfg.Format = YAML
err = yaml.Unmarshal(data, &cfg)
case "jsonc", "json":
cfg.Format = JSON
if cfg.Format == "jsonc" {
str := jsonutil.StripComments(string(data))
data = []byte(str)
}
cfg.Format = JSON
decoder := json.NewDecoder(bytes.NewReader(data))
err = decoder.Decode(&cfg)
case "toml", "tml":