Skip to content

feat: Recreate mix_lint using analysis_server plugin#871

Merged
tilucasoli merged 16 commits intomainfrom
feat/recreate-mix-lint-for-mix-v2
Mar 6, 2026
Merged

feat: Recreate mix_lint using analysis_server plugin#871
tilucasoli merged 16 commits intomainfrom
feat/recreate-mix-lint-for-mix-v2

Conversation

@tilucasoli
Copy link
Collaborator

@tilucasoli tilucasoli commented Mar 3, 2026

Description

Migrates mix_lint from the custom_lint_builder-based setup to the official Analysis Server plugin API (analysis_server_plugin). This aligns mix_lint with the first-party Dart 3.10+ plugin model, uses a single lib/main.dart entry point, and exposes lint rules as configurable diagnostics. The package no longer depends on custom_lint_builder or analyzer_plugin; it now depends on analysis_server_plugin and the current analyzer API. All six rules are reimplemented under the new plugin and rule contracts, with updated README and tests.

Changes

  • Plugin entry point: Added lib/main.dart exporting a plugin variable (MixLintPlugin) that registers all rules with PluginRegistry.registerLintRule().
  • Rule implementations: New rule classes under lib/src/rules/ using AnalysisRule and the analyzer’s RuleVisitorRegistry:
    • mix_avoid_defining_tokens_within_style
    • mix_avoid_defining_tokens_within_scope
    • mix_avoid_empty_variants
    • mix_max_number_of_attributes_per_style
    • mix_variants_last
    • mix_mixable_styler_has_create
  • Shared utilities: Added lib/src/utils/type_helpers.dart for Styler/Scope/Token type checks used by the rules.
  • Documentation: Updated README with plugin setup (plugins: mix_lint: any), per-diagnostic configuration under plugins.mix_lint.diagnostics, and suppression format // ignore: mix_lint/<rule_name>. Rule docs (with Don’t/Do examples) kept and aligned with the new diagnostic names.
  • Tests: New tests under test/ for each rule (e.g. mix_avoid_defining_tokens_within_style_test.dart) plus test/src/mix_stub.dart for test dependencies.
  • Removed: Previous custom_lint-based API (e.g. createPlugin(), lib/mix_lint.dart), old lints/assists/extensions, and legacy docs that referred to custom_lint.
  • Dependencies and config: pubspec.yaml updated to use analysis_server_plugin: ^0.3.0 and analyzer: ">=8.4.0 <12.0.0"; added dev_dependencies analyzer_testing, test_reflective_loader. analysis_options.yaml updated to reflect the new plugin structure (e.g. no custom_lint includes).

Review checklist

  • Testing: Unit tests added for each rule; run with melos run test:dart (or equivalent) in packages/mix_lint.
  • Breaking changes: Yes. Consumers must switch from custom_lint config to the Analysis Server plugin: add plugins: mix_lint: any (or with diagnostics:) in analysis_options.yaml and use // ignore: mix_lint/<rule_name>. Requires Dart ≥ 3.10 / Flutter ≥ 3.38.
  • Documentation: README and in-repo rule docs updated; no separate website doc changes in this PR.
  • Website: No website updates in this PR.

Additional information

  • Suppress format is // ignore: mix_lint/<diagnostic_code> (e.g. // ignore: mix_lint/mix_variants_last).
  • Rules are opt-in via diagnostics: in analysis_options.yaml when using the map form; mix_lint: any enables the plugin but individual diagnostics can be toggled.
  • Minimum Dart SDK is already 3.11.0 in the repo; the plugin supports Dart 3.10+ as per the official analyzer plugin docs.

@docs-page
Copy link

docs-page bot commented Mar 3, 2026

To view this pull requests documentation preview, visit the following URL:

docs.page/btwld/mix~871

Documentation is deployed and generated using docs.page.

@vercel
Copy link
Contributor

vercel bot commented Mar 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mix-docs Ready Ready Preview, Comment Mar 6, 2026 1:33am

Migrate mix_lint from the custom_lint-based builder to an Analysis Server plugin. Adds lib/main.dart plugin entrypoint and new rule implementations under src/rules, updates README and docs to show plugin usage and individual diagnostics, and adds tests and helper utilities (e.g. type_helpers). Removes the old custom_lint-based API, assorted lints/assists, extensions and legacy docs, and updates analysis_options.yaml and pubspec.yaml accordingly to reflect the new plugin structure.
Refactor several lint rule implementations: make all _Visitor constructors const, move LintCode (diagnosticCode) getters into the rule classes, and tidy method ordering/formatting. Adjust MixMixableStylerHasCreate to only consider BlockClassBody members for the presence of a named 'create' constructor and report on the class name part (node.namePart) to improve accuracy. Minor change in main.dart: move the plugin name getter to the end of the class for consistency.
Introduce a new lint rule that prefers Dart dot-shorthand calls (e.g. .all(10), .w600, .color(...)) when the target type can be inferred. Adds the rule implementation, registers it in the plugin, and includes unit tests, documentation, and README/examples updates. Also updates pubspec to add analyzer_plugin, and extends the test stubs to cover the new cases. This keeps Mix API usage more concise and documents the requirement (Dart 3.11+ noted in README).
Ensure the mix_prefer_dot_shorthands rule only recommends the leading-dot shorthand when the static member's static type is the same as the declaring class. Added helper methods to resolve the declaring class type and compare it to the expression's static type, and wired the check into MethodInvocation, PropertyAccess, PrefixedIdentifier, and InstanceCreationExpression handling. Updated documentation to clarify the Colors.blue (Color vs Colors) example, added a test to assert no diagnostic for static members with a different return type, and expanded the test stub with Colors/Color classes. Also added necessary imports.
Add a quick-fix for MixPreferDotShorthands and tests. Implements MixPreferDotShorthandsFix (correction producer) and registers it in mix_lint plugin main. Update the rule to ignore static members declared in extensions. Add tests for the fix plus a test helper (applyQuickFixForResult) and a mix test stub update. Also reorganize existing tests into test/src/rules and update their imports accordingly.
Apply minor formatting changes: collapse a multi-line StateError throw into a single line, reflow the getResolvedLibraryContaining call arguments onto separate lines, and adjust a test function signature line break in mix_prefer_dot_shorthands_test.dart. These are stylistic changes only and do not alter logic or behavior.
@tilucasoli tilucasoli force-pushed the feat/recreate-mix-lint-for-mix-v2 branch from 4115821 to 6e6b97e Compare March 6, 2026 01:25
@tilucasoli tilucasoli merged commit f101a66 into main Mar 6, 2026
8 checks passed
@tilucasoli tilucasoli deleted the feat/recreate-mix-lint-for-mix-v2 branch March 6, 2026 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant