From 4ec4c803a06111dd3cae8d8d9db14e7aa8077af8 Mon Sep 17 00:00:00 2001 From: jdkato Date: Sun, 17 Dec 2023 15:55:52 -0800 Subject: [PATCH] feat: new `StylesPath/config` directory --- internal/core/config.go | 20 +++++++++++++++++++ internal/core/util.go | 5 +++-- .../vocabularies}/Base/accept.txt | 0 .../vocabularies}/Base/reject.txt | 0 .../styles/{ => config/ignorefiles}/vocab.txt | 0 .../vocabularies}/Basic/accept.txt | 0 .../vocabularies}/Basic/reject.txt | 0 .../vocabularies}/Second/accept.txt | 0 .../vocabularies}/Second/reject.txt | 0 .../vocabularies}/Cap/accept.txt | 0 .../vocabularies}/Cap/reject.txt | 0 11 files changed, 23 insertions(+), 2 deletions(-) rename testdata/fixtures/fragments/styles/{Vocab => config/vocabularies}/Base/accept.txt (100%) rename testdata/fixtures/fragments/styles/{Vocab => config/vocabularies}/Base/reject.txt (100%) rename testdata/fixtures/vocab/styles/{ => config/ignorefiles}/vocab.txt (100%) rename testdata/fixtures/vocab/styles/{Vocab => config/vocabularies}/Basic/accept.txt (100%) rename testdata/fixtures/vocab/styles/{Vocab => config/vocabularies}/Basic/reject.txt (100%) rename testdata/fixtures/vocab/styles/{Vocab => config/vocabularies}/Second/accept.txt (100%) rename testdata/fixtures/vocab/styles/{Vocab => config/vocabularies}/Second/reject.txt (100%) rename testdata/styles/{Vocab => config/vocabularies}/Cap/accept.txt (100%) rename testdata/styles/{Vocab => config/vocabularies}/Cap/reject.txt (100%) diff --git a/internal/core/config.go b/internal/core/config.go index 3f1bd195..98518a38 100644 --- a/internal/core/config.go +++ b/internal/core/config.go @@ -12,6 +12,26 @@ import ( "github.com/errata-ai/vale/v2/internal/glob" ) +var ( + // ConfigDir is the default location for Vale's configuration files. + // + // This was introduced in v3.0.0 as a means of standardizing the location + // of Vale's configuration files. + // + // This directory is relative to the user's specified `StylesPath`, which + // can be set via the `--config` flag, the `VALE_CONFIG_PATH` environment + // variable, or the default search process. + // + // NOTE: The config pipeline is stored in the top-level `.config` + // directory. See `cmd/vale/sync.go`. + ConfigDir = "config" + + VocabDir = filepath.Join(ConfigDir, "vocabularies") + DictDir = filepath.Join(ConfigDir, "dictionaries") + TmplDir = filepath.Join(ConfigDir, "templates") + IgnoreDir = filepath.Join(ConfigDir, "ignorefiles") +) + // CLIFlags holds the values that are defined at runtime by the user. // // For example, `vale --minAlertLevel=error`. diff --git a/internal/core/util.go b/internal/core/util.go index 13ba4704..e2c17e26 100755 --- a/internal/core/util.go +++ b/internal/core/util.go @@ -288,7 +288,7 @@ func validateLevel(key, val string, cfg *Config) bool { func loadVocab(root string, cfg *Config) error { target := "" for _, p := range cfg.Paths { - opt := filepath.Join(p, "Vocab", root) + opt := filepath.Join(p, VocabDir, root) if IsDir(opt) { target = opt break @@ -296,7 +296,8 @@ func loadVocab(root string, cfg *Config) error { } if target == "" { - return NewE100("vocab", fmt.Errorf("'%s' does not exist", root)) + return NewE100("vocab", fmt.Errorf( + "The '%s/%s' directory does not exist", VocabDir, root)) } err := godirwalk.Walk(target, &godirwalk.Options{ diff --git a/testdata/fixtures/fragments/styles/Vocab/Base/accept.txt b/testdata/fixtures/fragments/styles/config/vocabularies/Base/accept.txt similarity index 100% rename from testdata/fixtures/fragments/styles/Vocab/Base/accept.txt rename to testdata/fixtures/fragments/styles/config/vocabularies/Base/accept.txt diff --git a/testdata/fixtures/fragments/styles/Vocab/Base/reject.txt b/testdata/fixtures/fragments/styles/config/vocabularies/Base/reject.txt similarity index 100% rename from testdata/fixtures/fragments/styles/Vocab/Base/reject.txt rename to testdata/fixtures/fragments/styles/config/vocabularies/Base/reject.txt diff --git a/testdata/fixtures/vocab/styles/vocab.txt b/testdata/fixtures/vocab/styles/config/ignorefiles/vocab.txt similarity index 100% rename from testdata/fixtures/vocab/styles/vocab.txt rename to testdata/fixtures/vocab/styles/config/ignorefiles/vocab.txt diff --git a/testdata/fixtures/vocab/styles/Vocab/Basic/accept.txt b/testdata/fixtures/vocab/styles/config/vocabularies/Basic/accept.txt similarity index 100% rename from testdata/fixtures/vocab/styles/Vocab/Basic/accept.txt rename to testdata/fixtures/vocab/styles/config/vocabularies/Basic/accept.txt diff --git a/testdata/fixtures/vocab/styles/Vocab/Basic/reject.txt b/testdata/fixtures/vocab/styles/config/vocabularies/Basic/reject.txt similarity index 100% rename from testdata/fixtures/vocab/styles/Vocab/Basic/reject.txt rename to testdata/fixtures/vocab/styles/config/vocabularies/Basic/reject.txt diff --git a/testdata/fixtures/vocab/styles/Vocab/Second/accept.txt b/testdata/fixtures/vocab/styles/config/vocabularies/Second/accept.txt similarity index 100% rename from testdata/fixtures/vocab/styles/Vocab/Second/accept.txt rename to testdata/fixtures/vocab/styles/config/vocabularies/Second/accept.txt diff --git a/testdata/fixtures/vocab/styles/Vocab/Second/reject.txt b/testdata/fixtures/vocab/styles/config/vocabularies/Second/reject.txt similarity index 100% rename from testdata/fixtures/vocab/styles/Vocab/Second/reject.txt rename to testdata/fixtures/vocab/styles/config/vocabularies/Second/reject.txt diff --git a/testdata/styles/Vocab/Cap/accept.txt b/testdata/styles/config/vocabularies/Cap/accept.txt similarity index 100% rename from testdata/styles/Vocab/Cap/accept.txt rename to testdata/styles/config/vocabularies/Cap/accept.txt diff --git a/testdata/styles/Vocab/Cap/reject.txt b/testdata/styles/config/vocabularies/Cap/reject.txt similarity index 100% rename from testdata/styles/Vocab/Cap/reject.txt rename to testdata/styles/config/vocabularies/Cap/reject.txt