mix dialyzer (Dialyxir v1.4.5) View Source

This task compiles the mix project, creates a PLT with dependencies if needed and runs dialyzer. Much of its behavior can be managed in configuration as described below.

If executed outside of a mix project, it will build the core PLT files and exit.

Command line options

  • --no-compile - do not compile even if needed
  • --no-check - do not perform (quick) check to see if PLT needs update
  • --force-check - force PLT check also if lock file is unchanged useful when dealing with local deps.
  • --ignore-exit-status - display warnings but do not halt the VM or return an exit status code
  • --list-unused-filters - list unused ignore filters useful for CI. do not use with mix do.
  • --plt - only build the required PLT(s) and exit
  • --format <name> - Specify the format for the warnings, can be specified multiple times to print warnings multiple times in different output formats. Defaults to dialyxir.
    • --format short - format the warnings in a compact format, suitable for ignore file using Elixir term format.
    • --format raw - format the warnings in format returned before Dialyzer formatting
    • --format dialyxir - format the warnings in a pretty printed format (default)
    • --format dialyzer - format the warnings in the original Dialyzer format
    • --format github - format the warnings in the Github Actions message format
    • --format ignore_file - format the warnings in {file, warning} format for Elixir Format ignore file
    • --format ignore_file_strict - format the warnings in {file, short_description} format for Elixir Format ignore file.
  • --quiet - suppress all informational messages
  • --quiet-with-result - suppress all informational messages except for the final result message

Warning flags passed to this task are passed on to :dialyzer - e.g.

mix dialyzer --unmatched_returns

Configuration

All configuration is included under a dialyzer key in the mix project keyword list.

Flags

You can specify any dialyzer command line argument with the :flags keyword.

Dialyzer supports a number of warning flags used to enable or disable certain kinds of analysis features. Until version 0.4, dialyxir used by default the additional warning flags shown in the example below. However some of these create warnings that are often more confusing than helpful, particularly to new users of Dialyzer. As of 0.4, there are no longer any flags used by default. To get the old behavior, specify them in your Mix project file. For compatibility reasons you can use either the -Wwarning convention of the dialyzer CLI, or (preferred) the WarnOpts atoms supported by the API. e.g.

def project do
  [
    app: :my_app,
    version: "0.0.1",
    deps: deps,
    dialyzer: [flags: ["-Wunmatched_returns", :error_handling, :underspecs]]
  ]
end

PLT Configuration

The task will build a PLT with default core Erlang applications: :erts :kernel :stdlib :crypto and re-use this core file in multiple projects - another core file is created for Elixir.

OTP application dependencies are (transitively) added to your project's PLT by default. The applications added are the same as you would see displayed with the command mix app.tree. There is also a :plt_add_deps option you can set to control the dependencies added. The following options are supported:

  • :apps_direct - Only Direct OTP runtime application dependencies - not the entire tree
  • :app_tree - Transitive OTP runtime application dependencies e.g. mix app.tree (default)
def project do
  [
    app: :my_app,
    version: "0.0.1",
    deps: deps,
    dialyzer: [plt_add_deps: :apps_direct, plt_add_apps: [:wx]]
  ]
end

You can also configure applications to include in the PLT more directly:

  • dialyzer: :plt_add_apps - applications to include in addition to the core applications and project dependencies.

  • dialyzer: :plt_ignore_apps - applications to ignore from the list of core applications and dependencies.

  • dialyzer: :plt_apps - a list of applications to include that will replace the default, include all the apps you need e.g.

Other Configuration

  • dialyzer: :plt_file - Deprecated - specify the PLT file name to create and use - default is to create one in the project's current build environment (e.g. _build/dev/) specific to the Erlang/Elixir version used. Note that use of this key in version 0.4 or later will produce a deprecation warning - you can silence the warning by providing a pair with key :no_warn e.g. plt_file: {:no_warn,"filename"}.

  • dialyzer: :plt_local_path - specify the PLT directory name to create and use - default is the project's current build environment (e.g. _build/dev/).

  • dialyzer: :plt_core_path - specify an alternative to MIX_HOME to use to store the Erlang and Elixir core files.

  • dialyzer: :ignore_warnings - specify file path to filter well-known warnings.

Link to this section Summary

Link to this section Functions

Link to this function

clean(opts, fun \\ &delete_plt/4)

View Source
Link to this function

delete_plt(plt, _, _, _)

View Source

Specs

dependency_hash() :: {[atom()], binary()}

Callback implementation for Mix.Task.run/1.