Skip to content

Execution of "add missing required arguments" will fill in extra commas #61531

@luo2430

Description

@luo2430
  • Dart SDK version: 3.9.2 (stable) (Wed Aug 27 03:49:40 2025 -0700) on "windows_x64"

  • repro:

The following is demonstrated using vscode. In addition, after my tests, the same problem will occur in IDEA and Android Studio

Add 2 required arguments
Image

  • problem:

import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MainApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(),
        // Here is a redundant comma that will cause the code to not be formatted correctly. 
        // Manually deleting it manually when there are fewer parameters, 
        // but when there are many parameters, it will make the entire line of code very long 
        // and it is impossible to simply format the document to make it automatically wrap 
        // the line to facilitate code writing
        //                                    ↓
        body: FilledButton(onPressed: () {  },, child: null,),
      ),
    );
  }
}
Image
  • expected:

import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MainApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(),
        body: FilledButton(onPressed: () {}, child: null,),
      ),
    );
  }
}
  • solution

We can see the problem in the refactoring preview

Image

Then I targeted the "compute" function in "add_missing_required_argument.dart" and found that the problem seems to be in this code of line 143

if ((arguments.isNotEmpty || index > 0) && !insertBetweenParams) {
  builder.write(', ');
}

I think it should be modified like this

if (arguments.isNotEmpty && !hasTrailingComma && !insertBetweenParams) {
  builder.write(', ');
}

I removed the "index" variable here, and this variable has not been used elsewhere in this "for" loop, so the code of line 94 might be changed like this

// before
for (var (index, diagnostic) in diagnostics.indexed) {
// after
for (final diagnostic in diagnostics) {
  • consultation

I would like to ask how to become a contributor to this project, and I found that it seems that all pull requests are closed. Is it possible that even if the pull request is closed, as long as the "Gerrit for code reviews" is approved, I can become a member of the contributor?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-quick-fixIssues with analysis server (quick) fixestype-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