Skip to content

Commit

Permalink
yamlfmt: hidden version of config file with ext (#164)
Browse files Browse the repository at this point in the history
This PR allows for the yamlfmt config file to be hidden if it has an
extension.
  • Loading branch information
braydonk authored Mar 8, 2024
1 parent 152168a commit e713bb3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 6 additions & 4 deletions cmd/yamlfmt/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (
)

var configFileNames = collections.Set[string]{
".yamlfmt": {},
"yamlfmt.yml": {},
"yamlfmt.yaml": {},
".yamlfmt": {},
".yamlfmt.yml": {},
".yamlfmt.yaml": {},
"yamlfmt.yml": {},
"yamlfmt.yaml": {},
}

const configHomeDir string = "yamlfmt"
Expand Down Expand Up @@ -119,7 +121,7 @@ func getConfigPathFromFlag() (string, error) {
logger.Debug(logger.DebugCodeConfig, "Using config path %s from -conf flag", configPath)
return configPath, validatePath(configPath)
}

logger.Debug(logger.DebugCodeConfig, "No config path specified in -conf")
return configPath, errNoConfFlag
}
Expand Down
13 changes: 11 additions & 2 deletions docs/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

## Config File Discovery

The config file is a file named `.yamlfmt`, `yamlfmt.yaml`, or `yamlfmt.yml` that contains a valid yamlfmt configuration. The config file is discovered in the following priority order:
The config file is a file is a yaml file that contains a valid yamlfmt configuration. yamlfmt will automatically search for files with the following names:

- `.yamlfmt`
- `yamlfmt.yml`
- `yamlfmt.yaml`
- `.yamlfmt.yaml`
- `.yamlfmt.yml`

You can also pass a config file to yamlfmt using the `-conf` flag. When using the `-conf` flag, the config file can be named anything.
When not using one of the config file flags, it will be automatically discovered in the following priority order:

1. Specified in the `-conf` flag (if this is an invalid path or doesn't exist, the tool will fail)
1. A config file in the current working directory
Expand All @@ -15,7 +24,7 @@ If none of these are found, the tool's default configuration will be used.

If the flag `-global_conf` is passed, all other steps will be circumvented and the config file will be discovered from the system config directory. See [the command line flag docs](./command-usage.md#configuration-flags).

In the `-conf` flag, the config file will be named anything. As long as it's valid yaml, yamlfmt will read it as a config file. This can be useful for applying unique configs to different directories in a project. The automatic discovery paths do need to use one of the known names.
In the `-conf` flag, the config file can be named anything. As long as it's valid yaml, yamlfmt will read it as a config file. This can be useful for applying unique configs to different directories in a project. The automatic discovery paths do need to use one of the known names.

## Command

Expand Down

0 comments on commit e713bb3

Please sign in to comment.