Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macros] support for avoid_unused_constructor_parameters #4934

Open
Tracked by #4881
pq opened this issue Apr 11, 2024 · 1 comment
Open
Tracked by #4881

[macros] support for avoid_unused_constructor_parameters #4934

pq opened this issue Apr 11, 2024 · 1 comment
Assignees
Labels
P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@pq
Copy link
Member

pq commented Apr 11, 2024

Example:

class A {
  A(int x); // LINT
}

augment class A {
  augment A.new(int x) { // NO LINT
    // do stuff
  }
}
@pq pq changed the title [macros] evaluate support for avoid_unused_constructor_parameters [macros] support for avoid_unused_constructor_parameters Apr 11, 2024
@pq pq self-assigned this Apr 11, 2024
@pq pq added the P2 A bug or feature request we're likely to work on label Apr 11, 2024
@srawlins srawlins added the type-enhancement A request for a change that isn't a bug label Apr 12, 2024
copybara-service bot pushed a commit to dart-lang/sdk that referenced this issue Apr 16, 2024
Fixes: dart-lang/linter#4934


Change-Id: Iafd6ed199bf69214b6520dd56c5bd0012e029341
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363104
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Phil Quitslund <pquitslund@google.com>
@pq
Copy link
Member Author

pq commented Apr 16, 2024

The above is now supported w/ dart-lang/sdk@4e3ff1d.

The following case is interesting though (thanks @bwilkerson!)

  test_augmentedConstructor_base() async {
    newFile('$testPackageLibPath/a.dart', r'''
augment library 'test.dart';

augment class A {
  final int y;
  augment A(int x) : y = x;
}
''');

    await assertNoDiagnostics(r'''
import augment 'a.dart';

class A {
  A(int x);
}
''');
  }

The rub is that A(int x); likely shouldn't produce a lint because in the augmentation, x is referenced in the assignment to y.

To get this test to pass though, we'd need to visit the ASTs of the augmentations in AvoidUnusedConstructorParameters to ensure that parameters are unused in all of them and currently we only have elements via the augmented property of the constructor declaration.

(Note that we'll need to do similar things when evaluating if a field could be final or late or is unused or...)

/fyi @scheglov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants