It checks .env
files for problems that may cause the application to malfunction:
β
Duplicated Key
β
Ending Blank Line
β
Extra Blank Line
β
Incorrect delimiter
β
Key without value
β
Leading character
β
Lowercase key
β
Quote character
β
Space character
β
Trailing whitespace
β
Unordered Key
The key features:
β‘οΈ Lightning-fast because it is written in Rust π¦
π£ Can be used on any project regardless of the programming language π₯
π Can be integrated with reviewdog and other CI services (including GitHub Actions) π₯
Articles about dotenv-linter:
Dotenv-linter is created & supported by Evrone. What else we develop with Rust.
# Linux / macOS / Windows (MINGW and etc). Installs it into ./bin/ by default.
$ curl -sSfL https://raw.githubusercontent.com/dotenv-linter/dotenv-linter/master/install.sh | sh -s
# Specify installation directory and version.
$ curl -sSfL https://raw.githubusercontent.com/dotenv-linter/dotenv-linter/master/install.sh | sh -s -- -b usr/local/bin v2.0.0
# Alpine Linux (wget)
$ wget -q -O - https://raw.githubusercontent.com/dotenv-linter/dotenv-linter/master/install.sh | sh -s
$ brew install dotenv-linter/tap/dotenv-linter
# use your favourite AUR-helper
$ trizen -S dotenv-linter-bin # for the binary distribution
$ trizen -S dotenv-linter-git # for the current master branch
$ scoop bucket add dotenv-linter https://github.com/dotenv-linter/scoop.git
$ scoop install dotenv-linter/dotenv-linter
$ docker run --rm -v `pwd`:/app -w /app dotenvlinter/dotenv-linter
If you are a Rust programmer, you can install dotenv-linter
via cargo
:
$ cargo install dotenv-linter
Example: .github/workflows/dotenv_linter.yml
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@v2
with:
github_token: ${{ secrets.github_token }}
In the example above, action-dotenv-linter is used to run dotenv-linter
.
Example: .circleci/config.yml
version: 2.1
jobs:
dotenv-linter:
docker:
- image: circleci/rust:latest
steps:
- checkout
- run:
name: Run dotenv-linter
command: |
wget https://github.com/dotenv-linter/dotenv-linter/releases/latest/download/dotenv-linter-alpine-x86_64.tar.gz \
-O - -q | tar -xzf -
./dotenv-linter
By default, dotenv-linter
checks all .env
files in the current directory:
$ 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
Found 3 problems
To check another directory, just pass its path as an argument. The same approach works if you need to check any files individually:
$ 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
Found 3 problems
If you need to exclude a file or directory from check, you can use the argument --exclude PATH
or its short version -e PATH
:
$ 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
Found 2 problems
If you need a recursive .env
file search inside directories, you can use the flag --recursive
or its short version -r
:
$ dotenv-linter --recursive
dir1/.env:2 DuplicatedKey: The FOO key is duplicated
dir2/subdir/.env:3 IncorrectDelimiter: The FOO-BAR key has incorrect delimiter
Found 2 problems
If you need to skip some checks, you can use the argument --skip CHECK_NAME
or its short version -s CHECK_NAME
:
$ dotenv-linter --skip UnorderedKey EndingBlankLine
.env:2 DuplicatedKey: The FOO key is duplicated
Found 1 problem
If you want to see only warnings without additional information, use the argument --quiet
or its short version -q
:
$ dotenv-linter --quiet
.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
If you need to view all available checks, you can use the flag --show-checks
:
$ dotenv-linter --show-checks
DuplicatedKey
EndingBlankLine
ExtraBlankLine
IncorrectDelimiter
KeyWithoutValue
LeadingCharacter
LowercaseKey
QuoteCharacter
SpaceCharacter
TrailingWhitespace
UnorderedKey
dotenv-linter
can also automatically fix warnings in the files. Currently only one kind of warnings is fixed
(LowercaseKey
). You should use the argument --fix
(or its short version -f
) for this (will be available in v2.2.0):
$ dotenv-linter -f
Fixed warnings:
.env:3 LowercaseKey: The foo key should be in uppercase
Unfixed warnings:
.env:2 DuplicatedKey: The BAR key is duplicated
Detects if a key is not unique:
β Wrong
FOO=BAR
FOO=BAR
β
Correct
FOO=BAR
BAR=FOO
Detects if a file doesn't have a blank line at the end:
β Wrong
FOO=BAR
β
Correct
FOO=BAR
Detects if a file contains more than one blank line in a row:
β Wrong
A=B
FOO=BAR
β Wrong
A=B
FOO=BAR
β
Correct
A=B
FOO=BAR
β
Correct
A=B
FOO=BAR
Detects if a key does not use an underscore to separate words:
β Wrong
FOO-BAR=FOOBAR
β
Correct
FOO_BAR=FOOBAR
Detects if a line has a key without a value:
β Wrong
FOO
β
Correct
FOO=
β
Correct
FOO=BAR
Detects if a line starts with an unallowed character (characters from A
to Z
and _
(underscore) are allowed):
β Wrong
FOO=BAR
β Wrong
.FOO=BAR
β Wrong
*FOO=BAR
β Wrong
1FOO=BAR
β
Correct
FOO=BAR
β
Correct
_FOO=BAR
Detects if a key has lowercase characters:
β Wrong
FOo_BAR=FOOBAR
β Wrong
foo_bar=FOOBAR
β
Correct
FOO_BAR=FOOBAR
Detects if a value is wrapped in quotes:
β Wrong
FOO="BAR"
β Wrong
FOO='BAR'
β
Correct
FOO=BAR
Detects lines with a whitespace around equal sign character =
:
β Wrong
FOO =BAR
β Wrong
FOO= BAR
β Wrong
FOO = BAR
β
Correct
FOO=BAR
Detects if a line has a trailing whitespace.
Detects if a key is not alphabetically ordered:
β Wrong
FOO=BAR
BAR=FOO
β
Correct
BAR=FOO
FOO=BAR
You can use blank lines to split lines into groups:
β Wrong
FOO=BAR
BAR=FOO
β
Correct
FOO=BAR
BAR=FOO
If you've ever wanted to contribute to open source, now you have a great opportunity:
- wemake-services/dotenv-linter (Python)
This project exists thanks to all the people who contribute. [Contribute].
Become a financial contributor and help us sustain our community.