Skip to main content

look_good_analyzer 0.2.1+2 copy "look_good_analyzer: ^0.2.1+2" to clipboard
look_good_analyzer: ^0.2.1+2 copied to clipboard

Beyond syntax linting. The Clean Architecture Boundary & Design System Guardian that makes your Flutter codebase truly look good — inside and out.

Look Good Analyzer #

pub package CI License: MIT style: very good analysis

Beyond syntax linting. The Clean Architecture Boundary & Design System Guardian that makes your Flutter codebase truly look good — inside and out.


1. Overview #

In the Flutter world, a codebase can pass standard syntax linters (very_good_analysis, official SDK lints) with 0 warnings and "look good" on the surface, while secretly harboring severe architectural violations inside:

  • Domain layer directly importing dio or database packages.
  • Features tangling their internal Presentation UI directly with other features.
  • Hardcoded numeric paddings (8, 16) and colors scattered everywhere instead of adhering to Design System tokens.
  • UI text and magic string comparisons (status == 'todo') bypassing localization and enums.

look_good_analyzer is built to solve these enterprise architectural challenges through deep AST static inspection.


2. Key Pillars & Unique Capabilities #

Pillar What It Does Why It Makes Your Code Truly Look Good
🛡️ Clean Architecture Guardian Enforces layer isolation (Domain ⇏ Data, Presentation ⇏ Data, Domain ⇏ Flutter, FeatureA ⇏ FeatureB UI). Keeps business logic framework-independent, modular, and maintainable.
🚫 Banned Packages Policy Enforces Zero-GetX policy (package:get/) and bans infrastructure leakage (dio, sqflite, drift) in UI. Guarantees strict State Management & Clean DI discipline across teams.
🎨 Design Token Linter & Auto-Fix Scans numeric literals in EdgeInsets, SizedBox, Gap, BorderRadius and automatically transforms them to tokens (--fix). Guarantees consistent typography, spacing, and radius according to Design System scale.
🔄 Input ➔ Output Token Migration Migrates legacy static tokens (AppSpacing.small) to modern context extensions (context.spacing.sm). Seamlessly upgrades large legacy codebases without manual find-and-replace.
🌐 All-Text UI String Detector Detects unlocalized strings in UI widgets while exempting technical keys (snake_case, paths, URLs). Ensures complete internationalization (l10n) readiness.
🧩 Anti-Magic Strings Guard Detects == and switch against raw string literals in business logic. Eliminates Primitive Obsession in favor of type-safe Enhanced Enums.
🚀 Continuous Watch & CI Tooling Incremental scan in ~15ms on save (--watch), 1-click Git pre-commit hook installer, and GitLab Code Quality JSON export. Elevates Developer Experience (DX) and guards pull requests automatically.

3. Architecture & AST Workflow #

flowchart TD
    CLI["CLI: dart run look_good [--watch] [--fix]"] --> Config["ConfigLoader (look_good_options.yaml / analysis_options.yaml)"]
    Config --> Resolver["FileResolver (globs, includes, excludes)"]
    Resolver --> Runner["AnalysisRunner"]

    subgraph Pure Dart AST Inspection
        Runner --> Parser["analyzer parseString()"]
        Parser --> Visitor["_AstCollector (RecursiveAstVisitor)"]

        Visitor --> R1["Architecture & Banned Packages (No GetX, Presentation isolation)"]
        Visitor --> R2["Design Tokens (Colors, Spacing, Radius, Input-Output Transformers)"]
        Visitor --> R3["All-Text UI Strings (UI widgets, keys exemption)"]
        Visitor --> R4["Anti-Magic Strings (Binary & Switch patterns)"]
        Visitor --> R5["File Line Counter (>250 lines)"]
    end

    R1 --> Issues["Issues Collector"]
    R2 --> Issues
    R3 --> Issues
    R4 --> Issues
    R5 --> Issues

    Issues --> Fix{"Auto-Fix Enabled?"}
    Fix -- Yes --> AutoFix["Safe AST Byte-offset Replacement + Smart Import Injection"]
    Fix -- No --> Reports["Reporters"]
    AutoFix --> Reports

    Reports --> Console["Clickable Terminal Links (file:///path#L10:C5)"]
    Reports --> GitLab["GitLab Code Quality JSON Artifact"]
    Reports --> Exit["Process Exit Code (0 / 1)"]

4. Installation & Setup #

Add look_good_analyzer to your dev_dependencies:

dev_dependencies:
  look_good_analyzer: ^0.1.0

Configure in analysis_options.yaml (or in a dedicated look_good_options.yaml):

look_good_analyzer:
  include:
    - "lib/**"
  exclude:
    - "**/*.g.dart"
    - "**/*.freezed.dart"
    - "build/**"

  rules:
    # 1. Enforce Design Tokens & Auto-Fix
    hardcoded_spacing:
      enabled: true
      severity: warning
      allow_zero: true
      required_import: "package:inite_theme/inite_theme.dart"
      token_mapping:
        4: "AppSpacing.xs"
        8: "AppSpacing.small"
        12: "AppSpacing.medium"
        16: "AppSpacing.large"

    hardcoded_radius:
      enabled: true
      severity: error
      required_import: "package:inite_theme/inite_theme.dart"
      token_mapping:
        4: "AppRadius.xs"
        8: "AppRadius.small"
        12: "AppRadius.medium"
        16: "AppRadius.large"

    # 2. Declarative Token Transformers (Legacy Static -> Context Extension)
    design_tokens:
      transformers:
        - name: "legacy_static_spacing_to_context"
          category: "spacing"
          type: "identifier_replacement"
          input_prefix: "AppSpacing."
          output_prefix: "context.spacing."

    # 3. All-Text UI Strings
    hardcoded_strings:
      enabled: true
      severity: error
      all_strings_mode: true

    # 4. Anti-Magic Strings in Business Logic
    magic_strings:
      enabled: true
      severity: warning

    # 5. Architecture Isolation & Banned Packages
    architecture_imports:
      enabled: true
      severity: error
      banned_packages:
        - "package:get/"
      banned_in_presentation:
        - "package:dio/"
        - "package:sqflite/"
      rules:
        - name: "domain_no_data"
          target: "lib/features/**/domain/**"
          forbidden_from: "lib/features/**/data/**"
          message: "Domain layer must not depend on Data layer"

        - name: "presentation_no_data"
          target: "lib/features/**/presentation/**"
          forbidden_from: "lib/features/**/data/**"
          message: "Presentation layer must not depend on Data layer"

        - name: "features_no_cross_import"
          target: "lib/features/**"
          forbidden_from: "lib/features/**"
          type: "cross_feature"
          message: "Pure Features must not depend on each other directly"

5. CLI Commands & Recipes #

Run Analysis #

# Full analysis
dart run look_good

# Or explicit command
dart run look_good_analyzer:analyze lib/features/auth

Continuous Watch Mode (Local DX) #

Scans files incrementally in ~15ms whenever you press Ctrl+S:

dart run look_good --watch lib

Automated Token Replacement (--fix) #

Automatically rewrites numeric literals and legacy tokens into design system tokens, safely injecting required imports:

dart run look_good --fix

CI/CD Quality Gate & GitLab Integration #

Generate GitLab Code Quality artifacts for Merge Requests:

dart run look_good --format=gitlab --gitlab-output=gl-code-quality-report.json

Install Git Pre-commit Hook #

Enforce quality gate automatically before every commit:

dart run look_good install-hook

6. Architecture Recipes #

Clean Architecture Isolation #

architecture_imports:
  rules:
    - name: "domain_pure"
      target: "lib/features/**/domain/**"
      forbidden_from:
        - "lib/features/**/data/**"
        - "package:flutter/**"
      message: "Domain must remain pure business logic"

MVVM Architecture Isolation #

architecture_imports:
  rules:
    - name: "viewmodel_no_view"
      target: "lib/**/viewmodels/**"
      forbidden_from: "lib/**/views/**"
      message: "ViewModel must not depend on Views"

7. License #

MIT License. See LICENSE for details.

1
likes
160
points
107
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Beyond syntax linting. The Clean Architecture Boundary & Design System Guardian that makes your Flutter codebase truly look good — inside and out.

Repository (GitLab)
View/report issues

License

MIT (license)

Dependencies

analyzer, args, meta, path, yaml

More

Packages that depend on look_good_analyzer