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

yamlfmt: hidden version of config file with ext #164

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading