Skip to content

Conversation

natebosch
Copy link
Member

@natebosch natebosch commented Aug 14, 2025

Closes #1143

The class emitter already used writeln following a => method to
include blank lines between members. Make this consistent for enums,
extensions, and mixins. Extract a method and use it for each type.

Sort changelog with user-facing changes at the top.

The `class` emitter already used `writeln` following a `=>` method to
include blank lines between members. Make this consistent for enums,
extensions, and mixins.

Sort changelog with user-facing changes at the top.
@natebosch natebosch requested a review from a team as a code owner August 14, 2025 21:52
Copy link

@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.

Summary of Changes

Hello @natebosch, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on improving the consistency of generated Dart code by ensuring that arrow-expression members in enums, extensions, and mixins are followed by a blank line, aligning their formatting with how similar members are handled in classes. This change enhances readability and maintains a uniform code style across different Dart constructs. Additionally, the changelog has been updated and reordered to reflect this and other recent changes clearly.

Highlights

  • Code Generation Consistency: Standardized blank line insertion after arrow-expression (=>) members in generated code for enums, extensions, and mixins, mirroring existing class behavior.
  • Changelog Update: Updated CHANGELOG.md to document this formatting improvement and reordered entries for clarity.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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 makes the blank line emission after => members consistent across classes, enums, extensions, and mixins, which is a good improvement for code formatting consistency. The changes in pkgs/code_builder/lib/src/emitter.dart are correct and achieve this goal. The changelog has also been updated appropriately. I've added one comment suggesting a refactoring to reduce code duplication that is highlighted by these changes. Extracting the method visiting logic into a helper function would improve the code's maintainability.

Comment on lines 204 to 210
for (var m in spec.methods) {
visitMethod(m, out);
if (_isLambdaMethod(m)) {
out.write(';');
out.writeln(';');
}
out.writeln();
}

Choose a reason for hiding this comment

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

medium

This block of code for iterating over and emitting methods is duplicated in several places. I see the same logic in visitClass (lines 165-171), visitExtension (lines 329-335), visitExtensionType (lines 375-381), and visitEnum (lines 910-916).

To improve maintainability and reduce code duplication, you could extract this logic into a private helper method. For example:

void _visitMethods(Iterable<Method> methods, StringSink out) {
  for (final m in methods) {
    visitMethod(m, out);
    if (_isLambdaMethod(m)) {
      out.writeln(';');
    }
    out.writeln();
  }
}

You could then call _visitMethods(spec.methods, out); in each of the visitor methods.

Copy link

github-actions bot commented Aug 14, 2025

PR Health

Breaking changes ⚠️
Package Change Current Version New Version Needed Version Looking good?
code_builder Breaking 4.10.1 4.10.2-wip 5.0.0
Got "4.10.2-wip" expected >= "5.0.0" (breaking changes)
⚠️

This check can be disabled by tagging the PR with skip-breaking-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

Coverage ✔️
File Coverage
pkgs/code_builder/lib/src/emitter.dart 💚 98 % ⬆️ 0 %

This check for test coverage is informational (issues shown here will not fail the PR).

API leaks ⚠️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources
code_builder SpecVisitor base.dart::Spec::accept::visitor
emitter.dart::DartEmitter
specs/code.dart::CodeVisitor
specs/code.dart::CodeEmitter
specs/expression.dart::ExpressionVisitor
specs/expression.dart::ExpressionEmitter
code_builder ClosureExpression specs/expression.dart::ExpressionVisitor::visitClosureExpression::expression
code_builder LiteralSetExpression specs/expression.dart::ExpressionVisitor::visitLiteralSetExpression::expression
specs/expression.dart::literalSet
specs/expression.dart::literalConstSet
code_builder LiteralMapExpression specs/expression.dart::ExpressionVisitor::visitLiteralMapExpression::expression
specs/expression.dart::literalMap
specs/expression.dart::literalConstMap
code_builder LiteralRecordExpression specs/expression.dart::ExpressionVisitor::visitLiteralRecordExpression::expression
specs/expression.dart::literalRecord
specs/expression.dart::literalConstRecord

This check can be disabled by tagging the PR with skip-leaking-check.

License Headers ✔️
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/bazel_worker/benchmark/benchmark.dart
pkgs/bazel_worker/example/client.dart
pkgs/bazel_worker/example/worker.dart
pkgs/benchmark_harness/integration_test/perf_benchmark_test.dart
pkgs/boolean_selector/example/example.dart
pkgs/clock/lib/clock.dart
pkgs/clock/lib/src/clock.dart
pkgs/clock/lib/src/default.dart
pkgs/clock/lib/src/stopwatch.dart
pkgs/clock/lib/src/utils.dart
pkgs/clock/test/clock_test.dart
pkgs/clock/test/default_test.dart
pkgs/clock/test/stopwatch_test.dart
pkgs/clock/test/utils.dart
pkgs/coverage/lib/src/coverage_options.dart
pkgs/html/example/main.dart
pkgs/html/lib/dom.dart
pkgs/html/lib/dom_parsing.dart
pkgs/html/lib/html_escape.dart
pkgs/html/lib/parser.dart
pkgs/html/lib/src/constants.dart
pkgs/html/lib/src/encoding_parser.dart
pkgs/html/lib/src/html_input_stream.dart
pkgs/html/lib/src/list_proxy.dart
pkgs/html/lib/src/query_selector.dart
pkgs/html/lib/src/token.dart
pkgs/html/lib/src/tokenizer.dart
pkgs/html/lib/src/treebuilder.dart
pkgs/html/lib/src/utils.dart
pkgs/html/test/dom_test.dart
pkgs/html/test/parser_feature_test.dart
pkgs/html/test/parser_test.dart
pkgs/html/test/query_selector_test.dart
pkgs/html/test/selectors/level1_baseline_test.dart
pkgs/html/test/selectors/level1_lib.dart
pkgs/html/test/selectors/selectors.dart
pkgs/html/test/support.dart
pkgs/html/test/tokenizer_test.dart
pkgs/html/test/trie_test.dart
pkgs/html/tool/generate_trie.dart
pkgs/pubspec_parse/test/git_uri_test.dart
pkgs/stack_trace/example/example.dart
pkgs/watcher/test/custom_watcher_factory_test.dart
pkgs/yaml_edit/example/example.dart

Was going to hold off on refactors in favor of cleaning up the whole
library in the future - but no reason not to clean up the bits we're
editing.
@natebosch natebosch merged commit 1195125 into main Aug 16, 2025
14 checks passed
@natebosch natebosch deleted the blank-between-arrrow-methods branch August 16, 2025 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generated extension class doesn't have blank line between members
2 participants