### Ensure FirstOne Application Starts Source: https://github.com/jeremyjh/dialyxir/blob/master/test/fixtures/umbrella/apps/first_one/README.md Include this in your `mix.exs` file to ensure the FirstOne application is started before your own. ```elixir def application do [applications: [:first_one]] end ``` -------------------------------- ### Ensure SecondOne Starts in Application Source: https://github.com/jeremyjh/dialyxir/blob/master/test/fixtures/umbrella/apps/second_one/README.md Add `second_one` to the list of applications in your `mix.exs` file to ensure it starts before your main application. ```elixir def application do [applications: [:second_one]] end ``` -------------------------------- ### Install Dependencies and Compile Project Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md After adding Dialyxir to your dependencies, run this command to fetch and compile all project dependencies. ```console mix do deps.get, deps.compile ``` -------------------------------- ### Install Dialyzer PLT and Compile Dependencies Source: https://github.com/jeremyjh/dialyxir/wiki/Phoenix-Dialyxir-Quickstart After updating `mix.exs`, run this command to fetch dependencies, compile them, and build the Dialyzer Program Logic Table (PLT). ```Shell mix do deps.get, deps.compile, dialyzer --plt ``` -------------------------------- ### Example Dialyzer Ignore File Content Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md Content for a Dialyzer ignore file, specifying string matches for warnings to be suppressed. This example targets specific guard test failures. ```text Guard test is_binary(_@5::#{'__exception__':='true', '__struct__':=_, _=>_}) can never succeed Guard test is_atom(_@6::#{'__exception__':='true', '__struct__':=_, _=>_}) can never succeed ``` -------------------------------- ### Ignore File using `ignore_file` formatter Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md This example demonstrates the output of the `mix dialyzer --format ignore_file` command, which groups warnings by file and warning type for simpler ignore entries. ```elixir # .dialyzer_ignore.exs [ # {file, warning_type} {"lib/something.ex", :no_return}, ] ``` -------------------------------- ### Explain Dialyzer Warnings Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md Use the `dialyzer.explain` task to get information about specific Dialyzer warnings. For instance, to learn about the `unmatched_return` warning, run `mix dialyzer.explain unmatched_return`. ```console mix dialyzer.explain unmatched_return ``` -------------------------------- ### Ignore File using `ignore_file_strict` formatter Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md This example shows the output of the `mix dialyzer --format ignore_file_strict` command, providing more granular ignore entries that include the specific warning description. ```elixir # .dialyzer_ignore.exs [ # {file, warning_description} {"lib/something.ex", "Function init/1 has no local return."}, {"lib/something.ex", "Function refresh/0 has no local return."}, {"lib/something.ex", "Function create/2 has no local return."}, {"lib/something.ex", "Function update/2 has no local return."}, {"lib/something.ex", "Function delete/1 has no local return."}, ] ``` -------------------------------- ### Elixir Term Format Ignore File Example Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md This snippet shows the various formats accepted in an Elixir term ignore file (`.dialyzer_ignore.exs`). It includes examples for ignoring warnings by short description, warning type, file, or using regex. ```elixir # .dialyzer_ignore.exs [ # {short_description} {':0:unknown_function Function :erl_types.t_is_opaque/1/1 does not exist.'}, # {short_description, warning_type} {':0:unknown_function Function :erl_types.t_to_string/1 does not exist.', :unknown_function}, # {short_description, warning_type, line} {':0:unknown_function Function :erl_types.t_to_string/1 does not exist.', :unknown_function, 0}, # {file, warning_type, line} {"lib/dialyxir/pretty_print.ex", :no_return, 100}, # {file, warning_description} {"lib/dialyxir/warning_helpers.ex", "Function :erl_types.t_to_string/1 does not exist."}, # {file, warning_type} {"lib/dialyxir/warning_helpers.ex", :no_return}, # {file} {"lib/dialyxir/warnings/app_call.ex"}, # regex ~r/my_file\.ex.*my_function.*no local return/ ] ``` -------------------------------- ### Dialyzer PLT Generation with Cache Source: https://github.com/jeremyjh/dialyxir/blob/master/docs/gitlab_ci.md This job generates the Dialyzer Program Logic (PLT) file. It depends on the `build-dev` job and uses a cache policy that pulls the existing PLT cache at the start and pushes any updated cache after completion. This is useful for Dialyzer's initial setup. ```yaml dialyzer-plt: stage: check-elixir-types needs: - build-dev cache: - key: files: - .tool-versions - mix.lock paths: - priv/plts # Pull cache at start, push updated cache after completion policy: pull-push script: - mix dialyzer --plt ``` -------------------------------- ### Configure Dialyzer to Ignore Warnings File in Mix Project Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md Specify a file path in the Mix project configuration for Dialyzer to read ignore warnings from. This example points to 'dialyzer.ignore-warnings'. ```elixir def project do [ app: :my_app, version: "0.0.1", deps: deps, dialyzer: [ignore_warnings: "dialyzer.ignore-warnings"] ] end ``` -------------------------------- ### Configure Dialyzer Paths and Flags in Mix Project Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md Set additional paths for Dialyzer to search for BEAM files and configure warning flags. This example includes :mnesia for PLT, specific flags, and custom paths. ```elixir def project do [ app: :my_app, version: "0.0.1", deps: deps, dialyzer: [ plt_add_apps: [:mnesia], flags: [:unmatched_returns, :error_handling, :no_opaque], paths: ["_build/dev/lib/my_app/ebin", "_build/dev/lib/foo/ebin"] ] ] end ``` -------------------------------- ### Run Dialyzer with Specific Warning Flags Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md Pass warning flags directly to Dialyzer by appending them to the `mix dialyzer` command. For example, to check for unmatched return values, use `--unmatched_returns`. ```console mix dialyzer --unmatched_returns ``` -------------------------------- ### Configure Dialyzer Flags in Mix Project Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md Specify Dialyzer warning flags directly in the Mix project configuration. This example shows how to include flags like '-Wunmatched_returns', :error_handling, and :underspecs. ```elixir def project do [ app: :my_app, version: "0.0.1", deps: deps, dialyzer: [flags: ["-Wunmatched_returns", :error_handling, :underspecs]] ] end ``` -------------------------------- ### Ignore Specific Function Warnings with @dialyzer Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md Use the @dialyzer module attribute to suppress warnings for specific functions. This example disables warnings for the 'rollback/1' function. ```elixir defmodule Myapp.Repo do use Ecto.Repo, otp_app: :myapp @dialyzer {:nowarn_function, rollback: 1} end ``` -------------------------------- ### Add FirstOne Dependency Source: https://github.com/jeremyjh/dialyxir/blob/master/test/fixtures/umbrella/apps/first_one/README.md Add this to your `mix.exs` file to include FirstOne as a project dependency. ```elixir def deps do [{:first_one, "~> 0.1.0"}] end ``` -------------------------------- ### Set Up Elixir Environment in GitHub Actions Source: https://github.com/jeremyjh/dialyxir/blob/master/docs/github_actions.md Configures the Erlang/OTP and Elixir versions for the build environment. Specify the desired OTP and Elixir versions using the `otp-version` and `elixir-version` inputs. ```yaml - name: Set up Elixir id: beam uses: erlef/setup-beam@v1 with: otp-version: "24.1" # Define the OTP version elixir-version: "1.12.3" # Define the Elixir version ``` -------------------------------- ### Run Dialyzer Analysis Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md Execute this command from the root of your Mix project to initiate Dialyzer analysis. Dialyxir will automatically create or update the necessary PLT file and compile your project if needed. ```console mix dialyzer ``` -------------------------------- ### List All Known Dialyzer Warnings Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md If invoked without arguments, `mix dialyzer.explain` will list all the warnings that Dialyxir is aware of. ```console mix dialyzer.explain ``` -------------------------------- ### Add SecondOne Dependency to Mix.exs Source: https://github.com/jeremyjh/dialyxir/blob/master/test/fixtures/umbrella/apps/second_one/README.md Add this to your `mix.exs` file to include `second_one` as a project dependency. ```elixir def deps do [{:second_one, "~> 0.1.0"}] end ``` -------------------------------- ### Add Runtime Dependencies to Applications List Source: https://github.com/jeremyjh/dialyxir/wiki/Upgrading-to-0.4 If your project has runtime dependencies on Elixir libraries like `:eex`, ensure they are included in your `applications` list in `mix.exs` to avoid warnings. ```elixir def application do [applications: [:logger, :eex, :public_key]] end ``` -------------------------------- ### Run Dialyzer Analysis in GitHub Actions Source: https://github.com/jeremyjh/dialyxir/blob/master/docs/github_actions.md Executes Dialyzer analysis on the project. It's recommended to use both `--format github` for PR annotations and `--format dialyxir` for detailed logs in the GitHub Actions output. ```yaml - name: Run dialyzer # Two formats are included for ease of debugging and it is lightly recommended to use both, see https://github.com/jeremyjh/dialyxir/issues/530 for reasoning # --format github is helpful to print the warnings in a way that GitHub understands and can place on the /files page of a PR # --format dialyxir allows the raw GitHub actions logs to be useful because they have the full warning printed run: mix dialyzer --format github --format dialyxir ``` -------------------------------- ### Configure Dialyxir PLT Dependencies Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md Customize PLT dependency inclusion and exclusion. Use `:apps_direct` for direct OTP dependencies, `:plt_add_apps` to add specific applications, and `:plt_ignore_apps` to exclude unwanted dependencies. This is useful for managing memory issues with large dependency trees. ```elixir def project do [ app: :my_app, version: "0.0.1", deps: deps, dialyzer: [ plt_add_deps: :apps_direct, plt_add_apps: [:wx], plt_ignore_apps: [:mnesia] ] ] end ``` -------------------------------- ### Checkout Source Code in GitHub Actions Source: https://github.com/jeremyjh/dialyxir/blob/master/docs/github_actions.md This step checks out the source code from the repository into the GitHub Actions runner. ```yaml steps: - name: Check out source uses: actions/checkout@v2 ``` -------------------------------- ### Configure Dialyzer in mix.exs Source: https://github.com/jeremyjh/dialyxir/wiki/Phoenix-Dialyxir-Quickstart Configure Dialyzer options within the `project` function in `mix.exs`. `plt_add_deps: :transitive` helps Dialyzer build a more comprehensive program. ```Elixir dialyzer: [plt_add_deps: :transitive] ``` -------------------------------- ### Add Dev-Only Dependencies to PLT Source: https://github.com/jeremyjh/dialyxir/wiki/Upgrading-to-0.4 For development-only runtime dependencies such as `:phoenix_live_reload`, use `plt_add_apps:` in your `mix.exs` project configuration to include them in the PLT without adding them to the main `:applications` list. ```elixir def project do [ app: :my_app, version: "0.0.1", deps: deps, dialyzer: [plt_add_apps: [:phoenix_live_reload]] ] end ``` -------------------------------- ### CircleCI Configuration for Elixir Build with Dialyzer Source: https://github.com/jeremyjh/dialyxir/blob/master/docs/circleci.md This configuration sets up a CircleCI build job for an Elixir project. It utilizes Docker for the build environment and includes steps for caching Dialyzer's PLT files to speed up analysis. The caching strategy is based on the Elixir/Erlang versions and the project's mix.lock file hash. ```yaml version: 2 jobs: build: docker: - image: cimg/elixir:1.14 steps: - checkout # Compile steps omitted for simplicity # Cache key based on Erlang/Elixir version and the mix.lock hash - run: name: "Save Elixir and Erlang version for PLT caching" command: echo "$ELIXIR_VERSION $ERLANG_VERSION" > .elixir_otp_version - restore_cache: name: "Restore PLT cache" keys: - plt-{{ arch }}-{{ checksum ".elixir_otp_version" }}-{{ checksum "mix.lock" }} - run: name: "Create PLTs" command: mix dialyzer --plt - save_cache: name: "Save PLT cache" key: plt-{{ arch }}-{{ checksum ".elixir_otp_version" }}-{{ checksum "mix.lock" }} paths: "priv/plts" - run: name: "Run dialyzer" command: mix dialyzer ``` -------------------------------- ### Create PLTs if Cache Not Found Source: https://github.com/jeremyjh/dialyxir/blob/master/docs/github_actions.md This step conditionally creates the Dialyzer PLTs using `mix dialyzer --plt` only if the cache was not found in the previous step. This ensures PLTs are available for analysis. ```yaml - name: Create PLTs if: steps.plt_cache.outputs.cache-hit != 'true' run: mix dialyzer --plt ``` -------------------------------- ### Configure Dialyxir to Disable Umbrella Project Detection Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md This Elixir configuration demonstrates how to set the `no_umbrella` flag to `true` in `mix.exs` to treat a project as non-umbrella, even if a lockfile exists in a parent folder. ```elixir dialyzer: [ no_umbrella: true ] ``` -------------------------------- ### Configure Dialyzer PLT File Path in mix.exs Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md Specify a custom path for the project-level PLT file within the `mix.exs` configuration. This is useful for managing PLT files in CI environments. ```elixir def project do [ ... dialyzer: [ # Put the project-level PLT in the priv/ directory (instead of the default _build/ location) plt_file: {:no_warn, "priv/plts/project.plt"} # The above is equivalent to: # plt_local_path: "priv/plts/project.plt" # You could also put the core Erlang/Elixir PLT into the priv/ directory like so: # plt_core_path: "priv/plts/core.plt" ] ] end ``` -------------------------------- ### Configure Dialyxir to List Unused Filters Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md This Elixir configuration shows how to enable the listing of unused filters by setting the `:list_unused_filters` option to `true` in `mix.exs`. This can also be set via the command line. ```elixir dialyzer: [ ignore_warnings: "ignore_test.exs", list_unused_filters: true ] ``` -------------------------------- ### Elixir Build Job with Dependency Caching Source: https://github.com/jeremyjh/dialyxir/blob/master/docs/gitlab_ci.md This job compiles Elixir dependencies and the project itself. It uses a cache strategy based on `.tool-versions` and `mix.lock` files to store and retrieve `deps/` and `_build/dev` directories, speeding up subsequent builds. ```yaml build-dev: stage: compile cache: - key: files: - .tool-versions - mix.lock paths: - deps/ - _build/dev policy: pull-push script: - mix do deps.get, compile ``` -------------------------------- ### Ignore PLT Files in .gitignore Source: https://github.com/jeremyjh/dialyxir/blob/master/README.md Add patterns to your `.gitignore` file to prevent Dialyzer's PLT files and their hashes from being committed to version control. ```shell # .gitignore /priv/plts/*.plt /priv/plts/*.plt.hash ``` -------------------------------- ### Silence Ecto.Repo rollback warning Source: https://github.com/jeremyjh/dialyxir/wiki/Phoenix-Dialyxir-Quickstart Add the `@dialyzer` attribute to suppress the 'Function rollback/1 has no local return' warning emitted by Ecto.Repo. ```Elixir defmodule Myapp.Repo do use Ecto.Repo, otp_app: :myapp @dialyzer {:nowarn_function, rollback: 1} end ``` -------------------------------- ### Silence Phoenix.View pattern match warning Source: https://github.com/jeremyjh/dialyxir/wiki/Phoenix-Dialyxir-Quickstart Add the `@dialyzer` attribute to the `Phoenix.View` module to prevent warnings about patterns that can never match, like `{'safe', _@2}` not matching a `binary()`. ```Elixir defmodule Myapp.PageView do use Chat.Web, :view @dialyzer :no_match end ``` -------------------------------- ### Add Dialyxir to mix.exs dependencies Source: https://github.com/jeremyjh/dialyxir/wiki/Phoenix-Dialyxir-Quickstart Add Dialyxir to your project's development dependencies in `mix.exs`. This ensures it's only compiled and available in development environments. ```Elixir {:dialyxir, "~> 0.5.0", only: [:dev], runtime: false} ``` -------------------------------- ### Silence Phoenix.Router call warning Source: https://github.com/jeremyjh/dialyxir/wiki/Phoenix-Dialyxir-Quickstart In newer Phoenix projects (e.g., Elixir 1.8.1, Phoenix 1.4.0), a warning about `Function call/2 has no local return` in `Phoenix.Router` may appear. This snippet shows how to suppress it. ```Elixir lib/phoenix/router.ex:2: Function call/2 has no local return ``` -------------------------------- ### Silence Phoenix.Presence function warnings Source: https://github.com/jeremyjh/dialyxir/wiki/Phoenix-Dialyxir-Quickstart For projects using `Phoenix.Presence`, add this `@dialyzer` attribute to each presence module to suppress warnings about functions like `init`, `track`, and `update` not having local returns. ```Elixir @dialyzer [ {:nowarn_function, 'init': 1}, {:nowarn_function, 'track': 3}, {:nowarn_function, 'track': 4}, {:nowarn_function, 'update': 3}, {:nowarn_function, 'update': 4}, ] ``` -------------------------------- ### Dialyzer Type Checking with Cache Policy Source: https://github.com/jeremyjh/dialyxir/blob/master/docs/gitlab_ci.md This job performs the actual Dialyzer type check. It depends on the `dialyzer-plt` job and uses a cache policy that only pulls the PLT cache. It does not push any updates, as the PLT file is assumed to be generated and sufficient for the check. ```yaml dialyzer-check: stage: check-elixir-types needs: - dialyzer-plt cache: - key: files: - .tool-versions - mix.lock paths: - priv/plts # Pull cache at start, don't push cache after completion policy: pull script: - mix dialyzer --format short ``` -------------------------------- ### Save PLT Cache in GitHub Actions Source: https://github.com/jeremyjh/dialyxir/blob/master/docs/github_actions.md Saves the newly created PLT cache to the GitHub Actions cache. This step is separated from the restore step to ensure the cache is saved even if the Dialyzer analysis fails. It uses the same cache key as the restore step. ```yaml - name: Save PLT cache id: plt_cache_save uses: actions/cache/save@v3 if: steps.plt_cache.outputs.cache-hit != 'true' with: key: plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }} path: priv/plts ``` -------------------------------- ### Restore PLT Cache in GitHub Actions Source: https://github.com/jeremyjh/dialyxir/blob/master/docs/github_actions.md Restores the compiled Dialyzer PLT (Persistent Lookaside Table) cache using the GitHub Actions cache mechanism. The cache key is generated based on the runner OS, Erlang/Elixir versions, and the `mix.lock` file hash. This speeds up subsequent runs by avoiding recompilation. ```yaml - name: Restore PLT cache id: plt_cache uses: actions/cache/restore@v3 with: key: | plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}-${{ hashFiles('**/mix.lock') }} restore-keys: | plt-${{ runner.os }}-${{ steps.beam.outputs.otp-version }}-${{ steps.beam.outputs.elixir-version }}- path: priv/plts ``` -------------------------------- ### Silence Gettext macro warnings Source: https://github.com/jeremyjh/dialyxir/wiki/Phoenix-Dialyxir-Quickstart Use the `@dialyzer` attribute to suppress warnings related to Gettext macros, such as type mismatches in `dgettext` and `dngettext` functions. This is particularly useful for older Elixir versions with known bugs. ```Elixir @dialyzer [{:nowarn_function, 'MACRO-dgettext': 3}, {:nowarn_function, 'MACRO-dgettext': 4}, {:nowarn_function, 'MACRO-dngettext': 5}, {:nowarn_function, 'MACRO-dngettext': 6}, ] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.