.env
files. Written in Rust 🦀
It checks .env
files for problems that may cause the application to malfunction:
✅Duplicated Key
✅Incorrect delimiter
✅Key without value
✅Leading character
✅Lowercase key
✅Space character
✅Unordered Key
The key features:
âš¡ï¸Blazing-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) 🔥
dotenv-linter is created & supported by Evrone. What else we develop with Rust.
```shell script
$ curl https://github.com/mgrachev/dotenv-linter/releases/download/v1.2.0/dotenv-linter-linux-x86_64.tar.gz -sSfL | tar -xzf -
$ wget https://github.com/mgrachev/dotenv-linter/releases/download/v1.2.0/dotenv-linter-alpine-x86_64.tar.gz -O - -q | tar -xzf -
$ curl https://github.com/mgrachev/dotenv-linter/releases/download/v1.2.0/dotenv-linter-darwin-x86_64.tar.gz -sSfL | tar -xzf - ```
shell script
$ brew install mgrachev/tap/dotenv-linter
```shell script
$ trizen -S dotenv-linter-bin # for the binary distribution $ trizen -S dotenv-linter-git # for the current master branch ```
shell script
$ docker run --rm -v `pwd`:/app -w /app mgrachev/dotenv-linter
If you are a Rust programmer, you can install dotenv-linter
via cargo
:
shell script
$ cargo install dotenv-linter
.github/workflows/dotenv_linter.yml
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: mgrachev/action-dotenv-linter@v1
with:
github_token: ${{ secrets.github_token }}
In the example above, action-dotenv-linter is used to run dotenv-linter
.
.circleci/config.yml
yaml
version: 2.1
jobs:
dotenv-linter:
docker:
- image: circleci/rust:latest
steps:
- checkout
- run:
name: Run dotenv-linter
command: |
DOTENV_LINTER_VERSION=v1.2.0
wget https://github.com/mgrachev/dotenv-linter/releases/download/$DOTENV_LINTER_VERSION/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:
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
Detects if a key is not unique:
```env âŒWrong FOO=BAR FOO=BAR
✅Correct FOO=BAR BAR=FOO ```
Detects if a key does not use an underscore to separate words: ```env âŒWrong FOO-BAR=FOOBAR
✅Correct FOO_BAR=FOOBAR ```
Detects if a line has a key without a value: ```env âŒ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):
```env âŒ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:
```env âŒWrong FOo_BAR=FOOBAR
âŒWrong foo_bar=FOOBAR
✅Correct FOO_BAR=FOOBAR ```
Detects lines with a whitespace around equal sign character =
:
```env âŒWrong FOO =BAR
âŒWrong FOO= BAR
âŒWrong FOO = BAR
✅Correct FOO=BAR ```
Detects if a key is not alphabetically ordered:
```env âŒWrong FOO=BAR BAR=FOO
✅Correct BAR=FOO FOO=BAR ```
If you've ever wanted to contribute to open source, now you have a great opportunity:
This project exists thanks to all the people who contribute. [Contribute].
Become a financial contributor and help us sustain our community.