markup_analyzer 4.0.1 copy "markup_analyzer: ^4.0.1" to clipboard
markup_analyzer: ^4.0.1 copied to clipboard

This tool checks the markup of a Flutter project and generates a report.

MarkupAnalyzer Lint Rule #

Pub Version License Issues Stars

MarkupAnalyzer logo

Description #

Markup Analyzer is a native Dart analyzer plugin that enforces localization in Flutter widgets. It flags raw string expressions passed to widget constructors, encouraging the use of localized strings instead.

The plugin uses the built-in analysis_server_plugin — no additional tools required.

Installation #

Add the plugin to your analysis_options.yaml. No changes to pubspec.yaml required:

plugins:
  markup_analyzer:
    diagnostics:
      simple_string: error
      string_interpolation: error
      adjacent_strings: error
      binary_expression: error
      prefixed_identifier: error
      method_invocation: error
      simple_identifier: false
      function_invocation: false

Configuration #

Each rule is configured independently under plugins: markup_analyzer: diagnostics:.

Set severity to error, warning, or info to enable. Set to false to disable entirely.

Code Description Suggested severity
simple_string Simple string literal error
string_interpolation String interpolation error
adjacent_strings Adjacent string literals error
binary_expression Binary string expression error
prefixed_identifier Prefixed String (e.g. widget.title) warning
method_invocation String-returning method call warning
simple_identifier String variable false
function_invocation String-returning function expression false

Diagnostics #

Code Description
simple_string Simple string literal passed to a widget
string_interpolation String interpolation passed to a widget
adjacent_strings Adjacent string literals passed to a widget
binary_expression Binary string expression (e.g. 'a' + 'b') passed to a widget
prefixed_identifier Prefixed identifier of type String (e.g. widget.title) passed to a widget
method_invocation Method call returning String (e.g. 'x'.tr()) passed to a widget
simple_identifier Variable of type String passed to a widget
function_invocation Function expression returning String passed to a widget

All checks are widget-scoped: only constructor calls of classes that extend Widget are analyzed.

Examples #

Simple string literal #

// BAD
Text('Hello, world!');

// GOOD
Text(AppLocalizations.of(context).greeting);

String interpolation #

// BAD
Text('Hello, $name!');

// GOOD
Text(AppLocalizations.of(context).helloWithName(name));

Adjacent strings #

// BAD
Text(
  'Hello, '
  'world!',
);

Binary expression #

// BAD
Text('Hello, ' + 'world!');

Prefixed identifier #

// BAD
Text(widget.title);

Method invocation #

// BAD
Text('hello'.tr());

// GOOD
Text(AppLocalizations.of(context).hello);

Simple identifier #

// BAD
final String title = 'Hello';
Text(title);

Function invocation #

// BAD
Text((() => 'Hello')());
8
likes
160
points
134
downloads

Documentation

API reference

Publisher

verified publishercontributors.info

Weekly Downloads

This tool checks the markup of a Flutter project and generates a report.

Repository (GitHub)
View/report issues

Topics

#analyzer #linter #script #code-style #format

License

BSD-3-Clause (license)

Dependencies

analysis_server_plugin, analyzer, analyzer_plugin

More

Packages that depend on markup_analyzer