Skip to content

Commit

Permalink
SPEC: add some thoughts about a config file and sensible (?) defaults (
Browse files Browse the repository at this point in the history
…#6)

* add some thoughts about a config file and sensible (?) defaults

* add a warning for paths on windows

* fix the NOTE in the "defaults" section

* add a newline in the Note and in the Warning
  • Loading branch information
amtoine committed Mar 25, 2023
1 parent 17d1fa0 commit a57d9d7
Showing 1 changed file with 101 additions and 1 deletion.
102 changes: 101 additions & 1 deletion docs/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,106 @@ There should be a `--limit` parameter to limit to the number of characters per l

There should be a `--lines-before` and `--lines-after` parameter to set the number of empty lines before and after a custom command.

## Config file

As `rustfmt` does it with a `TOML` file, `nufmt` could have a config file, alongside the command line flags above to set options in stone.
We have identified the NUON format as a suitable data format for this project: after it's THE data format for `nushell`!

With the values above, it could look something like:
```nuon
{
CRLF: false,
indent: 4,
limit: 100,
lines: {
after: 1,
before: 1
}
}
```

## Sensible (?) default and features

- :one: do not always add newlines when it can help understand the central point of a command call
```nushell
http get ({
scheme: https,
host: api.github.com,
path: /users/nushell/repos,
params: {
sort: updated,
per_page: 100
page: 1
}
} | url join)
```
to put the emphasis on the url structure
> **Note**
> the `({ ... } | url join)`
- :two: put `|` at the start of the lines for readability, creating a "wall of pipes"
```nushell
def "apply to" [
file: path
modification: closure
] {
$file
| path expand
| open --raw
| from toml
| do $modification
| save --force $file
}
```

- :three: ternary-like conditions when conditions and the two branches are short
```nushell
let sign = if $value < 0 { -1 } else { 1 }
```
instead of
```nushell
let sign = (
if $value < 0 {
-1
} else {
1
}
)
```

- :four: a newline before a block of comments
```nushell
some command
# a comment to explain
another comment
# a block
# of comment
# for this
last command
```

:five: two spaces before and one space after a comment on the same line as a command
```nushell
my-command # and some explaination
```
or in command arguments as well
```nushell
def foo [
a: int # my integer argument
b: string # my string integer
] {}
```

- :six: 4 spaces as the default indentation

- :seven: remove trailing whitespaces

- :eight: single quotes for single characters and double quotes for strings => that behaviour might change with string interpolation and paths.
> **Warning**
> one should use single quotes (') or backticks (\`) to quote paths on Windows
## Supported Commands

This is the list of the supported commands and their idiomatic formatting. Indentation will be covered by the `--indent` flag but for these examples, 2 spaces will be used.
Expand All @@ -42,4 +142,4 @@ if condition {
for var in 0..100 {
# do something here
}
```
```

0 comments on commit a57d9d7

Please sign in to comment.