Skip to content

Quickfix "Add final field formal parameters" ignores always_put_required_named_parameters_first lint #60783

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

Open
navaronbracke opened this issue May 23, 2025 · 1 comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@navaronbracke
Copy link

navaronbracke commented May 23, 2025

Considering the following code sample:

import 'package:flutter/widgets.dart';

class MyWidget extends StatelessWidget {
  const MyWidget({super.key});

  final int bar;
  final String qux;

  @override
  Widget build(BuildContext context) {
    return const Placeholder();
  }
}

Using the Add final field formal parameters quickfix, this produces

import 'package:flutter/widgets.dart';

class MyWidget extends StatelessWidget {
  const MyWidget({super.key, required this.bar, required this.qux});  // LINT: always_put_required_named_parameters_first

  final int bar;
  final String qux;

  @override
  Widget build(BuildContext context) {
    return const Placeholder();
  }
}

When using a distilled sample with just Foo & Bar (no Flutter), the quickfix did not insert them as named parameters, which prevented the issue. (I don't know how to tell the quickfix to insert named params, since I don't use the quickfix that much)

class Foo {
  Foo({this.key});

  final String? key;
}

class Bar extends Foo {
  Bar({super.key});

  final int bar;
  final String qux;
}

turns into

class Foo {
  Foo({this.key});

  final String? key;
}

class Bar extends Foo {
  Bar(this.bar, this.qux, {super.key});

  final int bar;
  final String qux;
}
#### General info

- Dart 3.7.2 (stable) (Tue Mar 11 04:27:50 2025 -0700) on "macos_x64"
- on macos / Version 14.6.1 (Build 23G93)
- locale is en-BE

#### Process info

| Memory |  CPU | Elapsed time | Command line                                                                               |
| -----: | ---: | -----------: | ------------------------------------------------------------------------------------------ |
|  70 MB | 0.0% |        50:07 | dart development-service --vm-service-uri=http:<path>/ --bind-address=127.0.0.1 --bind-port=0 |
|  15 MB | 0.0% |     02:32:59 | dart devtools --machine --allow-embedding --dtd-uri ws:<path>/cpviGxKKtUU=                 |
|  88 MB | 0.0% |        50:06 | dart devtools --no-launch-browser                                                          |
| 806 MB | 0.0% |     02:33:02 | dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.110.0           |
|  16 MB | 0.0% |     02:33:02 | dart tooling-daemon --machine                                                              |
|  49 MB | 0.0% |     02:33:02 | flutter_tools.snapshot daemon                                                              |
|  94 MB | 0.0% |        51:19 | flutter_tools.snapshot run                                             |

@FMorschel
Copy link
Contributor

FMorschel commented May 23, 2025

I've been working on some fixes about this lint here https://dart-review.googlesource.com/c/sdk/+/422369. I'll review this CL to make sure this fix is one of them (it has been some time since I last worked on it).

Edit: Yes, that is one of the fixes I handled here.

@lrhn lrhn added the area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. label May 23, 2025
@bwilkerson bwilkerson added P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants