✌️ dotenv-linter
Linter for .env
files. Written in Rust
👨💻 Installation
Binary
# Linux
$ curl https://github.com/mgrachev/dotenv-linter/releases/download/v1.1.1/dotenv-linter-linux-x86_64.tar.gz -sSfL | tar -xzf -
# Alpine Linux
$ wget https://github.com/mgrachev/dotenv-linter/releases/download/v1.1.1/dotenv-linter-alpine-x86_64.tar.gz -O - -q | tar -xzf -
# macOS
$ curl https://github.com/mgrachev/dotenv-linter/releases/download/v1.1.1/dotenv-linter-darwin-x86_64.tar.gz -sSfL | tar -xzf -
Homebrew / Linuxbrew
$ brew install mgrachev/tap/dotenv-linter
Arch Linux / AUR
# 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
$ docker run --rm -v `pwd`:/app -w /app mgrachev/dotenv-linter
Cargo
If you are a Rust programmer, you can install dotenv-linter
via cargo
:
$ cargo install dotenv-linter
GitHub Action
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: 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
Example: .circleci/config.yml
version: 2.1
jobs:
dotenv-linter:
docker:
- image: circleci/rust:latest
steps:
- checkout
- run:
name: Run dotenv-linter
command: |
DOTENV_LINTER_VERSION=v1.1.1
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
🚀 Usage
By default, dotenv-linter
checks all files that start and end with .env
. For example: .env
, test.env
, .env.qa
:
$ dotenv-linter
.env:1 Invalid leading character detected
.env:2 The FOO-BAR key has incorrect delimiter
.env:3 The FOo_BAR key should be in uppercase
.env:4 The line has spaces around equal sign
test.env:5 The foo_bar key should be in uppercase
test.env:6 The FOO key should be with a value or have an equal sign
If you want to include a file with a specific name to check,
you can use the argument --include FILE_NAME
or its short version -i FILE_NAME
:
$ dotenv-linter -i test.dotenv .my-env-file
.env:1 Invalid leading character detected
test.dotenv:2 The FOO-BAR key has incorrect delimiter
.my-env-file:3 The line has spaces around equal sign
If you want to exclude a file with a specific name from check,
you can use the argument --exclude FILE_NAME
or its short version -e FILE_NAME
:
$ dotenv-linter -e .env .env.test
If you want to specify the directory where to run dotenv-linter,
you can use the argument --path DIRECTORY_PATH
or its short version -p DIRECTORY_PATH
:
$ dotenv-linter -p /directory/where/to/run
✅ Checks
Duplicated Keys
Detects if a key is not unique:
❌Wrong
FOO=BAR
FOO=BAR
✅Correct
FOO=BAR
BAR=FOO
Incorrect delimiter
Detects if a key does not use an underscore to separate words:
❌Wrong
FOO-BAR=FOOBAR
✅Correct
FOO_BAR=FOOBAR
Keys without values
Detects if a line has a key without a value:
❌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):
❌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:
❌Wrong
FOo_BAR=FOOBAR
❌Wrong
foo_bar=FOOBAR
✅Correct
FOO_BAR=FOOBAR
Spaces around equal sign
Detects lines with a whitespace around equal sign character =
:
❌Wrong
FOO =BAR
❌Wrong
FOO= BAR
❌Wrong
FOO = BAR
✅Correct
FOO=BAR
Unordered Keys
Detects if a key is not alphabetically ordered:
❌Wrong
FOO=BAR
BAR=FOO
✅Correct
BAR=FOO
FOO=BAR
📋 Roadmap
- Add more checks:
- Duplicated keys;
- Incorrect delimiter;
- Keys without values;
- Leading character;
- Lowercase keys;
- Spaces around equal sign;
- Unordered keys;
- Support reviewdog;
- Create a GitHub Action for easily using
dotenv-linter
.
🤝 Contributing
If you've ever wanted to contribute to open source, now you have a great opportunity:
👍 Similar projects
- wemake-services/dotenv-linter (Python)
✨ Contributors
This project exists thanks to all the people who contribute. [Contribute].