/credo_envvar

Add-on for Credo for checking environment variables which evaluated at compile time

Primary LanguageElixirMIT LicenseMIT

Credo Envvar

Build Status Hex Version

Add-on for Credo for checking environment variables that get evaluated at Elixir compile time. Please see Credo for usage.

How does it work? + Disclaimer

This plugin does not guarantee 100% that all environment variables that are evaluated at compile time could be detected.

It just simply check wherever Application.get_env() or System.get_env() have been used outside def or defp. This will help you screen for most of the cases to make you less worried about environment variables compilation in your app.

Installation

If available in Hex, the package can be installed by adding credo_envvar to your list of dependencies in mix.exs:

def deps do
  [
    {:credo, "~> 1.0.0", only: [:dev, :test], runtime: false},
    {:credo_envvar, "~> 0.1.0", only: [:dev, :test], runtime: false}
  ]
end

And run:

$ mix deps.get

Basic Usage

Add CredoEnvvar check to .credo.exs in your project

  #
  ## Warnings
  #
  {Credo.Check.Warning.BoolOperationOnSameValues},
  {CredoEnvvar.Check.Warning.EnvironmentVariablesAtCompileTime}, # <- Add here
  {Credo.Check.Warning.ExpensiveEmptyEnumCheck},
  {Credo.Check.Warning.IExPry},

To run credo in the current project, just type:

$ mix credo

Options

Exclusions

You can exclude files or paths with the excluded_paths option:

{CredoEnvvar.Check.Warning.EnvironmentVariablesAtCompileTime, excluded_paths: ["test/support", "priv"]}

Contributing

  1. Fork it!
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

Theesit Konkaew (@kaorism)

License

CredoEnvvar is released under the MIT License. See the LICENSE file for further details.