Execute `dart analyze` to identify warnings and errors, and use `dart fix --apply` to automatically resolve mechanical lint issues. Use during development to ensure code quality and before committing changes.
설치
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
Execute `dart analyze` to identify warnings and errors, and use `dart fix --apply` to automatically resolve mechanical lint issues. Use during development to ensure code quality and before committing changes.
Configure the Dart analyzer using the analysis_options.yaml file located at the package root.
Base Configuration: Always include a standard rule set (e.g., package:lints/recommended.yaml or package:flutter_lints/flutter.yaml) using the include: directive.
Strict Type Checks: Enable strict type checks under the analyzer: language: node to prevent implicit downcasts and dynamic inferences. Set strict-casts: true, strict-inference: true, and strict-raw-types: true.
Linter Rules: Explicitly enable or disable specific rules under the linter: rules: node. Use a key-value map (rule_name: true/false) when overriding included rules, or a list (- rule_name) when defining a fresh set. Do not mix list and map syntax in the same rules block.
Formatter Configuration: Configure dart format behavior under the formatter: node. Set page_width (default 80) and trailing_commas (automate or preserve).
Analyzer Plugins: Enable custom diagnostics by adding plugins under the analyzer: plugins: node. Ensure the plugin package is added as a dev_dependency in pubspec.yaml.
Diagnostic Suppression
When a diagnostic (lint or warning) yields a false positive or applies to generated code, suppress it explicitly.
File-level Exclusion: Use the analyzer: exclude: node in analysis_options.yaml to exclude entire files or directories (e.g., **/*.g.dart) using glob patterns.
File-level Suppression: Add // ignore_for_file: <diagnostic_code> at the top of a Dart file to suppress specific diagnostics for the entire file. Use // ignore_for_file: type=lint to suppress all linter rules.
Line-level Suppression: Add // ignore: <diagnostic_code> on the line directly above the offending code, or appended to the end of the offending line.
Pubspec Suppression: Add # ignore: <diagnostic_code> above the offending line in pubspec.yaml files (e.g., # ignore: sort_pub_dependencies).
Plugin Diagnostics: Prefix the diagnostic code with the plugin name when suppressing plugin-specific issues (e.g., // ignore: some_plugin/some_code).
Workflow: Executing Static Analysis
Use this workflow to identify type-related bugs, style violations, and potential runtime errors.
Task Progress:
1. Verify analysis_options.yaml exists at the project root.
2. Run the analyzer using the analyze_files MCP tool (if available) or the CLI command dart analyze <target_directory>.
3. Review the diagnostic output.
4. If info-level issues must be treated as failures, append the --fatal-infos flag.
5. Resolve reported errors manually or proceed to the Automated Fixes workflow.
Workflow: Applying Automated Fixes
Use this workflow to resolve outdated API usages, apply quick fixes, and migrate code (e.g., Dart 3 migrations).
Task Progress:
1. Execute a dry run to preview proposed changes using the dart_fix MCP tool or CLI command dart fix --dry-run.
2. Review the proposed fixes to ensure they align with the intended architecture.
3. If additional fixes are required, verify that the corresponding linter rules are enabled in analysis_options.yaml.
4. Apply the fixes using the dart_fix MCP tool or CLI command dart fix --apply.
5. Format the modified code using the dart_format MCP tool or CLI command dart format ..
6. Run the static analysis workflow to verify all diagnostics are resolved.
Examples
Production-Grade analysis_options.yaml (Flutter)
This 231-rule template covers the core Dart lint rules, Flutter-specific rules, and additional rules from the SonarQube Dart rule set. Copy this as a starting point and adjust based on your project's needs.
include:package:flutter_lints/flutter.yamlanalyzer:errors:use_build_context_synchronously:ignoreexclude:-build/**-coverage/**-.dart_tool/**-.fvm/**-android/**-ios/**-macos/**-linux/**-windows/**-web/**-assets/**-test/**# Remove if you want lint enforced in testslinter:rules:# ── Core style & correctness ──prefer_single_quotes:truealways_declare_return_types:truealways_put_control_body_on_new_line:truealways_put_required_named_parameters_first:trueannotate_overrides:trueavoid_dynamic_calls:false# Allow dynamic when neededavoid_print:true# Use debugPrint insteadavoid_empty_else:trueavoid_function_literals_in_foreach_calls:trueavoid_init_to_null:trueavoid_positional_boolean_parameters:trueavoid_private_typedef_functions:trueavoid_redundant_argument_values:trueavoid_return_types_on_setters:trueavoid_single_cascade_in_expression_statements:trueavoid_types_as_parameter_names:trueavoid_unused_constructor_parameters:trueavoid_void_async:truecamel_case_extensions:truecamel_case_types:truecancel_subscriptions:truecascade_invocations:trueclose_sinks:truecomment_references:trueconstant_identifier_names:truecontrol_flow_in_finally:truecurly_braces_in_flow_control_structures:truediagnostic_describe_all_properties:true# One-sentence diagnosticsdirectives_ordering:trueempty_catches:trueempty_constructor_bodies:trueempty_statements:truefile_names:truehash_and_equals:trueimplementation_imports:truejoin_return_with_assignment:truelibrary_names:truelibrary_prefixes:truelines_longer_than_80_chars:false# Disable if using wider formatliteral_only_boolean_expressions:trueno_adjacent_strings_in_list:truenon_constant_identifier_names:truenull_closures:trueomit_local_variable_types:true# Reduces noise in local varsone_member_abstracts:trueonly_throw_errors:trueoverridden_fields:truepackage_names:trueparameter_assignments:trueprefer_adjacent_string_concatenation:trueprefer_collection_literals:trueprefer_conditional_assignment:trueprefer_const_constructors:trueprefer_const_constructors_in_immutables:trueprefer_const_declarations:trueprefer_const_literals_to_create_immutables:trueprefer_contains:trueprefer_expression_function_bodies:trueprefer_final_fields:trueprefer_final_in_for_each:trueprefer_final_locals:trueprefer_foreach:trueprefer_function_declarations_over_variables:trueprefer_generic_function_type_aliases:trueprefer_if_elements_to_conditional_expressions:trueprefer_initializing_formals:trueprefer_interpolation_to_compose_strings:trueprefer_is_empty:trueprefer_is_not_empty:trueprefer_is_not_operator:trueprefer_iterable_whereType:trueprefer_mixin:trueprefer_null_aware_method_calls:trueprefer_null_aware_operators:trueprefer_relative_imports:true# Cleaner importsprefer_spread_collections:trueprefer_typing_uninitialized_variables:trueprovide_deprecation_message:truepublic_member_api_docs:false# Skip doc requirementrecursive_getters:truesecure_pubsec_urls:trueslash_for_doc_comments:truesort_child_properties_last:true# Flutter: child last in widgetssort_constructors_first:truesort_unnamed_constructors_first:truetest_types_in_equals:truethrow_in_finally:truetype_annotate_public_apis:truetype_init_formals:trueunawaited_futures:true# Catch dangling futuresunnecessary_await_in_return:trueunnecessary_brace_in_string_interps:trueunnecessary_const:trueunnecessary_lambdas:trueunnecessary_new:trueunnecessary_null_aware_assignments:trueunnecessary_null_in_if_null_operators:trueunnecessary_overrides:trueunnecessary_parenthesis:trueunnecessary_statements:trueunnecessary_string_escapes:trueunnecessary_this:trueunrelated_type_equality_checks:trueuse_full_hex_values_for_flutter_colors:trueuse_function_type_syntax_for_parameters:trueuse_key_in_widget_constructors:trueuse_rethrow_when_possible:trueuse_setters_to_change_properties:trueuse_string_buffers:trueuse_super_parameters:truevalid_regexps:true# ── From SonarQube Dart rule set ──annotate_redeclares:trueavoid_bool_literals_in_conditional_expressions:trueavoid_catches_without_on_clauses:falseavoid_catching_errors:trueavoid_classes_with_only_static_members:trueavoid_double_and_int_checks:trueavoid_equals_and_hash_code_on_mutable_classes:trueavoid_escaping_inner_quotes:trueavoid_field_initializers_in_const_classes:trueavoid_implementing_value_types:trueavoid_js_rounded_ints:trueavoid_multiple_declarations_per_line:trueavoid_relative_lib_imports:trueavoid_renaming_method_parameters:trueavoid_returning_null_for_void:trueavoid_returning_this:trueavoid_shadowing_type_parameters:trueavoid_slow_async_io:trueavoid_type_to_string:trueavoid_types_on_closure_parameters:falseavoid_unnecessary_containers:trueawait_only_futures:truecast_nullable_to_non_nullable:truecollection_methods_unrelated_type:truecombinators_ordering:trueconditional_uri_does_not_exist:truedangling_library_doc_comments:truedepend_on_referenced_packages:truedeprecated_consistency:truedeprecated_member_use_from_same_package:truediscarded_futures:falsedo_not_use_environment:falsedocument_ignores:trueeol_at_end_of_file:trueexhaustive_cases:true# Critical for sealed class switchesflutter_style_todos:trueimplicit_call_tearoffs:trueimplicit_reopen:trueinvalid_case_patterns:trueinvalid_runtime_check_with_js_interop_types:trueleading_newlines_in_multiline_strings:truelibrary_annotations:truelibrary_private_types_in_public_api:truematching_super_parameters:truemissing_code_block_language_in_doc_comment:truemissing_whitespace_between_adjacent_strings:trueno_default_cases:true# Forces exhaustive switchno_duplicate_case_values:trueno_leading_underscores_for_library_prefixes:trueno_leading_underscores_for_local_identifiers:trueno_literal_bool_comparisons:trueno_runtimeType_toString:trueno_self_assignments:trueno_wildcard_variable_uses:truenoop_primitive_operations:truenull_check_on_nullable_type_parameter:trueomit_obvious_local_variable_types:truepackage_prefixed_library_names:trueprefer_asserts_with_message:trueprefer_constructors_over_static_methods:trueprefer_for_elements_to_map_fromIterable:trueprefer_if_null_operators:trueprefer_inlined_adds:trueprefer_int_literals:trueprefer_void_to_null:truerequire_trailing_commas:falsesized_box_for_whitespace:truesort_pub_dependencies:falsetighten_type_of_initializing_formals:truetype_literal_in_constant_pattern:trueunintended_html_in_doc_comment:trueunnecessary_breaks:trueunnecessary_constructor_name:trueunnecessary_getters_setters:trueunnecessary_late:trueunnecessary_library_directive:trueunnecessary_library_name:trueunnecessary_null_aware_operator_on_extension_on_nullable:trueunnecessary_null_checks:trueunnecessary_nullable_for_final_variable_declarations:trueunnecessary_raw_strings:trueunnecessary_string_interpolations:trueunnecessary_to_list_in_spreads:trueunreachable_from_main:trueuse_colored_box:trueuse_decorated_box:trueuse_enums:trueuse_is_even_rather_than_modulo:trueuse_late_for_private_fields_and_variables:trueuse_named_constants:trueuse_raw_strings:trueuse_string_in_part_of_directives:trueuse_test_throws_matchers:trueuse_to_and_as_if_applicable:trueuse_truncating_division:truevoid_checks:trueformatter:page_width:100trailing_commas:preserve
// Suppress for the entire file
// ignore_for_file: unused_local_variable, dead_code
void processData() {
// Suppress for a specific line
// ignore: invalid_assignment
int x = '';
const y = 10; // ignore: constant_identifier_names
}