dialyzer-configuration
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDialyzer Configuration
Dialyzer 配置
Dialyzer is a static analysis tool for Erlang and Elixir that identifies software discrepancies such as type errors, unreachable code, and unnecessary tests.
Dialyzer是一款针对Erlang和Elixir的静态分析工具,可识别软件中的不一致问题,例如类型错误、不可达代码和冗余测试。
Configuration Files
配置文件
dialyzer.ignore-warnings
dialyzer.ignore-warnings
undefinedundefinedIgnore specific warnings
Ignore specific warnings
lib/my_module.ex:42:pattern_match_cov
undefinedlib/my_module.ex:42:pattern_match_cov
undefined.dialyzer_ignore.exs
.dialyzer_ignore.exs
elixir
[
{"lib/generated_code.ex", :no_return},
{~r/lib\/legacy\/.*/, :unknown_function}
]elixir
[
{"lib/generated_code.ex", :no_return},
{~r/lib\/legacy\/.*/, :unknown_function}
]mix.exs Configuration
mix.exs 配置
elixir
def project do
[
app: :my_app,
dialyzer: [
plt_add_apps: [:mix, :ex_unit],
plt_core_path: "priv/plts",
plt_file: {:no_warn, "priv/plts/dialyzer.plt"},
flags: [:error_handling, :underspecs, :unmatched_returns],
ignore_warnings: ".dialyzer_ignore.exs",
list_unused_filters: true
]
]
endelixir
def project do
[
app: :my_app,
dialyzer: [
plt_add_apps: [:mix, :ex_unit],
plt_core_path: "priv/plts",
plt_file: {:no_warn, "priv/plts/dialyzer.plt"},
flags: [:error_handling, :underspecs, :unmatched_returns],
ignore_warnings: ".dialyzer_ignore.exs",
list_unused_filters: true
]
]
endCommon Configuration Options
常用配置选项
PLT Management
PLT 管理
- : Additional applications to include in PLT
plt_add_apps - : Directory for core PLT files
plt_core_path - : Custom PLT file location
plt_file - : Include dependencies (
plt_add_deps,:app_tree,:apps_direct):transitive
- : 要添加到PLT中的额外应用
plt_add_apps - : 核心PLT文件的存储目录
plt_core_path - : 自定义PLT文件的位置
plt_file - : 包含依赖项(
plt_add_deps,:app_tree,:apps_direct):transitive
Analysis Flags
分析标志
- - Check error handling
:error_handling - - Warn on under-specified functions
:underspecs - - Warn on unmatched return values
:unmatched_returns - - Warn on unknown functions/types
:unknown - - Warn on over-specified functions
:overspecs
- - 检查错误处理逻辑
:error_handling - - 针对规格不足的函数发出警告
:underspecs - - 针对不匹配的返回值发出警告
:unmatched_returns - - 针对未知函数/类型发出警告
:unknown - - 针对过度规格化的函数发出警告
:overspecs
Filter Options
过滤选项
- : File with warning patterns to ignore
ignore_warnings - : Show unused ignore patterns
list_unused_filters
- : 包含要忽略的警告模式的文件
ignore_warnings - : 显示未使用的忽略模式
list_unused_filters
Best Practices
最佳实践
- Incremental PLT Building: Use project-specific PLTs to speed up analysis
- Gradual Adoption: Start with subset of checks, expand over time
- CI Integration: Run Dialyzer in continuous integration
- Type Specs: Add comprehensive @spec annotations
- Warning Management: Document intentional ignores
- 增量PLT构建:使用项目专属PLT以加快分析速度
- 逐步采用:从部分检查开始,逐步扩展覆盖范围
- CI集成:在持续集成流程中运行Dialyzer
- 类型规范:添加全面的@spec注解
- 警告管理:记录有意忽略的警告内容
Common Patterns
常见模式
Conditional Analysis
条件分析
elixir
if Mix.env() in [:dev, :test] do
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false}
endelixir
if Mix.env() in [:dev, :test] do
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false}
endCustom Check Script
自定义检查脚本
bash
#!/bin/bash
mix dialyzer --format githubbash
#!/bin/bash
mix dialyzer --format githubGitHub Actions Integration
GitHub Actions 集成
yaml
- name: Run Dialyzer
run: mix dialyzer --format githubyaml
- name: Run Dialyzer
run: mix dialyzer --format github