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

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

MarkupAnalyzer Lint Rule #

Pub Version License Issues codecov Stars

Description #

Markup Analyzer is a customizable lint rule for the custom_lint package in Dart/Flutter. It allows you to prohibit specific types of string expressions in the parameters of Flutter widgets.

This rule enables you to control the usage of string expressions such as simple string literals, interpolations, binary expressions, and others based on your configuration.

Installation #

  1. Add the package to your project's dependencies:

    Add the following to your project's pubspec.yaml under dev_dependencies:

    dev_dependencies:
      custom_lint: 
      markup_analyzer: ^latest_version
    
    copied to clipboard
  2. Get the dependencies:

    flutter pub get
    
    copied to clipboard
  3. Activate the plugin in analysis_options.yaml:

    Create or update the analysis_options.yaml file at the root of your project:

    analyzer:
      plugins:
        - custom_lint
    
    custom_lint:
      rules:
        - markup_analyzer
    
    copied to clipboard

Configuration #

You can configure the MarkupAnalyzer rule via analysis_options.yaml by specifying which types of string expressions should be prohibited and the severity level of the error.

Example of a full configuration:

custom_lint:
  rules:
    - markup_analyzer:
      simple: error
      interpolation: warning
      binary: warning
      adjacent: warning
      prefixed_identifier: none
      method: none
      simple_identifier: none
      function: none
copied to clipboard

Usage #

After setting up the plugin and configuring the rules, run the analyzer on your project:

dart run custom_lint
copied to clipboard

All rule violations will be displayed in the console and highlighted in your IDE if it supports custom_lint.

Examples #

1. Simple String Literals (simple) #

Configuration:

custom_lint:
rules:
  markup_analyzer:
    simple: error
copied to clipboard
// BAD
Text('Hello, world!'); // Simple string literal is prohibited.

// OR GOOD
Text(AppLocalizations.of(context).greeting)
copied to clipboard

2. Prefixed Identifiers (prefixed_identifier) #

Configuration:

custom_lint:
rules:
  markup_analyzer:
    prefixed_identifier: error
copied to clipboard
// ERROR
Text(widget.title); // Prefixed identifier is prohibited.
copied to clipboard

3. String Interpolation (interpolation) #

Configuration:

custom_lint:
rules:
  markup_analyzer:
    interpolation: error
copied to clipboard
// BAD
Text('Hello, $name!'); // String interpolation is prohibited.

// GOOD
Text(AppLocalizations.of(context).helloWithName(name)); // Use string concatenation instead.
copied to clipboard

4. Binary Expressions (binary) #

Configuration:

custom_lint:
rules:
  markup_analyzer:
    binary: error
copied to clipboard
// ERROR
Text('Hello, ' + 'world!'); // Binary expression with '+' is prohibited.
copied to clipboard

5. Adjacent Strings (adjacent) #

Configuration:

custom_lint:
rules:
  markup_analyzer:
    adjacent: error
copied to clipboard
// ERROR
Text(
'Hello, '
'world!'
); // Adjacent strings are prohibited.
copied to clipboard

6. Method Invocations (method) #

Configuration:

custom_lint:
rules:
  markup_analyzer:
    method: error
copied to clipboard
// BAD
Text('hello'.tr()); // Method invocation is prohibited.

//GOOD
Text(AppLocalizations.of(context).hello)
copied to clipboard

7. Simple Identifiers (simple_identifier) #

Configuration:

custom_lint:
rules:
  markup_analyzer:
    simple_identifier: error
copied to clipboard
// ERROR
Text(title); // Simple identifier is prohibited.
copied to clipboard

8. Function Invocations (function) #

Configuration:

custom_lint:
rules:
  markup_analyzer:
    function: error
copied to clipboard
// ERROR
Text(() { return 'Hello' } ()); // Function invocation is prohibited.

copied to clipboard
Loading
6
likes
150
points
85
downloads

Publisher

verified publishercontributors.info

Weekly Downloads

2024.10.07 - 2025.09.01

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

Homepage
Repository (GitHub)
View/report issues

Topics

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

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

analyzer, analyzer_plugin, collection, custom_lint_builder

More

Packages that depend on markup_analyzer