Skip to content

Latest commit

 

History

25 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

apadmi_lints

The Apadmi lint rule set for Dart and Flutter projects, built on top of flutter_lints. It enables a stricter set of additional rules and escalates a number of important lints to analysis errors.

Usage

  1. Add apadmi_lints to your dev_dependencies in pubspec.yaml:

    dev_dependencies:
      apadmi_lints: ^3.0.0
  2. Include the rule set in your analysis_options.yaml:

    include: package:apadmi_lints/apadmi_lints.yaml
  3. Enable the analyzer plugin for the custom rules by adding a top-level plugins section to the root analysis_options.yaml:

    plugins:
      apadmi_lints: ^3.0.0

    Note: the plugins section cannot be inherited through include, so it must be declared in the root analysis_options.yaml of every project — the include line alone does not activate the custom rules.

  4. Restart the Dart Analysis Server so your IDE picks up the plugin (VS Code: "Dart: Restart Analysis Server" from the command palette; IntelliJ/Android Studio: the restart icon in the Dart Analysis panel).

Version 3.x requires Dart 3.10 / Flutter 3.38 or newer (in practice a Flutter version whose SDK ships meta 1.18.0 or newer, i.e. Flutter 3.44+). Older projects can stay on apadmi_lints 2.x, which is identical except for the custom rules.

Custom rules

On top of the standard analyzer lints, this package ships its own rules as a native analyzer plugin.

Flags helper functions, methods, and getters that return Widget (or a subtype). Returning widgets from helpers hides part of the widget tree from Flutter, hurting rebuild granularity, const-ability, and DevTools inspection. Extract a StatelessWidget subclass instead. Overrides such as build are exempt.

// Bad
Widget _buildHeader() => const Text('header');
Widget get _spacer => const SizedBox(height: 8);

// Good
class _Header extends StatelessWidget {
  const _Header();

  @override
  Widget build(BuildContext context) => const Text('header');
}

See the full rule documentation for do/don't examples, the rationale, and how to suppress or disable the rule.

Known issue: on some Dart SDK versions, dart analyze on the command line prints non-plugin diagnostics twice while a plugin is enabled (dart-lang/sdk#63497, fixed upstream). IDE analysis is unaffected. If the analysis server crashes after changing the plugins section, restart it (VS Code: "Dart: Restart Analysis Server"); if the crash persists, clear the server cache by removing ~/.dartServer.

Formatter settings

The configuration also sets the following formatter options:

  • page_width: 120 — lines are formatted to a width of 120 characters.
  • trailing_commas: preserve — trailing commas you write are kept as-is.

Additional rules

The following rules are enabled on top of what flutter_lints (and the underlying core and recommended sets from package:lints) already provides. Each rule links to the official Dart documentation, which explains the rule and includes good/bad examples.

Stricter severities

Violations of the following rules are reported as errors instead of the default severity, so they fail analysis outright.

Runtime crashes and wrong results:

Swallowed exceptions:

Leaks:

Always-wrong comparisons, unreachable branches, and no-op statements:

In addition, the following rules are escalated to warnings — issues to fix before merging, but rarely a crash:

The authoritative list lives in lib/apadmi_lints.yaml under analyzer: errors:.

Excluded files

Analysis is disabled for native folders (android, ios), generated files and assets folders.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages