Skip to content

RuleVisitorRegistry.afterLibrary not running for plugins(?) #62010

@FMorschel

Description

@FMorschel

I may be doing something wrong, but I did this change FMorschel/essential_lints@0f33417:

  @override
  void registerNodeProcessors(
    RuleVisitorRegistry registry,
    RuleContext context,
  ) {
    final visitor = _PendingListenerVisitor(this, context);
    var file =
        File(
          '${context.definingUnit.file.parent.path}/debug.txt',
        )..writeAsStringSync(
          'Evaluating ${context.definingUnit.file.path}\n',
          mode: FileMode.append,
        );
    registry
      ..addMethodInvocation(this, visitor)
      ..afterLibrary(this, () {
        file.writeAsStringSync(
          'Completed evaluation of ${context.definingUnit.file.path}\n',
          mode: FileMode.append,
        );
        var addedListeners = visitor.addedListeners;
        var removedListeners = visitor.removedListeners;
        file.writeAsStringSync(
          'Added Listeners: $addedListeners\n'
          'Removed Listeners: $removedListeners\n',
          mode: FileMode.append,
        );
        _reportFor(addedListeners, removedListeners, rule);
        _reportFor(
          removedListeners,
          addedListeners,
          PendingListener.unnecessaryRemove,
        );
      });
  }

And on my analyzed project, I have many locations that trigger on my tests, but the outputted file is:

Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\other.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\main.dart
Evaluating D:\dev\flutter\bug\lib\other.dart
Evaluating D:\dev\flutter\bug\lib\other.dart
Evaluating D:\dev\flutter\bug\lib\other.dart
Evaluating D:\dev\flutter\bug\lib\other.dart

So I never get to Completed evaluation of or Added Listeners, and I evaluate main.dart many times, even though I did not open it once (everything there is commented out), all my code is on other.dart.

The question mark in the title is because it works fine on my tests, but I'm guessing that the code isn't running the exact same path there.

Any idea what is happening here @srawlins?

CC @bwilkerson

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-plugintype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions