design_token_lints

pub package pub points CI coverage license: MIT

Lint rules for your Flutter design system, built on Dart's official analyzer plugin system.

  • Flag raw colors, magic spacing, hand-written radii, text styles, shadows, icon sizes and elevations, and raw widgets that have a design-system replacement, in your IDE and in dart analyze.
  • Fix each one with a quick fix that inserts the matching token from your own classes (AppColors.primary, AppSpacing.md) or ThemeExtension (context.palette.brand) and adds the import, or all of them at once with design_token_lints fix.
  • Measure how much of your UI uses the design system, counting your tokens and Material's ColorScheme and TextTheme, with design_token_lints coverage, and fail CI below a threshold.
  • Adopt gradually in an existing app: design_token_lints baseline accepts today's raw values, so only new ones are reported.

Quick fix replacing a raw color with a token

Watch: quick fixes in VS Code · coverage from 43% to 90% in the terminal

Contents: Getting started · Example app · What it reports · Configuration · Rules · Fix everything · Baseline · Coverage · Limitations · How this compares · Roadmap

Getting started

Requirements: Dart 3.11 or later (dart --version).

  1. Tell the analyzer to load the plugin, in the analysis_options.yaml at the root of your package (or workspace):

    plugins:
      design_token_lints: ^0.3.0
    
  2. Describe your design system. Add this to the same file, or to a design_token_lints.yaml next to pubspec.yaml:

    design_token_lints:
      design_system:
        paths: [lib/design_system/**]
      tokens:
        color:   { class: AppColors,  file: lib/design_system/app_colors.dart }
        spacing: { class: AppSpacing, file: lib/design_system/app_spacing.dart }
    
  3. Restart the Dart analysis server (in VS Code: Dart: Restart Analysis Server). Raw values in your code are now reported, with quick fixes.

Nothing is reported for a category until you configure its tokens, so you can adopt one category at a time.

Note: on the command line and in CI, run dart analyze. flutter analyze does not show analyzer plugin diagnostics, so with it the plugin looks like it is doing nothing.

Install the plugin only through analysis_options.yaml, never as a dependency in pubspec.yaml. The analysis server resolves plugins in its own package, so adding it to pubspec.yaml would only add its analyzer constraint to your app.

Example app

The example app is a small shop with a design system in lib/design_system/ and two versions of the same checkout screen:

Open the example in your IDE to try the quick fixes, or run design_token_lints coverage in it.

What it reports

Rule Severity Flags
avoid_raw_color warning Color(0xFF…), Color.fromARGB/fromRGBO/from, Colors.*
avoid_magic_spacing warning numeric literals in EdgeInsets, SizedBox, Gap
avoid_raw_radius warning BorderRadius.circular(8), Radius.circular(8)
avoid_inline_text_style warning TextStyle(...) written by hand
avoid_raw_shadow info BoxShadow(...) and lists of them
avoid_raw_icon_size warning Icon(size: 22), IconButton(iconSize:), IconThemeData(size:)
avoid_raw_elevation warning elevation: on Card, Material, AppBar, buttons' styleFrom and more
prefer_design_system_component warning raw widgets that have a replacement

All rules are on by default. Every rule skips the design-system files, the token files themselves, generated files, and anything you exclude.

To turn a rule off or change its severity, give the plugin entry a version and a diagnostics section:

plugins:
  design_token_lints:
    version: ^0.3.0
    diagnostics:
      avoid_raw_shadow: false
      avoid_magic_spacing: error

To silence one report:

// ignore: design_token_lints/avoid_raw_color
const legacyBlue = Color(0xFF123456);

// ignore_for_file: design_token_lints/<rule> silences a rule for a file.

Configuration

The plugin framework has no per-rule options yet, so the plugin reads its own configuration. It looks for, in this order:

  1. design_token_lints.yaml next to pubspec.yaml, or
  2. a top-level design_token_lints: section in analysis_options.yaml at the package root.

If both exist, the standalone file wins; they are not merged. The top-level section is not inherited through include:, because it is read from the package's own analysis_options.yaml only. In a pub workspace, a member package without its own configuration uses the one at the workspace root.

The configuration is found from the package that contains the analyzed file, cached per package, and reloaded when the configuration or a token file changes. A malformed configuration never crashes the analyzer: the plugin reports nothing, and design_token_lints check-config prints what is wrong.

design_token_lints:
  # Files where raw values legitimately live. Globs are relative to the
  # directory that holds the configuration. The token files themselves are
  # always exempt.
  design_system:
    paths: [lib/design_system/**, lib/theme/**]
    packages: [acme_design_system]   # exempt by package name (workspaces)

  # Your existing token classes. A token is a `static const` member; no
  # annotations or code generation. `file` is a path relative to the
  # configuration, or a package: URI for tokens in a dependency.
  tokens:
    color:      { class: AppColors,     file: lib/design_system/app_colors.dart }
    spacing:    { class: AppSpacing,    file: lib/design_system/app_spacing.dart }
    radius:     { class: AppRadius,     file: lib/design_system/app_radius.dart }
    typography: { class: AppTypography, file: lib/design_system/app_typography.dart }
    shadow:     { class: AppShadows,    file: package:acme_design_system/shadows.dart }
    icon_size:  { class: AppIconSize,   file: lib/design_system/app_icon_size.dart }
    elevation:  { class: AppElevation,  file: lib/design_system/app_elevation.dart }

  # Values that are always fine.
  allow:
    color: [Colors.transparent, 0xFF000000]   # Colors.<name> or an ARGB value
    spacing: [0, 2]                           # 0 is always allowed
    radius: [999]
    icon_size: [18]
    elevation: [1]

  # When to offer "nearest token" fixes. 0 (the default) means exact only.
  matching:
    spacing_tolerance: 0     # logical pixels
    radius_tolerance: 0      # logical pixels
    icon_size_tolerance: 0   # logical pixels
    elevation_tolerance: 0
    color_delta_e: 2.0       # CIEDE2000; around 2 is "barely noticeable"

  # Raw widgets and what replaces them.
  components:
    ElevatedButton: { replacement: AppButton, import: package:acme_ui/acme_ui.dart }
    Text:           { replacement: AppText,   import: package:acme_ui/acme_ui.dart }

  # Files no rule applies to. Generated files (`*.g.dart`, `*.freezed.dart`,
  # and files with a "GENERATED CODE" header) are skipped without listing them.
  exclude: ["**/*.g.dart", "**/*.freezed.dart", "test/**"]

  # Exclusions for a single rule.
  rules:
    avoid_magic_spacing: { exclude: [lib/legacy/**] }

How tokens are found

Each configured token file is parsed, without resolution and without a build step, and every static const member of the configured class is evaluated statically. These forms are understood:

  • numbers, including arithmetic and references to other constants in the same class or file (static const lg = md * 1.5;);
  • Color(0xAARRGGBB), Color.fromARGB, Color.fromRGBO, Color.from, and Colors.*;
  • Radius.circular, BorderRadius.circular, BorderRadius.all(Radius.circular(…));
  • TextStyle(fontSize:, fontWeight:, height:, letterSpacing:);
  • BoxShadow(...) and lists of them, with Offset(dx, dy).

Members that cannot be evaluated (computed values, static final, getters) are skipped. design_token_lints check-config lists them.

ThemeExtension tokens

Tokens that live in a ThemeExtension are read from one of its static const instances. Name the instance, and say how code reads a token:

class AppPalette extends ThemeExtension<AppPalette> {
  const AppPalette({required this.brand, required this.surface});
  final Color brand;
  final Color surface;

  static const light = AppPalette(
    brand: Color(0xFF6750A4),
    surface: Color(0xFFFEF7FF),
  );
  // copyWith, lerp …
}

extension PaletteContext on BuildContext {
  AppPalette get palette => Theme.of(this).extension<AppPalette>()!;
}
tokens:
  color:
    class: AppPalette
    file: lib/theme/app_palette.dart
    instance: light
    access: "context.palette.{name}"   # optional
    import: package:acme/theme.dart    # optional: the library a fix imports

Each argument of the instance's constructor call is a token, mapped to its field through the constructor's this.field parameter; an argument that does not initialize a field is skipped. Without access, tokens read as Theme.of(context).extension<AppPalette>()!.brand.

Messages always name the token, for example Try using context.palette.brand. The fix, in the IDE and in design_token_lints fix, is offered only where the result compiles: where a BuildContext context is in scope (a parameter, an untyped builder parameter such as (context) => …, or an instance member of a State) and not in a constant or a default value. Elsewhere, fix reports the value as matching a token that cannot be used there.

Reads of the extension's fields (context.palette.brand, Theme.of(context).extension<AppPalette>()!.surface) count as token uses in coverage.

Rules

avoid_raw_color

Flags Color(0xFF…), Color.fromARGB, Color.fromRGBO, Color.from, and Colors.<name>, including Colors.red.shade100 and Colors.red[100], unless allow-listed. Colors must be Flutter's class, from package:flutter or package:material_ui; your own Colors is ignored. Allowed: AppColors.primary, Theme.of(context).colorScheme.primary.

// Bad
Container(color: const Color(0xFF1E88E5))

// Good
Container(color: AppColors.primary)

Fix. An exact ARGB match offers Replace with AppColors.primary. When a token has the same value as another (an alias), both are offered. With matching.color_delta_e set, close colors also offer Replace with nearest token AppColors.primary (ΔE 1.3), at lower priority, up to three candidates. A color with a different alpha is never a nearest match.

A translucent color whose red, green and blue equal an opaque token, such as Color(0x801E88E5), offers Replace with AppColors.primary.withValues(alpha: 0.5). The alpha is written with two decimals, or three when two would change the 8-bit value (0x7F becomes 0.498), so the color stays the same. This fix is not offered where a method call is not allowed: in a constant context (const variables and collections) or in a parameter's default value.

avoid_magic_spacing

Flags numeric literals in EdgeInsets.all/symmetric/only/fromLTRB, EdgeInsetsDirectional.*, SizedBox(width:, height:), SizedBox.square, and Gap / SliverGap. 0, values in allow.spacing, negative numbers and non-literal expressions are ignored.

// Bad
Padding(padding: const EdgeInsets.all(16))

// Good
Padding(padding: const EdgeInsets.all(AppSpacing.md))

Fix. Replace 16 with AppSpacing.md. Within matching.spacing_tolerance, Replace 15 with nearest token AppSpacing.md (Δ1). Tokens at the same distance are all offered.

avoid_raw_radius

Flags BorderRadius.circular(n), BorderRadius.all(Radius.circular(n)), Radius.circular(n), and each corner of BorderRadius.only/vertical/horizontal.

// Bad
BorderRadius.circular(8)

// Good
BorderRadius.circular(AppRadius.md)   // a double token
AppRadius.card                        // a BorderRadius token

Fix. The surrounding constructor is kept when the token is a double, and the whole expression is replaced when the token is a Radius or BorderRadius. Nearest matches use matching.radius_tolerance.

avoid_inline_text_style

Flags TextStyle(...) written outside the design system, including inside Text(style:) and DefaultTextStyle. Allowed: AppTypography.body, Theme.of(context).textTheme.bodyMedium, and .copyWith(color: …) on a token.

// Bad
Text('Total', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold))

// Good
Text('Total', style: AppTypography.title)

Fix. Offered only when fontSize and fontWeight (and height and letterSpacing, which must agree in both directions) exactly match one token. If the style also sets color, the fix is AppTypography.title.copyWith(color: …), except in a const context, where no fix is offered. Any other argument (fontFamily, decoration, …) means no fix.

avoid_raw_shadow

Severity: info. Flags BoxShadow(...) and List<BoxShadow> literals. A list is reported once, not per element.

// Bad
BoxDecoration(boxShadow: [BoxShadow(color: Color(0x1A000000), blurRadius: 8)])

// Good
BoxDecoration(boxShadow: AppShadows.card)

Fix. Only on an exact structural match with a shadow token (same layers, colors, blur, spread and offset).

avoid_raw_icon_size

Flags numeric literals for icon sizes: Icon(size:), ImageIcon(size:), IconButton(iconSize:) (and its filled, filledTonal and outlined variants) and IconThemeData(size:). 0, negative numbers, values in allow.icon_size and non-literal expressions are ignored.

// Bad
Icon(Icons.person, size: 24)

// Good
Icon(Icons.person, size: AppIconSize.md)

Fix. Replace 24 with AppIconSize.md. Within matching.icon_size_tolerance, Replace 23 with nearest token AppIconSize.md (Δ1).

avoid_raw_elevation

Flags numeric literals for Material elevation: elevation: on Material, Card, AppBar and SliverAppBar (also scrolledUnderElevation:), BottomAppBar, NavigationBar, Drawer, Dialog, AlertDialog, BottomSheet, PopupMenuButton, Chip, FloatingActionButton and its variants, PhysicalModel, PhysicalShape, and the styleFrom of ElevatedButton, FilledButton, OutlinedButton and TextButton. 0 and values in allow.elevation are ignored.

// Bad
Card(elevation: 2, child: content)

// Good
Card(elevation: AppElevation.card, child: content)

Fix. Replace 2 with AppElevation.card, and nearest matches within matching.elevation_tolerance.

prefer_design_system_component

Flags construction of a Flutter widget listed under components:, from package:flutter, package:material_ui or package:cupertino_ui. The widget is matched through its resolved element, so your own Text class is never reported.

// Bad
ElevatedButton(onPressed: save, child: Text('Save'))

// Good
AppButton(onPressed: save, child: AppText('Save'))

Fix. Replace ElevatedButton with AppButton: the class name is renamed, the constructor name and the arguments are kept, and the configured import is added (or reused, including an existing prefixed import). The fix only renames; making the arguments compatible with the replacement is up to you.

Fix everything

The IDE applies quick fixes one at a time. To apply every exact fix in a project at once, use the command line tool:

dart pub global activate design_token_lints
design_token_lints fix --dry-run   # list what would change
design_token_lints fix             # apply it
lib/screens/legacy_checkout.dart
  12:37  16 -> AppSpacing.md
  15:16  const Color(0xFFFAFAFA) -> AppColors.surface
  51:11  ElevatedButton -> AppButton
  ...

Fixed 16 issues in 1 file. Run "dart format" if any line got too long.

7 issues have no exact token; "dart analyze" lists them.

It runs the same detectors as the plugin and adds imports the same way. It applies only fixes with exactly one exact token:

  • Nearest matches are never applied. Turning 15 into AppSpacing.md changes the design, so it is left to a person in the IDE.
  • Two tokens with the same value are listed, not fixed, so you choose.
  • A fix inside another fix (a color inside a shadow that matches a shadow token) is listed; run the command again.
  • // ignore: and // ignore_for_file: comments are honored.
design_token_lints fix [path] [--dry-run] [--rule avoid_raw_color,avoid_magic_spacing]

--dry-run changes nothing and exits with code 1 when there is something to fix, so CI can require that exact fixes are applied. --rule limits the fix to some rules.

Baseline for existing apps

Switching the plugin on in a large app can report hundreds of raw values at once. A baseline accepts today's values, so only new ones are reported:

design_token_lints baseline
Wrote design_token_lints.baseline.yaml: 23 raw values in 1 file.

Commit design_token_lints.baseline.yaml; it sits next to the configuration and is picked up without restarting the analysis server. From then on the IDE and dart analyze stay quiet about the accepted values and report every new one, so the design system can only gain ground.

  • Moving or reformatting code keeps a value accepted. A value is identified by its file, its rule and its code (for example EdgeInsets.all(16) in lib/screens/checkout.dart), not by its line.
  • Adding the same value again is reported. The baseline records how many times each value occurs in a file; further occurrences are new.
  • Coverage stays honest. coverage still counts accepted values as raw values, and says how many are in the baseline.
  • Shrink it as you go. After fixing some values (for example with design_token_lints fix), run design_token_lints baseline again. Running it on a subdirectory rewrites only that part of the file.

Coverage

dart pub global activate design_token_lints
design_token_lints coverage
Design system coverage: 42% (colors 25%, spacing 42%, radius 33%, typography 50%, shadows 50%, components 50%) — 7 magic spacing values in 1 file

Coverage of a category is token uses / (token uses + raw values). A token use is a reference to a static member of a configured token class (or a use of a configured replacement widget); a raw value is what the rules above report. The overall figure weights every use and every raw value equally. It runs the same detectors as the plugin, so the numbers match what the IDE shows.

Colors read from Flutter's ColorScheme and text styles read from its TextTheme count as uses too, because they come from the app's theme: Theme.of(context).colorScheme.primary, ColorScheme.of(context).surface, Theme.of(context).textTheme.bodyMedium, or a local scheme.primary. They are recognized by type, from package:flutter or package:material_ui, so a class of your own with the same name does not count.

Install the command line tool globally, not as a dev dependency. A dev dependency would add the analyzer's version constraints to your project.

design_token_lints coverage [path] [--format console|json|markdown]
                            [--output file] [--fail-under 80]
                            [--category color,spacing,radius,typography,shadow,icon_size,elevation,component]
design_token_lints fix [path] [--dry-run] [--rule rule,...]
design_token_lints baseline [path]
design_token_lints check-config [path]
Option Meaning
--format console (default), json (with "schemaVersion": 1), or markdown
--output write the report to a file; a one-line summary goes to the console
--fail-under N exit with code 1 if overall coverage is below N percent
--category measure only these categories

Exit codes: 0 success, 1 coverage below --fail-under, 2 usage or configuration error. check-config validates the configuration and prints every token it found and every member it skipped.

The JSON report has totals, per-categories statistics, per-rules counts, baselined (how many findings a baseline accepts), and files with each finding's line, column, rule, message, suggestedToken and baselined.

In CI

This GitHub Actions job keeps one "sticky" comment on each pull request up to date, and fails the build below 80%:

name: Design system coverage
on: pull_request

permissions:
  contents: read
  pull-requests: write

jobs:
  coverage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: subosito/flutter-action@v2
      - run: flutter pub get
      - run: dart pub global activate design_token_lints
      - name: Measure coverage
        id: coverage
        run: |
          set +e
          design_token_lints coverage --format markdown --output coverage.md --fail-under 80
          echo "status=$?" >> "$GITHUB_OUTPUT"
      - uses: marocchino/sticky-pull-request-comment@v2
        with:
          header: design-token-lints
          path: coverage.md
      - name: Enforce the threshold
        if: steps.coverage.outputs.status != '0'
        run: exit ${{ steps.coverage.outputs.status }}

Run the plugin's diagnostics in CI with dart analyze:

- run: dart analyze

Limitations

  • Restart the analysis server after you edit the plugins: section of analysis_options.yaml. Changes to the design_token_lints configuration and to token files need no restart: they are picked up the next time a file is analyzed, so touch (or reopen) a file to see them.
  • Plugins are configured at the root only. Declare the plugin in the analysis_options.yaml at the package or workspace root; the analyzer ignores plugin declarations in nested options files.
  • The design_token_lints: section is not inherited through include:. Put it in the package's own analysis_options.yaml, or use design_token_lints.yaml.
  • Use dart analyze, not flutter analyze, in CI. flutter analyze does not report this plugin's diagnostics.
  • Workspaces. The plugin keeps a small configuration and token cache for each configuration root. In a large workspace, give packages that share a design system one configuration at the workspace root rather than one each.
  • Names are matched, not resolved, for constructors. EdgeInsets, SizedBox, Gap, BorderRadius, Radius, TextStyle, BoxShadow, Color, and the icon and elevation widgets are recognized by name, so a class of your own with one of those names and constructor shapes is treated the same way. Colors and the classes under components: are checked through the resolved element.
  • Tokens must be constant. static final members, getters and values that need runtime evaluation are not read. ThemeExtension tokens are read from a static const instance (see ThemeExtension tokens).
  • "Context in scope" is checked by name. A ThemeExtension fix that uses context is offered next to a parameter called context typed BuildContext (or untyped, as in builders) or inside a State, not next to a context with another name.
  • No dart fix. The analysis server does not apply plugin fixes in bulk, so dart fix ignores them. Use design_token_lints fix instead.

How this compares

Compared with tools that also target design tokens or banned usages, as each project documents itself (November 2026):

design_token_lints house_rules design_system_lints DCM banned-usage
Runs in IDE and dart analyze (analyzer plugin) Command line and editor hook IDE (Sidecar plugin) IDE and command line
Analysis Parsed code, plus resolved elements for Colors and components Parsed code and source text; no resolved types Not documented Not documented
Token source Your existing static const classes String-keyed token maps and a palette class Classes annotated with @designSystem None: you list banned names
Fix to your token Exact and nearest matches, import added Suggestions only ("did you mean") "Code edits", not described Not documented
Coverage metric Yes, with a CI threshold Not documented; a baseline of finding counts Not documented Not documented
Price, latest release Free (MIT), 2026 Free (MIT), 2026 Free (MIT), 2023 Paid plans

General rule sets such as many_lints, altive_lints and clean_code_lints cover different ground and run side by side with this plugin in analysis_options.yaml.

Roadmap

  • More token sources: importing tokens from Figma, Tokens Studio and the W3C Design Tokens format.
  • More categories: motion (durations and curves) and opacity tokens.
  • CI output: SARIF from the coverage command.
  • Plugin platform: per-rule options in analysis_options.yaml once the SDK supports them (dart-lang/sdk#63098), and dart fix support once plugin fixes allow it.

Suggestions are welcome in the issue tracker.

Acknowledgements

Pat O'Brien's design_system_lints first showed that a design system can be linted. Thanks to the Dart team for the analyzer plugin system this package is built on.

Licensed under the MIT License.

Libraries

design_token_lints
Enforce your Flutter design system with analyzer lints, quick fixes and a coverage report.
main