|
| 1 | +package aspell |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | +) |
| 7 | + |
| 8 | +// configTemplate is the full .aspell.yml with all options commented out and documented. |
| 9 | +const configTemplate = `## Spell check scope: disabled (off), subject (first line only), |
| 10 | +## commit (full commit message), all (commit + file content, default: subject) |
| 11 | +# mode: disabled | subject | commit | all |
| 12 | +
|
| 13 | +## Minimum word length to spell-check (words shorter than this are skipped, default: 3) |
| 14 | +# min_length: 3 |
| 15 | +
|
| 16 | +## If true, code identifiers will NOT be excluded from spell check |
| 17 | +# no_ignore_identifiers: false |
| 18 | +
|
| 19 | +## Where to collect code identifiers from to exclude as allowed words (default: files) |
| 20 | +## diff - only from the diff content (added lines) |
| 21 | +## files - from the full content of changed files |
| 22 | +## all - from every file in the repository |
| 23 | +# identifier_scope: diff | files | all |
| 24 | +
|
| 25 | +## File patterns to skip when mode is "all" (glob syntax) |
| 26 | +# ignore_files: |
| 27 | +# - '*test.go' |
| 28 | +# - 'gen/*' |
| 29 | +
|
| 30 | +## Extra words to accept as correctly spelled (one per line, case-insensitive) |
| 31 | +# allowed: |
| 32 | +# - myword |
| 33 | +# - anotherword |
| 34 | +
|
| 35 | +## Fetch an additional allowed-word list from a JSON API endpoint |
| 36 | +# remote_file: |
| 37 | +# ## Direct URL to fetch |
| 38 | +# url: "https://example.com/api/words" |
| 39 | +# ## Or read the URL from this environment variable instead |
| 40 | +# url_env: ALLOWED_WORDS_URL |
| 41 | +# ## Set a custom HTTP header whose value is read from the named env var |
| 42 | +# header_from_env: X-Custom-Header |
| 43 | +# ## Set PRIVATE-TOKEN header from this env var (GitLab/GitHub auth) |
| 44 | +# private_token_env: PRIVATE_TOKEN |
| 45 | +# ## JSON key that contains the word list in the response |
| 46 | +# allowed_items_key: words |
| 47 | +
|
| 48 | +## Fetch dictionary files (.txt word lists or .rws aspell compiled dicts) from remote sources |
| 49 | +# dictionaries: |
| 50 | +# ## Fetch every .txt/.rws file from a GitHub repo directory |
| 51 | +# github: |
| 52 | +# - url: "https://github.com/haproxytech/check-commit/tree/main/aspell/dictionaries" |
| 53 | +# ## Optional env var holding a GitHub token (needed for private repos) |
| 54 | +# token_env: GITHUB_TOKEN |
| 55 | +# ## Fetch every .txt/.rws file from a GitLab repo directory (supports self-hosted instances) |
| 56 | +# gitlab: |
| 57 | +# - url: "https://gitlab.com/group/project/-/tree/main/path/to/dictionaries" |
| 58 | +# ## Optional env var holding a GitLab private token (needed for private repos) |
| 59 | +# token_env: GITLAB_TOKEN |
| 60 | +# ## Fetch individual dictionary files by direct URL |
| 61 | +# urls: |
| 62 | +# - "https://raw.githubusercontent.com/haproxytech/check-commit/main/aspell/dictionaries/computing.txt" |
| 63 | +# - "https://example.com/custom-words.txt" |
| 64 | +` |
| 65 | + |
| 66 | +// PrintHelp prints all available .aspell.yml configuration options to stdout. |
| 67 | +func PrintHelp() { |
| 68 | + fmt.Print(".aspell.yml configuration options:\n\n") |
| 69 | + fmt.Print(configTemplate) |
| 70 | +} |
| 71 | + |
| 72 | +// Init creates a .aspell.yml file with all options commented out. |
| 73 | +// Returns an error if the file already exists. |
| 74 | +func Init(filename string) error { |
| 75 | + if _, err := os.Stat(filename); err == nil { |
| 76 | + return fmt.Errorf("%s already exists", filename) |
| 77 | + } |
| 78 | + return os.WriteFile(filename, []byte(configTemplate), 0o644) |
| 79 | +} |
0 commit comments