dotenv-linter 2.0.0

Lightning-fast linter for .env files
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<p align="center">
  <a href="https://github.com/dotenv-linter/dotenv-linter">
    <img alt="dotenv-linter"
         width="350" height="192"
         src="https://raw.githubusercontent.com/dotenv-linter/dotenv-linter/master/logo.svg?sanitize=true">
  </a>
</p>

<h2 align="center">
⚑️Lightning-fast linter for <code>.env</code> files. Written in Rust πŸ¦€
</h2>

<p align="center">
  <a href="https://github.com/dotenv-linter/dotenv-linter/actions">
    <img alt="GitHub Actions" src="https://github.com/dotenv-linter/dotenv-linter/workflows/CI/badge.svg">
  </a>
  <a href="https://codecov.io/gh/dotenv-linter/dotenv-linter">
    <img alt="Coverage Status" src="https://codecov.io/gh/dotenv-linter/dotenv-linter/branch/master/graph/badge.svg">
  </a>
  <a href="https://github.com/dotenv-linter/dotenv-linter/blob/master/LICENSE">
    <img alt="License" src="https://img.shields.io/github/license/dotenv-linter/dotenv-linter">
  </a>
  <a href="https://github.com/dotenv-linter/dotenv-linter/releases">
    <img alt="Releases" src="https://img.shields.io/github/release/dotenv-linter/dotenv-linter">
  </a>
</p>

It checks `.env` files for problems that may cause the application to malfunction:
<p>
&nbsp;&nbsp;&nbsp;&nbsp;βœ…&nbsp;<a href="#duplicated-key">Duplicated Key</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;βœ…&nbsp;<a href="#ending-blank-line">Ending Blank Line</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;βœ…&nbsp;<a href="#extra-blank-line">Extra Blank Line</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;βœ…&nbsp;<a href="#incorrect-delimiter">Incorrect delimiter</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;βœ…&nbsp;<a href="#key-without-value">Key without value</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;βœ…&nbsp;<a href="#leading-character">Leading character</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;βœ…&nbsp;<a href="#lowercase-key">Lowercase key</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;βœ…&nbsp;<a href="#quote-character">Quote character</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;βœ…&nbsp;<a href="#space-character">Space character</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;βœ…&nbsp;<a href="#trailing-whitespace">Trailing whitespace</a><br />
&nbsp;&nbsp;&nbsp;&nbsp;βœ…&nbsp;<a href="#unordered-Key">Unordered Key</a><br />
</p>

The key features:
<p>
&nbsp;&nbsp;&nbsp;&nbsp;⚑️&nbsp;Lightning-fast because it is written in Rust πŸ¦€<br />
&nbsp;&nbsp;&nbsp;&nbsp;πŸ’£&nbsp;Can be used on any project regardless of the programming language πŸ’₯<br />
&nbsp;&nbsp;&nbsp;&nbsp;πŸš€&nbsp;Can be integrated with <a href="https://github.com/reviewdog/reviewdog">reviewdog</a> and other CI services (including <a href="https://github.com/dotenv-linter/action-dotenv-linter">GitHub Actions</a>) πŸ”₯
</p>

Articles about dotenv-linter:
* [In English]https://evrone.com/dotenv-linter?utm_source=github&utm_campaign=dotenv-linter
* [In Russian]https://www.mgrachev.com/2020/04/20/dotenv-linter

[Dotenv-linter](https://evrone.com/dotenv-linter?utm_source=github&utm_campaign=dotenv-linter) is created & supported by [Evrone](https://evrone.com/?utm_source=github&utm_campaign=dotenv-linter). What else we develop with [Rust](https://evrone.com/rust?utm_source=github&utm_campaign=dotenv-linter).

## πŸ‘¨β€πŸ’» Installation

### Binary

```shell script
# Linux
$ curl https://github.com/dotenv-linter/dotenv-linter/releases/download/v2.0.0/dotenv-linter-linux-x86_64.tar.gz -sSfL | tar -xzf -

# Alpine Linux
$ wget https://github.com/dotenv-linter/dotenv-linter/releases/download/v2.0.0/dotenv-linter-alpine-x86_64.tar.gz -O - -q | tar -xzf -

# macOS
$ curl https://github.com/dotenv-linter/dotenv-linter/releases/download/v2.0.0/dotenv-linter-darwin-x86_64.tar.gz -sSfL | tar -xzf -
```

### Homebrew / Linuxbrew

```shell script
$ brew install dotenv-linter/tap/dotenv-linter
```

### Arch Linux / AUR

```shell script
# use your favourite AUR-helper
$ trizen -S dotenv-linter-bin # for the binary distribution
$ trizen -S dotenv-linter-git # for the current master branch
```

### Docker

```shell script
$ docker run --rm -v `pwd`:/app -w /app dotenvlinter/dotenv-linter
```

### Cargo

If you are a **Rust** programmer, you can install `dotenv-linter` via `cargo`:

```shell script
$ cargo install dotenv-linter
```

### GitHub Action

<details>
<summary>Example: <code>.github/workflows/dotenv_linter.yml</code></summary>

```yaml
name: dotenv-linter
on: [pull_request]
jobs:
  dotenv-linter:
    name: runner / dotenv-linter
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v1
      - name: dotenv-linter
        uses: dotenv-linter/action-dotenv-linter@v1
        with:
          github_token: ${{ secrets.github_token }}
```

In the example above, [action-dotenv-linter](https://github.com/dotenv-linter/action-dotenv-linter) is used to run `dotenv-linter`.
</details>

### CircleCI

<details>
<summary>Example: <code>.circleci/config.yml</code></summary>

```yaml
version: 2.1
jobs:
  dotenv-linter:
    docker:
      - image: circleci/rust:latest
    steps:
      - checkout
      - run:
          name: Run dotenv-linter
          command: |
            DOTENV_LINTER_VERSION=v2.0.0
            wget https://github.com/dotenv-linter/dotenv-linter/releases/download/$DOTENV_LINTER_VERSION/dotenv-linter-alpine-x86_64.tar.gz \
            -O - -q | tar -xzf -
            ./dotenv-linter
```
</details>

## πŸš€ Usage

By default, `dotenv-linter` checks all `.env` files in the current directory:

```shell script
$ dotenv-linter
.env:2 DuplicatedKey: The FOO key is duplicated
.env:3 UnorderedKey: The BAR key should go before the FOO key
.env.test:1 LeadingCharacter: Invalid leading character detected
```

To check another directory, just pass its path as an argument. The same approach works if you need to check any files individually:

```shell script
$ dotenv-linter dir1 dir2/.my-env-file
dir1/.env:1 LeadingCharacter: Invalid leading character detected
dir1/.env:3 IncorrectDelimiter: The FOO-BAR key has incorrect delimiter
dir2/.my-env-file:1 LowercaseKey: The bar key should be in uppercase
```

If you need to exclude a file from check, you can use the argument `--exclude FILE_PATH` or its short version `-e FILE_PATH`:

```shell script
$ dotenv-linter --exclude .env.test
.env:2 DuplicatedKey: The FOO key is duplicated
.env:3 UnorderedKey: The BAR key should go before the FOO key
```

If you need to skip some checks, you can use the argument `--skip CHECK_NAME` or its short version `-s CHECK_NAME`:

```shell script
$ dotenv-linter --skip UnorderedKey EndingBlankLine
.env:2 DuplicatedKey: The FOO key is duplicated
```

If you need to view all available checks, you can use the argument `--show-checks`:

```shell script
$ dotenv-linter --show-checks
DuplicatedKey
EndingBlankLine
ExtraBlankLine
IncorrectDelimiter
KeyWithoutValue
LeadingCharacter
LowercaseKey
QuoteCharacter
SpaceCharacter
TrailingWhitespace
UnorderedKey
```

## βœ… Checks

### Duplicated Key

Detects if a key is not unique:

```env
❌ Wrong
FOO=BAR
FOO=BAR

βœ… Correct
FOO=BAR
BAR=FOO
```

### Ending Blank Line

Detects if a file doesn't have a blank line at the end:

```env
❌ Wrong
FOO=BAR
```

```env
βœ… Correct
FOO=BAR

```

### Extra Blank Line

Detects if a file contains more than one blank line in a row:

```env
❌ Wrong
A=B


FOO=BAR
```

```env
❌ Wrong
A=B
FOO=BAR


```

```env
βœ… Correct
A=B

FOO=BAR

```

```env
βœ… Correct
A=B
FOO=BAR

```

### Incorrect delimiter

Detects if a key does not use an underscore to separate words:
```env
❌ Wrong
FOO-BAR=FOOBAR

βœ… Correct
FOO_BAR=FOOBAR
```

### Key without value

Detects if a line has a key without a value:
```env
❌ Wrong
FOO

βœ… Correct
FOO=

βœ… Correct
FOO=BAR
```

### Leading character

Detects if a line starts with an unallowed character (characters from `A` to `Z` and `_` (underscore) are allowed):

```env
❌ Wrong
 FOO=BAR

❌ Wrong
.FOO=BAR

❌ Wrong
*FOO=BAR

❌ Wrong
1FOO=BAR

βœ… Correct
FOO=BAR

βœ… Correct
_FOO=BAR
```

### Lowercase key

Detects if a key has lowercase characters:

```env
❌ Wrong
FOo_BAR=FOOBAR

❌ Wrong
foo_bar=FOOBAR

βœ… Correct
FOO_BAR=FOOBAR
```

### Quote character

Detects if a value is wrapped in quotes:

```env
❌ Wrong
FOO="BAR"

❌ Wrong
FOO='BAR'

βœ… Correct
FOO=BAR
```

### Space character

Detects lines with a whitespace around equal sign character `=`:

```env
❌ Wrong
FOO =BAR

❌ Wrong
FOO= BAR

❌ Wrong
FOO = BAR

βœ… Correct
FOO=BAR
```

### Trailing whitespace

Detects if a line has a trailing whitespace.

### Unordered Key

Detects if a key is not alphabetically ordered:

```env
❌ Wrong
FOO=BAR
BAR=FOO

βœ… Correct
BAR=FOO
FOO=BAR
```

## 🀝 Contributing

If you've ever wanted to contribute to open source, now you have a great opportunity:

* [How to set up the project]/CONTRIBUTING.md#how-to-set-up-the-project
* [How to add a new check]/CONTRIBUTING.md#how-to-add-a-new-check

## πŸ‘ Similar projects

* [wemake-services/dotenv-linter]https://github.com/wemake-services/dotenv-linter (Python)

## ✨ Contributors

This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
<a href="https://github.com/dotenv-linter/dotenv-linter/graphs/contributors"><img src="https://opencollective.com/dotenv-linter/contributors.svg?width=890&button=false" /></a>

## β™₯️ Sponsors

<p>
  <a href="https://evrone.com/?utm_source=github&utm_campaign=dotenv-linter">
    <img src="https://www.mgrachev.com/assets/static/evrone-sponsored-300.png"
      alt="Sponsored by Evrone" width="210">
  </a>
</p>

Become a financial contributor and help us sustain our community.

<a href="https://opencollective.com/dotenv-linter"><img src="https://opencollective.com/dotenv-linter/individuals.svg?width=890"></a>

## πŸ“ƒ License

[MIT](https://choosealicense.com/licenses/mit)