feat: Recreate mix_lint using analysis_server plugin#871
Merged
tilucasoli merged 16 commits intomainfrom Mar 6, 2026
Merged
Conversation
|
To view this pull requests documentation preview, visit the following URL: Documentation is deployed and generated using docs.page. |
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
This reverts commit fcfe97c.
4115821 to
6e6b97e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 singlelib/main.dartentry point, and exposes lint rules as configurable diagnostics. The package no longer depends oncustom_lint_builderoranalyzer_plugin; it now depends onanalysis_server_pluginand the currentanalyzerAPI. All six rules are reimplemented under the new plugin and rule contracts, with updated README and tests.Changes
lib/main.dartexporting apluginvariable (MixLintPlugin) that registers all rules withPluginRegistry.registerLintRule().lib/src/rules/usingAnalysisRuleand the analyzer’sRuleVisitorRegistry:mix_avoid_defining_tokens_within_stylemix_avoid_defining_tokens_within_scopemix_avoid_empty_variantsmix_max_number_of_attributes_per_stylemix_variants_lastmix_mixable_styler_has_createlib/src/utils/type_helpers.dartfor Styler/Scope/Token type checks used by the rules.plugins: mix_lint: any), per-diagnostic configuration underplugins.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.test/for each rule (e.g.mix_avoid_defining_tokens_within_style_test.dart) plustest/src/mix_stub.dartfor test dependencies.createPlugin(),lib/mix_lint.dart), old lints/assists/extensions, and legacy docs that referred to custom_lint.pubspec.yamlupdated to useanalysis_server_plugin: ^0.3.0andanalyzer: ">=8.4.0 <12.0.0"; added dev_dependenciesanalyzer_testing,test_reflective_loader.analysis_options.yamlupdated to reflect the new plugin structure (e.g. no custom_lint includes).Review checklist
melos run test:dart(or equivalent) inpackages/mix_lint.plugins: mix_lint: any(or withdiagnostics:) inanalysis_options.yamland use// ignore: mix_lint/<rule_name>. Requires Dart ≥ 3.10 / Flutter ≥ 3.38.Additional information
// ignore: mix_lint/<diagnostic_code>(e.g.// ignore: mix_lint/mix_variants_last).diagnostics:inanalysis_options.yamlwhen using the map form;mix_lint: anyenables the plugin but individual diagnostics can be toggled.