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

Format parameters better #3731

Merged
merged 2 commits into from
Mar 26, 2024
Merged

Conversation

srawlins
Copy link
Member

@srawlins srawlins commented Mar 19, 2024

Compare:

Before After Notes
Screenshot 2024-03-20 at 9 51 45 AM Screenshot 2024-03-20 at 8 06 32 AM test() and orElse() now on one line
Screenshot 2024-03-20 at 9 51 57 AM Screenshot 2024-03-20 at 8 06 47 AM Unchanged
Screenshot 2024-03-20 at 9 54 46 AM Screenshot 2024-03-20 at 9 44 29 AM braces as in dartfmt, trailing comma
Screenshot 2024-03-20 at 9 55 09 AM Screenshot 2024-03-20 at 9 45 22 AM braces as in dartfmt, trailing comma
Screenshot 2024-03-20 at 9 57 05 AM Screenshot 2024-03-20 at 9 49 01 AM Unchanged
Screenshot 2024-03-20 at 9 57 15 AM Screenshot 2024-03-20 at 9 49 12 AM braces as in dartfmt, trailing comma

  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

@srawlins srawlins force-pushed the format-parameters branch from 6ef7589 to c91cf90 Compare March 20, 2024 19:35
@srawlins srawlins requested a review from kallentu March 20, 2024 19:55
if (trailingComma) suffix += ', ';
} else {
suffix += ', ';
for (var p in namedParams) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we make a helper to avoid the duplicate logic of each parameter type?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I was able to fold more things into _renderParameter, much simpler. Thanks!

</span>
\}
Copy link
Member

Choose a reason for hiding this comment

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

Where is the opening bracket for all the closing brackets in these tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch; these all moved to where you'd expect, based on where the closing ones moved. Updated the tests.

In a nutshell:

* When there are more than 3 parameters, or any named parameters, use "block
  style" (vs "inline style", using CSS terminology).
* In block style, always place a comma after the last parameter.
* In block style, display a `{` or `[` delimiter between required and optional
  parameters, to the right of the last required parameter.
* In block style, display a `}` or `]` closing delimiter on the line after the
  last optional parameter, just before the closing `)`.
* Do not change inline style.
* Indent soft-wrapped lines. This is not as good as whatever `dart format`
  would do when hard-wrapping lines, but at least a wrapped parameter has it's
  non-first-line text indented to separate from the surrounding parameter
  indentations.
@srawlins srawlins force-pushed the format-parameters branch from c91cf90 to 53b497f Compare March 26, 2024 20:49
@srawlins srawlins merged commit 4e096f8 into dart-lang:main Mar 26, 2024
9 checks passed
@srawlins srawlins deleted the format-parameters branch March 26, 2024 21:31
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Mar 28, 2024
Revisions updated by `dart tools/rev_sdk_deps.dart`.

dartdoc (https://github.com/dart-lang/dartdoc/compare/79c1675..bf6080c):
  bf6080c8  2024-03-27  Sam Rawlins  Remove unnecessary EnclosedElement mixin (dart-lang/dartdoc#3736)
  c5bb9066  2024-03-26  Sam Rawlins  Bump to 8.0.8; fix changelog wrapping (dart-lang/dartdoc#3735)
  4e096f84  2024-03-26  Sam Rawlins  Format parameters better (dart-lang/dartdoc#3731)

http (https://github.com/dart-lang/http/compare/7949d6f..280d361):
  280d361  2024-03-27  Derek Xu  [package:http_profile] Expand README.md (dart-lang/http#1162)
  9fddb1c  2024-03-27  Brian Quinlan  Fix the connectionInfo getter (dart-lang/http#1163)
  9f47439  2024-03-27  Derek Xu  [package:http_profile] Make connectionInfo a top-level field of HttpClientRequestProfile (dart-lang/http#1160)

Change-Id: Ib50584ef7d7914ab262bb01eeb087e44c34e4dc7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360240
Auto-Submit: Devon Carew <devoncarew@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants