Skip to content

Commit e1dcd0b

Browse files
committed
Add a styleguide to documentation site
1 parent a152db7 commit e1dcd0b

File tree

2 files changed

+214
-0
lines changed

2 files changed

+214
-0
lines changed

docs/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
- [Installation](installation.md)
22
- [Usage](usage.md)
3+
- [Styleguide](styleguide.md)
34
- [Taskfile Versions](taskfile_versions.md)
45
- [Examples](examples.md)
56
- [Releasing Task](releasing_task.md)

docs/styleguide.md

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# Styleguide
2+
3+
This is the official Task styleguide for `Taskfile.yml` files. This guide
4+
contains some basic instructions to keep your Taskfile clean and familiar to
5+
other users.
6+
7+
This contains general guidelines, but don't necessarely need to be strictly
8+
followed. Feel free to disagree and proceed differently in some point if you
9+
need or want to. Also, feel free to open issues or pull requests with
10+
improvements to this guide.
11+
12+
## Use `Taskfile.yml` and not `taskfile.yml`
13+
14+
```yaml
15+
# bad
16+
taskfile.yml
17+
18+
19+
# good
20+
Taskfile.yml
21+
```
22+
23+
This is important to specially to Linux users. Windows and macOS have case
24+
insensitive filesystems, so `taskfile.yml` will end up working, even that not
25+
officially supported. On Linux, only `Taskfile.yml` will work, though.
26+
27+
## Use the correct order of keywords
28+
29+
- `version:`
30+
- `includes:`
31+
- Configuration ones, like `output:` and `expansions:`
32+
- `vars:`
33+
- `env:`
34+
- `tasks:`
35+
36+
## Use 2 spaces for indentation
37+
38+
This is the most common convention for YAML files, and Task follows it.
39+
40+
```yaml
41+
# bad
42+
tasks:
43+
foo:
44+
cmds:
45+
- echo 'foo'
46+
47+
48+
# good
49+
tasks:
50+
foo:
51+
cmds:
52+
- echo 'foo'
53+
```
54+
55+
## Separate with spaces the mains sections
56+
57+
```yaml
58+
# bad
59+
version: 2
60+
includes:
61+
docker: ./docker/Taskfile.yml
62+
output: prefixed
63+
expansions: 3
64+
vars:
65+
FOO: bar
66+
env:
67+
BAR: baz
68+
tasks:
69+
# ...
70+
71+
72+
# good
73+
version: 2
74+
75+
includes:
76+
docker: ./docker/Taskfile.yml
77+
78+
output: prefixed
79+
expansions: 3
80+
81+
vars:
82+
FOO: bar
83+
84+
env:
85+
BAR: baz
86+
87+
tasks:
88+
# ...
89+
```
90+
91+
## Add spaces between tasks
92+
93+
```yaml
94+
# bad
95+
version: 2
96+
97+
tasks:
98+
foo:
99+
cmds:
100+
- echo 'foo'
101+
bar:
102+
cmds:
103+
- echo 'bar'
104+
baz:
105+
cmds:
106+
- echo 'baz'
107+
108+
109+
# good
110+
version: 2
111+
112+
tasks:
113+
foo:
114+
cmds:
115+
- echo 'foo'
116+
117+
bar:
118+
cmds:
119+
- echo 'bar'
120+
121+
baz:
122+
cmds:
123+
- echo 'baz'
124+
```
125+
126+
## Use upper-case variable names
127+
128+
```yaml
129+
# bad
130+
version: 2
131+
132+
vars:
133+
binary_name: myapp
134+
135+
tasks:
136+
build:
137+
cmds:
138+
- go build -o {{.binary_name}} .
139+
140+
141+
# good
142+
version: 2
143+
144+
vars:
145+
BINARY_NAME: myapp
146+
147+
tasks:
148+
build:
149+
cmds:
150+
- go build -o {{.BINARY_NAME}} .
151+
```
152+
153+
## Don't wrap vars in spaces when templating
154+
155+
```yaml
156+
# bad
157+
version: 2
158+
159+
tasks:
160+
greet:
161+
cmds:
162+
- echo '{{ .MESSAGE }}'
163+
164+
165+
# good
166+
version: 2
167+
168+
tasks:
169+
greet:
170+
cmds:
171+
- echo '{{.MESSAGE}}'
172+
```
173+
174+
This convention is also used by most people for any Go templating.
175+
176+
## Separate task name words with a dash
177+
178+
```yaml
179+
# bad
180+
version: 2
181+
182+
tasks:
183+
do_something_fancy:
184+
cmds:
185+
- echo 'Do something'
186+
187+
188+
# good
189+
version: 2
190+
191+
tasks:
192+
do-something-fancy:
193+
cmds:
194+
- echo 'Do something'
195+
```
196+
197+
## Use colon for task namespacing
198+
199+
```yaml
200+
# good
201+
version: 2
202+
203+
tasks:
204+
docker:build:
205+
cmds:
206+
- docker ...
207+
208+
docker:run:
209+
cmds:
210+
- docker-compose ...
211+
```
212+
213+
This is also done automatically when using included Taskfiles.

0 commit comments

Comments
 (0)