Token导航 LogoToken导航TokenDH.com
开发只读github未标认证来源可访问许可证需确认审计通过

dart-fix-static-analysis-errorsdart 修复静态分析错误

Agent Skill

dart-fix-static-analysis-errors 用于记录任务执行中的错误、用户纠正、经验和能力缺口,适合在 Codex、Claude、Cursor、Gemini CLI 中希望让 Agent 持续沉淀问题、修正和最佳实践时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

1,858

周安装

79

GitHub Stars

63

下载量

651
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:dart-fix-static-analysis-errors(dart 修复静态分析错误)
来源仓库:https://github.com/dart-lang/skills
仓库路径:skills/dart-fix-static-analysis-errors
安装命令:
npx skills add https://github.com/dart-lang/skills --skill dart-fix-static-analysis-errors
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/dart-lang/skills --skill dart-fix-static-analysis-errors

简介

dart-fix-static-analysis-errors 用于自动识别并修复 Dart 代码中的静态分析错误,提升代码质量和一致性。

  • 适用于需要持续改进代码质量、处理静态分析警告或进行代码审查的 Dart 项目场景。
  • 通过运行 dart analyze 获取诊断信息,结合自动化修复建议快速定位和解决类型、空安全等问题。
  • 安装前请确认项目是否使用 Dart SDK,并检查是否需要额外权限执行分析或修改文件。
  • 注意该技能可能触发文件读写,建议在非生产分支测试后再应用到主代码库。

SKILL.md

Resolving Dart Static Analysis Errors

Contents

Diagnostic Execution

Execute the Dart analyzer to identify static errors, warnings, and informational diagnostics across the codebase.

  • Run $ dart analyze to evaluate all Dart files in the current directory.
  • Target specific directories or files by appending the path: $ dart analyze bin or $ dart analyze lib/main.dart.
  • Enforce strictness by failing on info-level issues using the --fatal-infos flag.
  • Apply automated quick-fixes for supported diagnostics using $ dart fix --apply. Preview changes first with $ dart fix --dry-run.

Null Safety & Type Resolution

Address static errors related to Dart's sound null safety and strict type system.

  • Nullability: Append ? to types to explicitly allow null (e.g., String?).
  • Assertion: Use the postfix bang operator ! to cast a nullable expression to its underlying non-nullable type when you can guarantee it is not null.
  • Delayed Initialization: Apply the late modifier to non-nullable top-level or instance variables that are guaranteed to be initialized before their first read, bypassing the analyzer's definite assignment checks.
  • Named Parameters: Use the required modifier for named parameters that do not have a default value and cannot be null.
  • Explicit Downcasts: If static analysis disallows an implicit downcast (e.g., assigning List<Animal> to List<Cat>), use an explicit cast: as List<Cat>.
  • Generic Types: Always provide explicit type annotations to generic classes (e.g., List<String>, Map<String, dynamic>). Avoid using a raw List or Map which defaults to dynamic.

Flow Analysis & Type Promotion

Leverage Dart's control flow analysis to safely promote nullable types to non-nullable types without manual casting.

  • Null Checks: Check a local variable against null (e.g., if (value!= null)) to automatically promote it to a non-nullable type within that block.
  • Type Tests: Use the is operator (e.g., if (value is String)) to promote a variable to a specific subclass or type.
  • Early Returns: Use early returns, break, or throw to exit a control flow path if a variable is null or the wrong type. The analyzer will promote the variable for the remainder of the scope.
  • Reachability: Use the Never type for functions that unconditionally throw exceptions or terminate the process. The analyzer uses this to determine unreachable code paths.

Analyzer Configuration

Configure the analysis_options.yaml file at the package root to enforce stricter type checks and customize linter rules.

  • Enable strict-casts: true to prevent implicit downcasts from dynamic.
  • Enable strict-inference: true to prevent the analyzer from falling back to dynamic when it cannot infer a type.
  • Enable strict-raw-types: true to require explicit type arguments on generic types.
  • Suppress specific diagnostics in a file using // ignore_for_file: <diagnostic_name>.
  • Suppress a diagnostic on a specific line using // ignore: <diagnostic_name>.

Workflow: Static Analysis Remediation

Follow this sequential workflow to resolve static analysis errors in a Dart project.

Task Progress Checklist

Copy this checklist to track your progress:

  • Run $ dart analyze to establish a baseline of errors.
  • Run $ dart fix --apply to resolve automatically fixable issues.
  • Address remaining Null Safety errors (?, !, late, required).
  • Address remaining Type System errors (explicit as casts, generic type annotations).
  • Run $ dart analyze to verify all errors are resolved.
  • Execute tests or run the application to ensure fixes did not introduce runtime exceptions (e.g., failed as casts or uninitialized late variables).

Conditional Logic

  • If working with mixed-version code (legacy Dart 2.9): Disable sound null safety temporarily by passing --no-sound-null-safety to dart run or flutter run, or by adding // @dart=2.9 to the top of the entrypoint file.
  • If a field is private and final: Rely on flow analysis for type promotion.
  • If a field is public or non-final: Flow analysis cannot promote it. Copy the field to a local variable first, check the local variable for null, and use the local variable.

Feedback Loop

  1. Run Validator: $ dart analyze
  2. Review Errors: Identify the file, line number, and diagnostic code.
  3. Fix: Apply the appropriate null safety or type resolution fix.
  4. Repeat: Continue until $ dart analyze returns "No issues found!".

Examples

Type Promotion via Local Variable Assignment

When dealing with nullable instance fields, copy to a local variable to enable flow analysis.

Incorrect (Fails Analysis):

class Coffee {
  String? _temperature;

  void checkTemp() {
    if (_temperature != null) {
      // ERROR: Property cannot be promoted because it is not a local variable.
      print(_temperature.length);
    }
  }
}

Correct:

class Coffee {
  String? _temperature;

  void checkTemp() {
    final temp = _temperature; // Copy to local variable
    if (temp != null) {
      // SUCCESS: 'temp' is promoted to non-nullable String.
      print(temp.length);
    }
  }
}

Strict Analyzer Configuration

Implement the following analysis_options.yaml to enforce strict type safety.

include: package:lints/recommended.yaml

analyzer:
  language:
    strict-casts: true
    strict-inference: true
    strict-raw-types: true
  errors:
    invalid_assignment: error
    missing_return: error
    dead_code: info

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.73%
按下载量换算220

Claude

29.11%
按下载量换算190

Cursor

18.03%
按下载量换算117

Gemini CLI

10.14%
按下载量换算66

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills