Giter Site home page Giter Site logo

purplemyst / dotenv-linter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dotenv-linter/dotenv-linter

0.0 1.0 0.0 505 KB

⚡️Lightning-fast linter for .env files. Written in Rust 🦀

Home Page: https://dotenv-linter.github.io

License: MIT License

Rust 97.20% Dockerfile 0.24% Shell 2.56%

dotenv-linter's Introduction

dotenv-linter

⚡️Lightning-fast linter for .env files. Written in Rust 🦀

GitHub Actions Coverage Status License Releases

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.

👨‍💻 Installation

Binary

# 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

Homebrew / Linuxbrew

# Installs the latest stable release
$ brew install dotenv-linter/tap/dotenv-linter

# Builds the latest version from the repository
$ brew install --HEAD dotenv-linter/tap/dotenv-linter

Arch Linux / AUR

# Use your favourite AUR-helper, e.g. trizen

# Installs the latest stable release
$ trizen -S dotenv-linter-bin

# Builds the latest version from the repository
$ trizen -S dotenv-linter-git

Windows / Scoop

$ scoop bucket add dotenv-linter https://github.com/dotenv-linter/scoop.git
$ scoop install dotenv-linter/dotenv-linter

Docker

$ 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:

$ 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: 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.

CircleCI

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

🚀 Usage

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

You can also disable checks for a specific file or line using comments:

# .env
# At the beginning - it disables checks for the whole file
# dotenv-linter:off DuplicatedKey, EndingBlankLine

# dotenv-linter:off UnorderedKey (You can disable a check for only some lines)
FOO=BAR
BAR=FOO
# dotenv-linter:on UnorderedKey (And enable it again)

If you want to see only warnings without additional information, use the argument --quiet or its short version -q (will be available in v2.2.0):

$ 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. You should use the argument --fix (or its short version -f) for this (will be available in v2.2.0):

$ dotenv-linter -f
Original file was backed up to: ".env_1601378896"

.env:2 DuplicatedKey: The BAR key is duplicated
.env:3 LowercaseKey: The foo key should be in uppercase

All warnings are fixed. Total: 2

✅ Checks

Duplicated Key

Detects if a key is not unique:

❌ 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:

❌ Wrong
FOO=BAR
✅ Correct
FOO=BAR

Extra Blank Line

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

Incorrect delimiter

Detects if a key does not use an underscore to separate words:

❌ Wrong
FOO-BAR=FOOBAR

✅ Correct
FOO_BAR=FOOBAR

Key without value

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

Quote character

Detects if a value contains quote characters (' / "):

❌ Wrong
FOO="BAR"

❌ Wrong
FOO='BAR'

❌ Wrong
FOO='B"AR'

✅ Correct
FOO=BAR

Space character

Detects lines with a whitespace around equal sign character =:

❌ 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:

❌ 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

Control comments also split lines (this is done to make the linter logic more predictable, will be available in v2.2.0):

❌ Wrong
FOO=BAR
BAR=FOO

✅ Correct 
FOO=BAR
# dotenv-linter:off LowercaseKey
bar=FOO

🤝 Contributing

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

👍 Similar projects

✨ Contributors

This project exists thanks to all the people who contribute. [Contribute].

♥️ Sponsors

Sponsored by Evrone

Become a financial contributor and help us sustain our community.

📃 License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.