Skip to content

Commit

Permalink
Document ways to avoid formatting with black
Browse files Browse the repository at this point in the history
  • Loading branch information
erictleung committed Jun 5, 2023
1 parent 8e60127 commit 1c3fd79
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,41 @@ Other settings available to change can be found by running `black --help`.
You can read more about this
[here](https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-format).


## Conditionally apply formatting

There are two ways to tell black to apply formatting to a code block:

1. Use `# fmt: off` before a block of code
2. Use `black = FALSE` in chunk options

For example, black won't format the `custom_formatting` object, but will format
the `black_formatting` object.

```python
# fmt: off
custom_formatting = [
0, 1, 2,
3, 4, 5,
6, 7, 8,
]
# fmt: on
black_formatting = [
0, 1, 2,
3, 4, 5,
6, 7, 8,
]
```

Another way to avoid formatting an entire code block is to set `black = FALSE`
in the code chunk.

````{verbatim}
```{python, black = FALSE}
```
````

## License

MIT
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,40 @@ Other settings available to change can be found by running
You can read more about this
[here](https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-format).

## Conditionally apply formatting

There are two ways to tell black to apply formatting to a code block:

1. Use `# fmt: off` before a block of code
2. Use `black = FALSE` in chunk options

For example, black won’t format the `custom_formatting` object, but will
format the `black_formatting` object.

``` python
# fmt: off
custom_formatting = [
0, 1, 2,
3, 4, 5,
6, 7, 8,
]
# fmt: on
black_formatting = [
0, 1, 2,
3, 4, 5,
6, 7, 8,
]
```

Another way to avoid formatting an entire code block is to set
`black = FALSE` in the code chunk.

```` default
```{python, black = FALSE}
```
````

## License

MIT

0 comments on commit 1c3fd79

Please sign in to comment.