669 words
3 minutes
Theodo Analysis: Simple, Strong Lints for Dart & Flutter (with DCM power)

1) What is theodo_analysis?#

theodo_analysis is a ready‑made set of lint rules for Dart and Flutter. It also ships with a subset of DCM rules (DCM is an advanced linter and code‑quality tool). The package is used internally at Theodo Apps and was inspired by very_good_analysis.


2) What you get (the leverage)#

  • Consistent code style across your repo(s). Your team uses the same rules everywhere, which reduces nit‑picky code review comments.
  • Extra quality checks via DCM (optional). DCM provides 450+ configurable rules, quick fixes, and code‑health metrics like cyclomatic complexity. theodo_analysis includes a subset of those rules; you can also enable the full DCM tool if you have a license.
  • Sensible defaults. Generated files such as *.g.dart, *.freezed.dart, and *.graphql.dart are excluded by default so you don’t get noisy warnings from generated code.
  • Clear customization path. You can turn a rule off, turn another one on, or add more rules later in analysis_options.yaml.

3) Important rules you’ll likely encounter#

The package lets you enable/disable rules and add more. Here are notable ones you’ll see referenced in the docs and changelog, with simple explanations.

  • no_leading_underscores_for_local_identifiers (Dart linter) Don’t start local variable/parameter names with _. In Dart, underscore suggests privacy; using it for locals is confusing.

  • public_member_api_docs (Dart linter) Encourages adding doc comments to public APIs. You can disable it if it’s too strict for your team.

  • member-ordering (DCM) Keeps class members (fields/getters/setters/constructors/methods) in a consistent order, improving readability and discoverability. Configurable (and even alphabetization options exist).

  • avoid-inferrable-type-arguments (DCM) If Dart can infer the type argument, don’t spell it out—removes noise like <String> when it’s obvious. Has an auto‑fix.

  • list-all-equatable-fields (DCM, Equatable) When using Equatable, ensure every relevant field is listed in props, so equality works correctly. This rule was added to the package in v1.2.0.

The full Dart lints list is on dart.dev, and the full DCM rule catalog is on dcm.dev. theodo_analysis uses a curated subset.


4) How to add it (copy–paste)#

Best practice: add as a dev dependency and include the package’s analysis options file.

  1. Add the package (dev dependency):
Terminal window
dart pub add dev:theodo_analysis
# or
flutter pub add dev:theodo_analysis
  1. Include it in analysis_options.yaml (at your project root):
include: package:theodo_analysis/analysis_options.yaml

These steps come straight from the official docs.

Note: Pub’s generic “Install” tab may show adding it under normal dependencies, but the package’s own docs say dev dependency—follow that.


5) Customize rules (turn rules on/off, add more)#

You can tweak rules directly in analysis_options.yaml. The docs show examples like:

Turn a rule off (suppress):

include: package:theodo_analysis/analysis_options.yaml
linter:
rules:
public_member_api_docs: false
dart_code_metrics:
rules:
- member-ordering: false

Add a rule:

include: package:theodo_analysis/analysis_options.yaml
linter:
rules:
- no_leading_underscores_for_local_identifiers
dart_code_metrics:
rules:
- avoid-inferrable-type-arguments

Exclude generated files (already the default, but you can keep it explicit):

include: package:theodo_analysis/analysis_options.yaml
analyzer:
exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
- "**/*.graphql.dart"
dart_code_metrics:
rules-exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
- "**/*.graphql.dart"

6) Optional: enable DCM extras (unused code checks, metrics, quick fixes)#

If you want the full DCM features (like “find unused code”, “check duplicate code”, quick‑fixes, and metrics such as cyclomatic complexity), you can install and activate DCM. The theodo_analysis docs explain that DCM needs an API key. In short:

  • Install DCM (macOS example):

    Terminal window
    brew tap CQLabs/dcm
    brew install dcm
  • Activate license:

    Terminal window
    dcm activate --license-key=YOUR_KEY

Then you can run commands like:

Terminal window
dcm check-unused-code lib
dcm check-code-duplication lib

…and configure thresholds (e.g., cyclomatic-complexity) in your analysis options.

What DCM adds:

  • 450+ rules, configurable, many with auto‑fix.
  • Code health metrics (complexity, nesting, parameters, inheritance depth, etc.).
  • Project‑wide checks (unused code/files/localizations, dependency misuse).

7) Tips & troubleshooting#

  • Put analysis_options.yaml at the repo/project root. The analyzer looks there.
  • If “include file not found” appears: it’s usually a path/refresh issue. Confirm the include: line, run dart pub get, and restart your IDE/analyzer.
  • Rules not taking effect? Make sure you added the package as a dev dependency and that your include: is exactly package:theodo_analysis/analysis_options.yaml.

8) Quick comparison#

  • flutter_lints – the official baseline/recommended lints from Flutter. Good starting point, fewer rules than DCM, no metrics.
  • very_good_analysis – a popular curated lint set from Very Good Ventures. theodo_analysis was inspired by this, but it also brings optional DCM integration.

Summary#

  • Use theodo_analysis to get a clean, consistent codebase fast.
  • Add it as a dev dependency and include its options file.
  • Customize: switch rules on/off in analysis_options.yaml.
  • Optional DCM brings powerful extras: unused code checks, metrics, quick fixes—great for growing teams and stricter CI.