diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/docs/README.md b/docs/README.md index 3aed286..7f85754 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,7 +4,7 @@ --- -Dotenv-linter can [check](/usage/check) / [fix](/usage/fix) / [compare](/usage/compare) `.env` files for problems that may cause the application to malfunction. +Dotenv-linter can [check](/usage/check) / [fix](/usage/fix) / [diff](/usage/diff) `.env` files for problems that may cause the application to malfunction. **Available checks**:

@@ -16,6 +16,7 @@ Dotenv-linter can [check](/usage/check) / [fix](/usage/fix) / [compare](/usage/c     ✅ Leading character
    ✅ Lowercase key
    ✅ Quote character
+    ✅ Schema violation
    ✅ Space character
    ✅ Substitution key
    ✅ Trailing whitespace
diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 2b78f2e..0501111 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -2,7 +2,8 @@ * [👨‍💻 Installation](installation.md) * 🎉 What's new? - * [v3.3.1 (latest)](whats_new/v331.md) + * [v4.0.0 (latest)](whats_new/v400.md) + * [v3.3.1](whats_new/v331.md) * [v3.3.0](whats_new/v330.md) * [v3.2.0](whats_new/v320.md) * [v3.1.1](whats_new/v311.md) @@ -13,9 +14,8 @@ * 🚀 Usage * [✅ Check](usage/check.md) - * [🤲 Compare](usage/compare.md) + * [🤲 Diff](usage/diff.md) * [🛠 Fix](usage/fix.md) - * [📄 List](usage/list.md) * ✅ Checks * [Duplicated key](checks/duplicated_key.md) @@ -26,6 +26,7 @@ * [Leading character](checks/leading_character.md) * [Lowercase key](checks/lowercase_key.md) * [Quote character](checks/quote_character.md) + * [Schema violation](checks/schema_violation.md) * [Space character](checks/space_character.md) * [Substitution key](checks/substitution_key.md) * [Trailing whitespace](checks/trailing_whitespace.md) diff --git a/docs/checks/schema_violation.md b/docs/checks/schema_violation.md new file mode 100644 index 0000000..cdca96f --- /dev/null +++ b/docs/checks/schema_violation.md @@ -0,0 +1,49 @@ +# Schema violation + +`dotenv-linter` can check `.env` files for schema compliance. +A schema is simply a `JSON` file that describes the names of keys and the format of their values. +If a key value is of a different type, `dotenv-linter` will display a warning. + +Example of the contents of a schema file (the schema file name can be anything): +```json +// .schema.env.json +{ + "version": "1.0", + "entries": { + "NAME": { + "type": "String", + "regex": "^DOT*" + }, + "PORT": { + "type": "Integer" + }, + "PRICE": { + "type": "Float" + }, + "URL": { + "type": "Url" + }, + "EMAIL": { + "type": "Email" + }, + "FLAG": { + "type": "Boolean" + } + } +} +``` + +To run `dotenv-linter` using a schema, there is a special argument `--schema` (or its short version `-s`): + +```bash +$ dotenv-linter check --schema .schema.env.json . +Checking .env +.env:1 SchemaViolation: The EMAIL key is not a valid email address +.env:2 SchemaViolation: The FLAG key is not a valid boolean +.env:3 SchemaViolation: The NAME key does not match the regex +.env:4 SchemaViolation: The PORT key is not an integer +.env:5 SchemaViolation: The PRICE key is not a valid float +.env:6 SchemaViolation: The URL key is not a valid URL + +Found 6 problems +``` diff --git a/docs/usage/check.md b/docs/usage/check.md index daf1aa4..26b656c 100644 --- a/docs/usage/check.md +++ b/docs/usage/check.md @@ -1,9 +1,9 @@ # ✅ Check -By default, `dotenv-linter` checks all `.env` files in the current directory: +`dotenv-linter` can check all `.env` files in a directory: ```bash -$ dotenv-linter +$ dotenv-linter check . Checking .env .env:2 DuplicatedKey: The FOO key is duplicated .env:3 UnorderedKey: The BAR key should go before the FOO key @@ -17,7 +17,7 @@ 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: ```bash -$ dotenv-linter dir1 dir2/.my-env-file +$ dotenv-linter check dir1 dir2/.my-env-file Checking dir1/.env dir1/.env:1 LeadingCharacter: Invalid leading character detected dir1/.env:3 IncorrectDelimiter: The FOO-BAR key has incorrect delimiter @@ -33,7 +33,7 @@ Found 3 problems If you need to exclude a file from check, you can use the `--exclude FILE_PATH` argument (or its short version `-e`): ```bash -$ dotenv-linter --exclude .env.test +$ dotenv-linter check --exclude .env.test . Checking .env .env:2 DuplicatedKey: The FOO key is duplicated .env:3 UnorderedKey: The BAR key should go before the FOO key @@ -46,7 +46,7 @@ Found 2 problems If you need a recursive search inside directories (deeper than 1 level), you can use the `--recursive` argument (or its short version `-r`): ```bash -$ dotenv-linter --recursive +$ dotenv-linter check --recursive . Checking .env Checking dir1/.env dir1/.env:2 DuplicatedKey: The FOO key is duplicated @@ -57,12 +57,12 @@ dir2/subdir/.env:3 IncorrectDelimiter: The FOO-BAR key has incorrect delimiter Found 2 problems ``` -#### Skip checks +#### Ignore checks -If you need to skip some checks, you can use the `--skip CHECK_NAME` argument (or its short version `-s`): +If you need to ignore some checks, you can use the `--ignore-checks CHECK_NAME` argument (or its short version `-i`): ```bash -$ dotenv-linter --skip UnorderedKey EndingBlankLine +$ dotenv-linter check --ignore-checks UnorderedKey,EndingBlankLine . Checking .env .env:2 DuplicatedKey: The FOO key is duplicated @@ -87,7 +87,7 @@ BAR=FOO If you want to see only warnings without additional information, use the `--quiet` argument (or its short version `-q`): ```bash -$ dotenv-linter --quiet +$ dotenv-linter check --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 @@ -95,10 +95,10 @@ $ dotenv-linter --quiet #### Disable colored output -By default, the output is colored. If you want to disable colored output, you can use the `--no-color` argument: +By default, the output is colored. If you want to disable colored output, you can use the `--plain` argument: ```bash -$ dotenv-linter --no-color +$ dotenv-linter check --plain . .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 @@ -112,7 +112,7 @@ By default, `dotenv-linter` checks for a new version once a day. If the new version is available, it will display information about it: ```bash -$ dotenv-linter +$ dotenv-linter check . .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 @@ -123,7 +123,7 @@ A new release of dotenv-linter is available: v3.1.0 -> v3.1.1 https://github.com/dotenv-linter/dotenv-linter/releases/tag/v3.1.1 ``` -If you want to disable checking for updates, you can use the `--not-check-updates` argument. +If you want to disable checking for updates, you can use the `--skip-updates` argument. #### Export prefix @@ -133,3 +133,17 @@ It is possible to use `export` prefix for defined variables. For example, `expor Some tools use `.env` file names but content of these files is not what `dotenv-linter` expects.
Currently `dotenv-linter` doesn't check `.envrc` files because [direnv](https://direnv.net) uses them as bash scripts. + +#### Environment variables + +Some settings can be controlled via environment variables. + +* `DOTENV_LINTER_IGNORE_CHECKS` - disables checks (multiple checks are specified separated by commas): +```bash +$ DOTENV_LINTER_IGNORE_CHECKS=QuoteCharacter dotenv-linter check . +``` + +* `DOTENV_LINTER_SKIP_UPDATES` - disables checking for updates: +```bash +$ DOTENV_LINTER_SKIP_UPDATES=true dotenv-linter check . +``` diff --git a/docs/usage/compare.md b/docs/usage/compare.md deleted file mode 100644 index ede2915..0000000 --- a/docs/usage/compare.md +++ /dev/null @@ -1,17 +0,0 @@ -# 🤲 Compare - -`dotenv-linter` can compare `.env` files with each other and output the difference between them with the `compare` command (or its short version `c`): - -```bash -$ dotenv-linter compare .env .env.example -Comparing .env -Comparing .env.example -.env is missing keys: BAR -.env.example is missing keys: FOO -``` - -#### Addition arguments - -In addition, the `compare` command supports the following list of arguments: -* [--quiet](/usage/check?id=quiet-mode) -* [--no-color](/usage/check?id=disable-colored-output) diff --git a/docs/usage/diff.md b/docs/usage/diff.md new file mode 100644 index 0000000..9e853ea --- /dev/null +++ b/docs/usage/diff.md @@ -0,0 +1,17 @@ +# 🤲 Diff + +`dotenv-linter` can compare `.env` files with each other and output the difference between them with the `diff` command: + +```bash +$ dotenv-linter diff .env .env.example +Comparing .env +Comparing .env.example +.env is missing keys: BAR +.env.example is missing keys: FOO +``` + +#### Additional arguments + +In addition, the `diff` command supports the following list of arguments: +* [--quiet](/usage/check?id=quiet-mode) +* [--plain](/usage/check?id=disable-colored-output) diff --git a/docs/usage/fix.md b/docs/usage/fix.md index d7b842c..0bb2a10 100644 --- a/docs/usage/fix.md +++ b/docs/usage/fix.md @@ -1,9 +1,9 @@ # 🛠 Fix -`dotenv-linter` can also fix the found warnings with the `fix` command (or its short version `f`): +`dotenv-linter` can also fix the found warnings with the `fix` command: ```bash -$ dotenv-linter fix +$ dotenv-linter fix . Fixing .env Original file was backed up to: ".env_1601378896" @@ -18,7 +18,7 @@ All warnings are fixed. Total: 2 By default, `fix` creates backups of files. If you want to disable the backup function, use the argument `--no-backup`: ```bash -$ dotenv-linter fix --no-backup +$ dotenv-linter fix --no-backup . Fixing .env .env:2 DuplicatedKey: The BAR key is duplicated .env:3 LowercaseKey: The foo key should be in uppercase @@ -31,7 +31,7 @@ All warnings are fixed. Total: 2 If you want to run `fix` without modifying any files on disk, use the `--dry-run` flag. ```bash -$ dotenv-linter fix --dry-run +$ dotenv-linter fix --dry-run . Fixing .env Dry run - not changing any files on disk. @@ -39,18 +39,17 @@ BAR=bar_example_one # BAR=bar_example_two FOO=foo_example - .env:2 DuplicatedKey: The BAR key is duplicated .env:3 LowercaseKey: The foo key should be in uppercase All warnings are fixed. Total: 2 ``` -#### Addition arguments +#### Additional arguments In addition, the `fix` command supports the following list of arguments: * [--exclude](/usage/check?id=exclude-files) * [--recursive](/usage/check?id=recursive-check) -* [--skip](/usage/check?id=skip-checks) +* [--ignore-checks](/usage/check?id=ignore-checks) * [--quiet](/usage/check?id=quiet-mode) -* [--no-color](/usage/check?id=disable-colored-output) +* [--plain](/usage/check?id=disable-colored-output) diff --git a/docs/usage/list.md b/docs/usage/list.md deleted file mode 100644 index d0faee6..0000000 --- a/docs/usage/list.md +++ /dev/null @@ -1,19 +0,0 @@ -# 📄 List - -If you need to view all available checks, you can use the `list` command (or its short version `l`): - -```bash -$ dotenv-linter list -DuplicatedKey -EndingBlankLine -ExtraBlankLine -IncorrectDelimiter -KeyWithoutValue -LeadingCharacter -LowercaseKey -QuoteCharacter -SpaceCharacter -SubstitutionKey -TrailingWhitespace -UnorderedKey -``` diff --git a/docs/whats_new/v331.md b/docs/whats_new/v331.md index e62c261..f1b56b4 100644 --- a/docs/whats_new/v331.md +++ b/docs/whats_new/v331.md @@ -10,7 +10,7 @@ PR: [#757](https://github.com/dotenv-linter/dotenv-linter/pull/757) ([@harryzcy] PR: [#772](https://github.com/dotenv-linter/dotenv-linter/pull/772) ([@Dev380](https://github.com/Dev380)) -These are all the key changes that are included in the new [v3.3.1](https://github.com/dotenv-linter/dotenv-linter/releases/tag/v3.2.0) release.
+These are all the key changes that are included in the new `v3.3.1` release.
Thanks to everyone who contributed 🙏 --- diff --git a/docs/whats_new/v400.md b/docs/whats_new/v400.md new file mode 100644 index 0000000..3b68110 --- /dev/null +++ b/docs/whats_new/v400.md @@ -0,0 +1,113 @@ +# What's new in v4.0.0? + +Here's an overview of the key changes included in this release. + +### 1. New API 🆕 + +The new version of `dotenv-linter` has a changed API. Now, you must explicitly specify commands and file paths: + +| Command | v3.3.1 | v4.0.0 | +|---------|--------------------------------|----------------------------| +| Check | `$ dotenv-linter` (by default) | `$ doctenv-linter check .` | +| Diff | `$ dotenv-linter compare` | `$ dotenv-linter diff` | + +Some command options have also changed: + +| Option | v3.3.1 | v4.0.0 | +|---------------------------------------------|---------------------|-----------------| +| Lint checks to bypass | --skip | --ignore-checks | +| Switch to plain text output without colors | --no-color | --plain | +| Disable checking for application updates | --not-check-updates | --skip-updates | + +### 2. Schema based check 🔥 + +A new schema-based check has been introduced. +A schema is simply a `JSON` file that describes the names of keys and the format of their values. +If a key value is of a different type, `dotenv-linter` will display a warning. + +Example of the contents of a schema file (the schema file name can be anything): +```json +// .schema.env.json +{ + "version": "1.0", + "entries": { + "NAME": { + "type": "String", + "regex": "^DOT*" + }, + "PORT": { + "type": "Integer" + }, + "PRICE": { + "type": "Float" + }, + "URL": { + "type": "Url" + }, + "EMAIL": { + "type": "Email" + }, + "FLAG": { + "type": "Boolean" + } + } +} +``` + +To run `dotenv-linter` using a schema, there is a special argument `--schema` (or its short version `-s`): + +```bash +$ dotenv-linter check --schema .schema.env.json . +Checking .env +.env:1 SchemaViolation: The EMAIL key is not a valid email address +.env:2 SchemaViolation: The FLAG key is not a valid boolean +.env:3 SchemaViolation: The NAME key does not match the regex +.env:4 SchemaViolation: The PORT key is not an integer +.env:5 SchemaViolation: The PRICE key is not a valid float +.env:6 SchemaViolation: The URL key is not a valid URL + +Found 6 problems +``` + +### 3. Division into crates 📦 + +Starting with this version, the `dotenv-linter` project is split into 5 separate crates that you can use in your projects: +* [dotenv-core](https://github.com/dotenv-linter/dotenv-linter/tree/master/dotenv-core) - a common crate for `dotenv-linter` crates (contains types that are used across all other crates); +* [dotenv-finder](https://github.com/dotenv-linter/dotenv-linter/tree/master/dotenv-finder) - a crate to find and parse `.env` files; +* [dotenv-analyzer](https://github.com/dotenv-linter/dotenv-linter/tree/master/dotenv-analyzer) - a crate to check and fix `.env` files; +* [dotenv-schema](https://github.com/dotenv-linter/dotenv-linter/tree/master/dotenv-schema) - a crate to validate `.env` files against schemas; +* [dotenv-cli](https://github.com/dotenv-linter/dotenv-linter/tree/master/dotenv-cli) - combines all crates into `dotenv-linter`; + +### 4. Improving `Quote Character` check 👍 + +Previously, `dotenv-linter` could print warnings for lines like this: +```env +DB_CONNECT="authSource=admin&tls=true" +``` + +In the new version, we have added exceptions for the `&` and `=` symbols, and now the warning for the example above will not be displayed. + +### 5. Environment variables 💪 + +Some settings can be controlled via environment variables. + +* `DOTENV_LINTER_IGNORE_CHECKS` - disables checks (multiple checks are specified separated by commas): +```bash +$ DOTENV_LINTER_IGNORE_CHECKS=QuoteCharacter dotenv-linter check . +``` + +* `DOTENV_LINTER_SKIP_UPDATES` - disables checking for updates: +```bash +$ DOTENV_LINTER_SKIP_UPDATES=true dotenv-linter check . +``` + +These are all the key changes that are included in the new [v4.0.0](https://github.com/dotenv-linter/dotenv-linter/releases/tag/v4.0.0) release.
+Thanks to everyone who contributed 🙏 + +--- + +How you can support the project 😉 + +* Star on [GitHub](https://github.com/dotenv-linter/dotenv-linter) ⭐️ +* Become a sponsor on [GitHub Sponsors](https://github.com/sponsors/dotenv-linter) or [OpenCollective](https://opencollective.com/dotenv-linter) ❤️ +* Contribute to the [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter/blob/master/CONTRIBUTING.md) ⚙️