Code Monkey home page Code Monkey logo

dotenv-linter's Introduction

dotenv-linter

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

GitHub Actions Coverage Status License Releases

dotenv-linter can check / fix / compare .env files for problems that may cause the application to malfunction.

Available checks:

    ✅ Duplicated key
    ✅ Ending blank line
    ✅ Extra blank line
    ✅ Incorrect delimiter
    ✅ Key without value
    ✅ Leading character
    ✅ Lowercase key
    ✅ Quote character
    ✅ Space character
    ✅ Substitution key
    ✅ Trailing whitespace
    ✅ Unordered key
    ✅ Value without quotes

What is a .env file?

    💡 A .env file or dotenv file is a simple text file containing all the environment variables of a project.
    Storing configuration in the environment variables is one of the tenets of the Manifesto of Twelve-Factor App.
    The .env file has a simple key-value format, for example: FOO=BAR.
    More information you can find in articles in English and Russian.

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 and Super-Linter) 🔥

Articles about dotenv-linter:

👨‍💻 Installation

Pre-compiled 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

# Or a shorter way
$ curl -sSfL https://git.io/JLbXn | sh -s

# Specify installation directory and version
$ curl -sSfL https://git.io/JLbXn | sh -s -- -b usr/local/bin v2.0.0

# Alpine Linux (using wget)
$ wget -q -O - https://git.io/JLbXn | sh -s

You can find other installation methods here: https://dotenv-linter.github.io/#/installation

🚀 Usage

✅ Check

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

$ dotenv-linter
Checking .env
.env:2 DuplicatedKey: The FOO key is duplicated
.env:3 UnorderedKey: The BAR key should go before the FOO key

Checking .env.test
.env.test:1 LeadingCharacter: Invalid leading character detected

Found 3 problems

🛠 Fix

It can also fix the found warnings with the fix command:

$ dotenv-linter fix
Fixing .env
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

🤲 Compare

In addition, dotenv-linter can compare .env files with each other and output the difference between them:

$ dotenv-linter compare .env .env.example
Comparing .env
Comparing .env.example
.env is missing keys: BAR
.env.example is missing keys: FOO

Other use cases you can find on the documentation site (https://dotenv-linter.github.io):

🚦 Continuous Integration

dotenv-linter can also be used with CI services such as: GitHub Actions and Circle CI.

🚧 Benchmark

Benchmarking dotenv-linter/dotenv-linter and wemake-services/dotenv-linter has done using the hyperfine utility:

Command Mean [ms] Min [ms] Max [ms] Relative
dotenv-linter/dotenv-linter .env 2.7 ± 0.4 2.0 4.3 1.00
wemake-services/dotenv-linter .env 162.6 ± 12.1 153.0 201.3 60.83 ± 10.20
Content of .env file used for benchmarking
 SPACED=

KEY = VALUE

SECRET="my value"

SECRET=Already defined

kebab-case-name=1
snake_case_name=2

✌️ Mentorship

dotenv-linter is not just a linter for .env files — it is also a contributor-friendly open-source project with the purpose of helping others learn Rust using a simple, but useful tool. 😊

In addition to studying Rust, this project has another goal — to promote love for open-source, help you with the first steps in it and give an opportunity to contribute to the open-source project written in Rust. ❤️

We act as a mentor within this project and help developers follow the path of a novice contributor from start to the top. 🤗

🤝 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

dotenv-linter is created & supported by Evrone. What else we develop with Rust.

Sponsored by Evrone

Become a financial contributor and help us sustain our community.

📃 License

MIT

dotenv-linter's People

Contributors

anthuang avatar artem-russkikh avatar baile320 avatar brahms116 avatar ddtkey avatar dependabot[bot] avatar evgeniy-r avatar fcukit avatar gillespiecd avatar k0va1 avatar kilotaras avatar louis-lesage avatar mgrachev avatar mideb avatar mstruebing avatar pineapplethief avatar pmk21 avatar qelphybox avatar rossjones avatar samura1rem1x avatar sergioribera avatar shapurid avatar skonik avatar sonro avatar sourabhmarathe avatar stevetaggart avatar tamasflorin avatar tisorlawan avatar tom01098 avatar vbrandl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dotenv-linter's Issues

Replace field warning with template for all check structs

If we look at existing checks, we will see a little weird way of working with warnings:

pub(crate) struct KeyWithoutValueChecker {
    warning: Warning,
}

impl Default for KeyWithoutValueChecker {
    fn default() -> Self {
        Self {
            warning: Warning::new("The {} key should be with a value or have an equal sign"),
        }
    }
}

Some(Warning { message: self.warning.message.replace("{}", &line.raw_string) })
}

Therefore, I suggest replacing warning: Warning with template: String for all check structs:

pub(crate) struct KeyWithoutValueChecker {
    template: String,
}

impl Default for KeyWithoutValueChecker {
    fn default() -> Self {
        Self {
            template: String::from("The {} key should be with a value or have an equal sign"),
        }
    }
}

Some(Warning::new(self.template.replace("{}", &line.raw_string)))

Add check: Lowercase keys

Example:

# .env

# Wrong
rails_env=development

# Correct
RAILS_ENV=development

This check should display a message:

.env:1 The rails_env key should be in uppercase

Proposal: New API

Hi there!

I would like to suggest the new way of using dotenv-linter:

# Checks `*.env*` files in the current directory
$ dotenv-linter
$ dotenv-linter .

# Checks `*.env*` files in the `path`
$ dotenv-linter path

# Checks `*.env*` files in several paths
$ dotenv-linter path1 path2

# Checks only the `.env` file
$ dotenv-linter .env

# Checks only several files
$ dotenv-linter .env path/.env

# Checks only the `.env` file and `*.env*` files in the `path`
$ dotenv-linter .env path

I also want to remove --include and --path arguments, because they are no longer needed;

@mstruebing @artem-russkikh @qelphybox @sonro @Louis-Lesage
What do you think about these changes?

Global refactoring

What should be done:

  • Add mutability support for checks (First of all, this is necessary for #4, #5, #33);
  • Reorder checks alphabetically;
  • Split some tests into methods;
  • Remove dead_code (Methods used in tests).

Add support for command line arguments

Add support for 2 command line arguments:

  • --help, -h;
  • --version, -v.

To implement that we should use clap, because in the future we will increase the number of supported arguments.

Add check: Duplicated keys

Example:

# .env

# Wrong
RAILS_ENV=development
RAILS_ENV=test

# Correct
RAILS_ENV=development
RAILS_MAX_THREADS=5

This check should display a message:

.env:2 The RAILS_ENV key is duplicated

Add check: Incorrect delimiter

Example:

# .env

# Wrong
RAILS-ENV=development

# Correct
RAILS_ENV=development

This check should display a message:

.env:1 The RAILS-ENV key has incorrect delimiter

SpaceCharacter: Show check name in message

Right now the message looks like this:

.env:2 The line has spaces around equal sign

Need to add the check name to the message:

.env:2 SpaceCharacter: The line has spaces around equal sign

Fix a bug with duplicate paths

We can pass an argument to dotenv-linter to include some files to check:

$ dotenv-linter -i .my-env-file
.env:1 Leading space detected
.my-env-file:1 Leading space detected

If the file already exists in the paths, we will get a duplicate result:

$ dotenv-linter -i .env -i .env
.env:1 Leading space detected
.env:1 Leading space detected
.env:1 Leading space detected

Need to fix that and write tests for that case.

Link: https://github.com/mgrachev/dotenv-linter/blob/master/src/lib.rs#L101

Remove inline comments from lines

We should remove inline comments before running checks, because inline comments may affect checks behaviour.

Example:

FOO=BAR # some comment ===

Is need to ensure that commented lines with leading spaces will be skipped too:

 # FOO=BAR

LeadingCharacter: Show check name in message

Right now the message looks like this:

.env:2 Invalid leading character detected

Need to add the check name to the message:

.env:2 LeadingCharacter: Invalid leading character detected

Add check: Unordered keys

Example:

# .env

# Wrong
RAILS_ENV=development
DATABASE_URL=postgres://postgres@db

# Correct
DATABASE_URL=postgres://postgres@db
RAILS_ENV=development

This check should display a message:

.env:2 The DATABASE_URL key should go before the RAILS_ENV key

Add ability to include files to check

What should be done:

  • Add the command line argument: -i FILE_NAME, --include FILE_NAME;
  • Support multiple use: -i FILE_1 -i FILE_2 -i FILE_3;
  • Add usage information to README.

IncorrectDelimiter: Show check name in message

Right now the message looks like this:

.env:2 The FOO-BAR key has incorrect delimiter

Need to add the check name to the message:

.env:2 IncorrectDelimiter: The FOO-BAR key has incorrect delimiter

Provide dotenv-linter in the Arch User Repository

The Arch User Repository is like a package repository for Arch linux maintained by it's users.
I would be happy to set it up there so that any arch user can simply install it with:

<your-aur-helper> -S dotenv-linter (-S is mostly the command to install a package, in case your aur helper does it differently you need to substitute this command.

If that would be desired I would be happy to go :)

Provide more short way to install dotenv-linter

Right now we can install dotenv-linter something like this:

# Linux
$ curl https://github.com/mgrachev/dotenv-linter/releases/download/v1.1.2/dotenv-linter-linux-x86_64.tar.gz -sSfL | tar -xzf - 

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

# macOS
$ curl https://github.com/mgrachev/dotenv-linter/releases/download/v1.1.2/dotenv-linter-darwin-x86_64.tar.gz -sSfL | tar -xzf -

I would like to have a script which provides more short way to install it. For example:

curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s

Or something like that.

Prepare a template for easy adding new checks

What should be done:

  • Implement a structure for new checks (File structure, Struct, Trait);
  • Add documentation "How to write new check";
  • Add documentation "How to test new check".

Build Docker image

What should be done:

  • Build a Docker image;
  • Publish to Docker Hub;
  • Update README.

Add check: Spaces around equal sign

Example:

# .env

# Wrong
RAILS_ENV = development

# Correct
RAILS_ENV=development

This check should display a message:

.env:1 The line has spaces around equal sign

Release first version

What should be done:

  • Create a GitHub Action to make a release;
  • Build binaries for Linux, macOS and Windows;
  • Publish release to GitHub;
  • Update README.md.

LowercaseKey: Show check name in message

Right now the message looks like this:

.env:2 The FOo_BAR key should be in uppercase

Need to add the check name to the message:

.env:2 LowercaseKey: The FOo_BAR key should be in uppercase

Update README

What should be done:

  • Add build status badge;
  • Add license badge;
  • Add latest version badge;
  • Replace examples with FOO=VAR;
  • Add some emoji ✌️

Add check: Keys without values

Example:

# .env

# Wrong
RAILS_ENV

# Correct
RAILS_ENV=

# Correct
RAILS_ENV=development

This check should display a message:

.env:1 The RAILS_ENV key should be with a value

KeyWithoutValue: Show check name in message

Right now the message looks like this:

.env:2 The FOO1 key should be with a value or have an equal sign

Need to add the check name to the message:

.env:2 KeyWithoutValue: The FOO1 key should be with a value or have an equal sign

Add ability to exclude files from check

What should be done:

  • Add the command line argument: -e FILE_NAME, --exclude FILE_NAME;
  • Support multiple use: -e FILE_1 -e FILE_2 -e FILE_3;
  • Add usage information to README.

DuplicatedKey: Show check name in message

Right now the message looks like this:

.env:2 The FOO key is duplicated

Need to add the check name to the message:

.env:2 DuplicatedKey: The FOO key is duplicated

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.