Skip to content

Commit

Permalink
Documentation for global configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
WuerfelDev committed Jun 5, 2024
1 parent 4eefa53 commit 46b1d47
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
16 changes: 14 additions & 2 deletions Documentation/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ used as a command line tool or as an API.

## Command Line Configuration

A `swift-format` configuration file is a JSON file with the following
A `.swift-format` configuration file is a JSON file with the following
top-level keys and values:

* `version` _(number)_: The version of the configuration file. For now, this
Expand Down Expand Up @@ -92,7 +92,7 @@ top-level keys and values:

An example `.swift-format` configuration file is shown below.

```javascript
```json
{
"version": 1,
"lineLength": 100,
Expand All @@ -118,6 +118,18 @@ You can also run this command to see the list of rules in the default

$ swift-format dump-configuration

## Global Configuration

If no `.swift-format` can be found for the current project/file, the configuration directories
are searched for a `swift-format/config.json` file. While the filename is different,the
configuration format stays the same.

Locations that are searched, in this order:

- `~/Library/Application Support/swift-format/config.json`
- `$XDG_CONFIG_HOME/swift-format/config.json`
- `~/.config/swift-format/config.json`

## API Configuration

The `SwiftConfiguration` module contains a `Configuration` type that is
Expand Down
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ subcommands:
or off respectively, regardless of whether the output is going to a
terminal.

* `--configuration <file>`: The path to a JSON file that contains
* `--configuration <file|string>`: The path to a JSON file that contains
[configurable settings](#configuring-the-command-line-tool) for
`swift-format`. If omitted, a default configuration is use (which
can be seen by running `swift-format dump-configuration`).
`swift-format`. If no file is found, `swift-format` tries to load the json
data as a string, if valid. If the parameter is omitted, a default
configuration is used (which can be seen by running
`swift-format dump-configuration`).

* `--ignore-unparsable-files`: If this option is specified and a source file
contains syntax errors or can otherwise not be parsed successfully by the
Expand Down Expand Up @@ -202,14 +204,18 @@ JSON-formatted file named `.swift-format` in the same directory. If one is
found, then that file is loaded to determine the tool's configuration. If the
file is not found, then it looks in the parent directory, and so on.

If there is no project specific configuration file, the
[config directories](Documentation/Configuration.md#Global-Configuration)
are checked for a `swift-format/config.json` configuration file.

If no configuration file is found, a default configuration is used. The
settings in the default configuration can be viewed by running
`swift-format dump-configuration`, which will dump it to standard
output.

If the `--configuration <file>` option is passed to `swift-format`, then that
configuration will be used unconditionally and the file system will not be
searched.
If the `--configuration <file|string>` option is passed to `swift-format`,
then that configuration will be used unconditionally and the file system will
not be searched.

See [Documentation/Configuration.md](Documentation/Configuration.md) for a
description of the configuration file format and the settings that are
Expand Down

0 comments on commit 46b1d47

Please sign in to comment.