Skip to content

Commit f574be2

Browse files
doc: add TLDR and hide details (#195)
* doc: add TLDR * chore(doc): auto generate docs * doc: remove heading for better helpdoc generation * chore(doc): auto generate docs * doc: add help tag links * chore(doc): auto generate docs --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 6c7f7b5 commit f574be2

File tree

2 files changed

+182
-129
lines changed

2 files changed

+182
-129
lines changed

README.md

Lines changed: 76 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# guard.nvim
2-
31
[![LuaRocks](https://img.shields.io/luarocks/v/xiaoshihou514/guard.nvim?logo=lua&color=green)](https://luarocks.org/modules/xiaoshihou514/guard.nvim)
42
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/nvimdev/guard.nvim/test.yml?label=tests)
53
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/nvimdev/guard.nvim/ci.yml?label=lint)
@@ -13,94 +11,116 @@ Async formatting and linting utility for neovim `0.10+`.
1311
- Minimal API allowing for full customization
1412
- Light-weight
1513

16-
## Usage
14+
## TLDR
1715

18-
For rocks.nvim
16+
[`help guard.nvim-tldr`](#tldr)
1917

20-
```vim
21-
Rocks install guard.nvim
18+
- Install with your favorite package manager
19+
20+
```
21+
nvimdev/guard.nvim
2222
```
2323

24-
For lazy.nvim
24+
- Register formatters:
2525

2626
```lua
27-
{
28-
"nvimdev/guard.nvim",
29-
-- lazy load by ft
30-
ft = { "lua", "c", "markdown" },
31-
-- Builtin configuration, optional
32-
dependencies = {
33-
"nvimdev/guard-collection",
34-
},
35-
}
27+
local ft = require('guard.filetype')
28+
ft('c'):fmt('clang-format')
3629
```
3730

38-
To register formatters and linters:
31+
[demo](https://github.com/user-attachments/assets/3160f979-6683-4288-870d-2447ee445431)
32+
33+
- Register linters
3934

4035
```lua
4136
local ft = require('guard.filetype')
37+
ft('lua'):lint('selene')
38+
```
4239

43-
-- Assuming you have guard-collection
44-
-- Put this in your ftplugin/lang.lua to lazy load guard
45-
ft('lang'):fmt('format-tool-1')
46-
:append('format-tool-2')
47-
:env(env_table)
48-
:lint('lint-tool-1')
49-
:extra(extra_args)
40+
[demo](https://github.com/user-attachments/assets/2ee2fdaa-42b2-41b3-80ad-26a53bf16809)
5041

51-
-- change this anywhere in your config (or not), these are the defaults
52-
vim.g.guard_config = {
53-
-- format on write to buffer
54-
fmt_on_save = true,
55-
-- use lsp if no formatter was defined for this filetype
56-
lsp_as_default_formatter = false,
57-
-- whether or not to save the buffer after formatting
58-
save_on_fmt = true,
59-
-- automatic linting
60-
auto_lint = true,
61-
-- how frequently can linters be called
62-
lint_interval = 500
63-
}
42+
- They can also be chained together:
43+
44+
```lua
45+
local ft = require('guard.filetype')
46+
ft('haskell'):fmt('ormolu')
47+
:lint('hlint')
6448
```
6549

66-
- Use `Guard fmt` to manually call format, when there is a visual selection only the selection is formatted. **NOTE**: Regional formatting is best-effort, expect inconsistencies.
67-
- `enable-fmt`, `disable-fmt` turns auto formatting on and off for the current buffer.
68-
- Use `Guard Lint` to lint manually.
69-
- `enable-lint` and `disable-lint` controls auto linting for the current buffer.
50+
- Formatters and linters can also be chained:
7051

71-
## Examples
52+
```lua
53+
local ft = require('guard.filetype')
54+
ft('python'):fmt('isort')
55+
:append('black')
56+
:lint('mypy')
57+
:append('mypyc')
58+
:append('dmypy')
59+
```
7260

73-
Format c files with clang-format and lint with clang-tidy:
61+
- You can register the same formatter for multiple filetypes:
7462

7563
```lua
76-
ft('c'):fmt('clang-format')
77-
:lint('clang-tidy')
64+
local ft = require('guard.filetype')
65+
ft('typescript,javascript,typescriptreact'):fmt('prettier')
7866
```
7967

80-
Or use lsp to format lua files first, then format with stylua, then lint with selene:
68+
- Lint all your files with `codespell`
8169

8270
```lua
83-
ft('lua'):fmt('lsp')
84-
:append('stylua')
85-
:lint('selene')
71+
-- this does not work with formatters
72+
ft('*'):lint('codespell')
8673
```
8774

88-
Register multiple filetypes to a single linter or formatter:
75+
- Custom formatters:
8976

9077
```lua
91-
ft('typescript,javascript,typescriptreact'):fmt('prettier')
78+
-- always use 4 spaces for c files
79+
ft('c'):fmt({
80+
cmd = "clang-format",
81+
args = { "--style={IndentWidth: 4}" },
82+
stdin = true,
83+
})
9284
```
9385

94-
Lint all your files with `codespell`
86+
## Usage
87+
88+
[`help guard.nvim-usage`](#usage)
89+
90+
Some presets can be configured via `vim.g.guard_config`
9591

9692
```lua
97-
-- NB: this does not work with formatters
98-
ft('*'):lint('codespell')
93+
-- defaults
94+
vim.g.guard_config = {
95+
-- format on write to buffer
96+
fmt_on_save = true,
97+
-- use lsp if no formatter was defined for this filetype
98+
lsp_as_default_formatter = false,
99+
-- whether or not to save the buffer after formatting
100+
save_on_fmt = true,
101+
-- automatic linting
102+
auto_lint = true,
103+
-- how frequently can linters be called
104+
lint_interval = 500
105+
}
99106
```
100107

101-
You can also easily create your own configuration that's not in `guard-collection`, see [CUSTOMIZE.md](./CUSTOMIZE.md).
108+
Here are all the `Guard` subcommands
109+
110+
| Name | Desc |
111+
| :----------------: | :------------------------------------------------------------------------------: |
112+
| Guard fmt | Manually call format, also works with visual mode (best effort range formatting) |
113+
| Guard lint | Manually request for lint |
114+
| Guard enable-fmt | Turns auto formatting on for the current buffer |
115+
| Guard disable-fmt | Turns auto formatting off for the current buffer |
116+
| Guard enable-lint | Turns linting on for the current buffer |
117+
| Guard disable-lint | Turns linting off for the current buffer |
118+
119+
## Further configuration
120+
121+
You can easily create your own configuration that's not in `guard-collection`, see [`help guard.nvim-creating-new-configurations`](./CUSTOMIZE.md).
102122

103-
For more niche use cases, [ADVANCED.md](./ADVANCED.md) demonstrates how to:
123+
For more niche use cases, [`help guard.nvim-advanced-tips`](./ADVANCED.md) demonstrates how to:
104124

105125
- Write your own formatting logic using the `fn` field.
106126
- Write your own linting logic using the `fn` field.

0 commit comments

Comments
 (0)