Skip to content

Migrate/proper super calls#229

Merged
solid-vovabeloded merged 10 commits intoanalysis_server_migrationfrom
migrate/proper_super_calls
Apr 21, 2026
Merged

Migrate/proper super calls#229
solid-vovabeloded merged 10 commits intoanalysis_server_migrationfrom
migrate/proper_super_calls

Conversation

@Islam-Shaaban-Ibrahim
Copy link
Copy Markdown
Collaborator

No description provided.

@Islam-Shaaban-Ibrahim Islam-Shaaban-Ibrahim changed the base branch from master to analysis_server_migration April 15, 2026 13:42
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the solid_lints package to utilize the analysis_server_plugin and migrates several lint rules—AvoidDebugPrintInReleaseRule, AvoidGlobalStateRule, and ProperSuperCallsRule—to a visitor-based architecture. It also introduces a new test suite for these rules. Review feedback highlights that ProperSuperCallsRule is missing its import and registration in the main plugin file. Additionally, there are recommendations to improve the detection logic in AvoidDebugPrintInReleaseRule by replacing unreliable string-based URI and expression checks with more robust AST and element resolution.

I am having trouble creating individual review comments. Click here to see my feedback.

lib/main.dart (4)

high

The import for ProperSuperCallsRule is missing, which is required for its registration.

import 'package:solid_lints/src/lints/avoid_global_state/avoid_global_state_rule.dart';
import 'package:solid_lints/src/lints/proper_super_calls/proper_super_calls_rule.dart';

lib/main.dart (21-28)

high

The ProperSuperCallsRule is not registered in the plugin. Given the PR title specifically mentions this rule, it should be included in the register method.

  void register(PluginRegistry registry) {
    registry.registerLintRule(
      AvoidGlobalStateRule(),
    );
    registry.registerLintRule(
      AvoidDebugPrintInReleaseRule(),
    );
    registry.registerLintRule(
      ProperSuperCallsRule(),
    );
  }

lib/src/lints/avoid_debug_print_in_release/visitors/avoid_debug_print_in_release_visitor.dart (39-41)

high

The check sourceUri.contains(_foundationUri) will likely fail for standard Flutter usage. debugPrint is defined in package:flutter/src/foundation/print.dart, which does not contain the string package:flutter/foundation.dart. A more robust check would be to verify if the URI starts with package:flutter/ and contains foundation.

      final isFlutterFoundation = sourceUri.startsWith('package:flutter/') &&
          sourceUri.contains('foundation');

lib/src/lints/avoid_debug_print_in_release/visitors/avoid_debug_print_in_release_visitor.dart (58)

medium

Using toString().contains() on an expression is unreliable for logic as it can lead to false negatives (e.g., if a variable name happens to contain the substring). It is better to inspect the AST nodes and resolve the elements to ensure they refer to the expected constants from the Flutter foundation library.

import 'package:solid_lints/src/lints/avoid_debug_print_in_release/avoid_debug_print_in_release_rule.dart';

/// Visitor for [AvoidDebugPrintInReleaseRule].
class AvoidDebugPrintInReleaseVisitor extends SimpleAstVisitor<void> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think it should be in this PR.

final hasOverride = node.metadata.any(
(annotation) => annotation.name.name == _override,
);
if (!hasOverride) return;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if we could check if this method overrides Flutter's State class.

Comment on lines +70 to +71
@override
LintCode get diagnosticCode => _superInitStateCode;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we are repeating the same statements from rule to rule. It would be great if we could have something as we did before - SolidLintRule. It would allow us to get rid of boilerplate code and make our code cleaner.

Comment on lines +79 to +86
onViolation: (nameToken, {required bool isInitState}) {
// Access the reporter from the currentUnit
final reporter = context.currentUnit?.diagnosticReporter;

reporter?.atToken(
nameToken,
isInitState ? _superInitStateCode : _superDisposeCode,
);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we passing this logic as a closure? Does it make sense to encapsulate it in the visitor as we do for all other rules?

Comment thread test/proper_super_calls_rule_test.dart Outdated
String get analysisRule => ProperSuperCallsRule.lintName;

/// Mocks the Flutter framework parts relevant to this lint.
String get _flutterBase => r'''
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
String get _flutterBase => r'''
String get _flutterWidgetImplementation => r'''

Comment thread test/proper_super_calls_rule_test.dart Outdated

void test_initState_reports_when_not_first() async {
await assertDiagnostics(
_flutterBase +
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use dependency mocking instead, as you did for the avoid_debug_print rule tests.

Comment thread test/proper_super_calls_rule_test.dart Outdated
}
''',
[
lint(197, 9), // Highlights 'initState'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lint(197, 9), // Highlights 'initState'
lint(197, 9),

Please, remove unnecessary comments.

Comment thread test/proper_super_calls_rule_test.dart Outdated
Comment on lines +81 to +83
''');
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we miss some test cases here:

  • rule should not assert when we are not overriding the method.
  • rule should assert when we do override, but omit explicit @override declaration.

Also, please think of edge cases and add more tests.

@solid-vovabeloded solid-vovabeloded force-pushed the migrate/proper_super_calls branch from 0ac062d to 5aa35df Compare April 21, 2026 06:31
@solid-vovabeloded solid-vovabeloded merged commit 04a0112 into analysis_server_migration Apr 21, 2026
0 of 2 checks passed
@solid-vovabeloded solid-vovabeloded deleted the migrate/proper_super_calls branch April 21, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants