markup_analyzer 4.0.3 copy "markup_analyzer: ^4.0.3" to clipboard
markup_analyzer: ^4.0.3 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 — but the entry must carry a source, otherwise the analyzer parses the block, finds nothing to resolve, and silently loads no plugin at all (no error, just zero diagnostics):

plugins:
  markup_analyzer:
    version: ^version
    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

Any of pub's source formats works in place of version:

plugins:
  # From pub.dev.
  markup_analyzer: ^4.0.2

  # From another host.
  markup_analyzer:
    version: ^4.0.2
    hosted: https://my-pub-host.dev

  # From git.
  markup_analyzer:
    git:
      url: https://github.com/AlexHCJP/markup_analyzer.git
      ref: main

  # From a local checkout.
  markup_analyzer:
    path: ../markup_analyzer

The short markup_analyzer: ^4.0.2 form takes no diagnostics: block — use the nested form whenever you want to configure severities.

Verify the plugin is live by running dart analyze from the package root, with no target. Passing a subdirectory (dart analyze lib) makes that directory the analysis context root; with no pubspec.yaml there the plugin cannot be resolved, and the run reports "No issues found" even where the plugin would fire.

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')());
9
likes
0
points
182
downloads

Publisher

verified publisherbangertstudio.kz

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

unknown (license)

Dependencies

analysis_server_plugin, analyzer

More

Packages that depend on markup_analyzer