Skip to content

Conversation

@nate-thegrate
Copy link
Contributor

@nate-thegrate nate-thegrate commented Jul 30, 2024

This pull request contains various updates for the the style guide:

  • Removes the Prefer single quotes for strings and Separate the 'if' expression from its statement sections, since at this point, any contributions that violate these guidelines will trigger linter rules.
  • Updates examples in the style guide based on style guidelines (i.e. previously some guidelines were contradicted by code samples in the file). This includes if-statement curly braces, aligning expressions, and trailing commas.
  • Alters the => rule to include multi-line getters that return collection literals or switch expressions. (This is based on a recommendation from Bernardo Ferrari and Michael Goderbauer in a previous comment thread.)

@github-actions github-actions bot added c: contributor-productivity Team-specific productivity, code health, technical debt. framework flutter/packages/flutter repository. See also f: labels. d: docs/ flutter/flutter/docs, for contributors labels Jul 30, 2024
Comment on lines -931 to +933
if (_theProperty == value)
if (_theProperty == value) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that we've enabled a linter rule to enforce if-statement curly braces, it makes sense for the examples here to reflect that.

Comment on lines -755 to +761
if (owner.debugDoingLayout)
return (RenderObject.debugActiveLayout == parent) &&
parent.debugDoingThisLayout;
if (owner.debugDoingPaint)
return ((RenderObject.debugActivePaint == parent) &&
parent.debugDoingThisPaint) ||
((RenderObject.debugActivePaint == this) && debugDoingThisPaint);
if (owner.debugDoingLayout) {
return (RenderObject.debugActiveLayout == parent) && parent.debugDoingThisLayout;
}
if (owner.debugDoingPaint) {
return ((RenderObject.debugActivePaint == parent) && parent.debugDoingThisPaint)
|| ((RenderObject.debugActivePaint == this) && debugDoingThisPaint);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is based on Align expressions; it also adds if-statement curly braces.

Comment on lines -1076 to +1077
However, where possible avoid global constants. Rather than `kDefaultButtonColor`, consider `Button.defaultColor`. If necessary, consider creating a class with a private constructor to hold relevant constants.
However, where possible avoid global constants. Rather than `kDefaultButtonColor`, consider `Button.defaultColor`. If necessary, consider creating an `abstract final class` to hold relevant constants.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Classes built to hold constants (e.g. Colors and Durations) now use the abstract and final modifiers in place of a private constructor.

Comment on lines 1252 to 1256
```dart
setState(() { /* The animation ticked. We use the animation's value in the build method. */ });
setState(() {
// The animation ticked. We use the animation's value in the build method.
});
```
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is based on the 80 characters guideline, along with the Dart documentation guide linked in the Documentation section:

DON'T use block comments for documentation

void greet(String name) {
  // Assume we have a valid name.
  print('Hi, $name!');
}
void greet(String name) {
  /* Assume we have a valid name. */
  print('Hi, $name!');
}

Comment on lines -1331 to 1338
// one-line constructor example
abstract class Foo extends StatelessWidget {
Foo(this.bar, { Key key, this.child }) : super(key: key);
final int bar;
final Widget child;
class ConstantTween<T> extends Tween<T> {
ConstantTween(T value) : super(begin: value, end: value);
// ...
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The old example would have triggered the use_super_parameters rule (I'm sure it was written before that feature existed).

Comment on lines -1491 to -1500
### Prefer single quotes for strings

Use double quotes for nested strings or (optionally) for strings that contain single quotes.
For all other strings, use single quotes.

Example:

```dart
print('Hello ${name.split(" ")[0]}');
```
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This section was likely written before the prefer_single_quotes and avoid_escaping_inner_quotes rules were introduced.

Since violations of this guideline result in analysis check failures, there isn't any additional utility that we gain from keeping this section. Removing it decreases the total length of this markdown file, making it more likely that the reader will pay attention to other sections.

Comment on lines 1527 to 1607
return <PopupMenuItem<String>>[
PopupMenuItem<String>(
value: 'Friends',
child: MenuItemWithIcon(Icons.people, 'Friends', '5 new')
child: MenuItemWithIcon(Icons.people, 'Friends', '5 new'),
),
PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.event, 'Events', '12 upcoming')
child: MenuItemWithIcon(Icons.event, 'Events', '12 upcoming'),
),
];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated based on the Use a trailing comma guideline.

Comment on lines -1669 to -1671
### Separate the 'if' expression from its statement

(This is enforced by the `always_put_control_body_on_new_line` and `curly_braces_in_flow_control_structures` lints.)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing this section, for the same reason as 'Prefer single quotes' above.

Comment on lines -1435 to -1436
foo(bar,
baz);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only change I'm on the fence about.

Personally, I think the other two examples are much easier to visually parse than this one.

Copy link
Contributor

@cedvdb cedvdb Jul 31, 2024

Choose a reason for hiding this comment

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

Why are you on the fence with this one ? This would only make sense if it breaks the max char per line rule, wouldn't it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If foo() takes up multiple lines due to a callback/switch expression/list or map literal, then I think it's all right to format it this way.

foo(bar, () {
  baz.quux();
  return baz.toInt();
});

foo(bar, switch (baz) {
  1 => 'a',
  2 => 'b`,
  _ => `c`,
});

foo(bar, [
  'quux',
  'qaax',
  'qeex',
]);

But in any other situation where the foo() arguments take up more than 1 line, I think it's much more readable with a trailing comma.

foo(
  bar,
  baz,
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it'd be nice to get another perspective on this, and then possibly add the above examples to this section.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with removing this example and would be fine with adding the other examples you're mentioning in the comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome!

Examples have been added in the most recent commit. I'll plan on adding autosubmit tomorrow, to leave a window for any additional feedback 👍

@nate-thegrate nate-thegrate marked this pull request as ready for review July 30, 2024 01:25
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines -1435 to -1436
foo(bar,
baz);
Copy link
Member

Choose a reason for hiding this comment

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

I agree with removing this example and would be fine with adding the other examples you're mentioning in the comment above.

Comment on lines -1435 to -1436
foo(bar,
baz);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome!

Examples have been added in the most recent commit. I'll plan on adding autosubmit tomorrow, to leave a window for any additional feedback 👍

Comment on lines -1529 to -1530
closing `]`, `}`, or `)` bracket will line up with the argument name, for
named arguments, or the `(` of the argument list, for positional arguments.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was confused by "argument name" and "argument list" here, since the code has a nested argument structure.

Comment on lines +1585 to +1587
you can instead use the `=>` form.\
When doing this, the closing `]`, `}`, or `)` bracket will have the same
indentation as the line where the callback starts.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I picked up the \ from the resources linked in the semantic line breaks documentation :)

Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

@nate-thegrate nate-thegrate added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 16, 2024
@auto-submit auto-submit bot merged commit a0c0453 into flutter:master Aug 16, 2024
@nate-thegrate nate-thegrate deleted the style-guide-updates branch August 16, 2024 16:19
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Aug 16, 2024
flutter/flutter@bced008...a0c0453

2024-08-16 [email protected] Style Guide updates (flutter/flutter#152525)
2024-08-16 [email protected] Roll Packages from 86d15a6 to 2c37fb0 (5 revisions) (flutter/flutter#153571)
2024-08-16 [email protected] Move Android API level 35 emulator tests to staging (flutter/flutter#153568)
2024-08-16 [email protected] Roll Flutter Engine from a8fefc81188e to d5bf3afc601f (2 revisions) (flutter/flutter#153565)
2024-08-16 [email protected] [Swift Package Manager] Test removing the last Flutter plugin (flutter/flutter#153519)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
DBowen33 pushed a commit to DBowen33/flutter that referenced this pull request Aug 16, 2024
This pull request updates the style guide for improved internal consistency and to match current linter rules.

I'll make comments for each change here!
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
This pull request updates the style guide for improved internal consistency and to match current linter rules.

I'll make comments for each change here!
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App c: contributor-productivity Team-specific productivity, code health, technical debt. d: docs/ flutter/flutter/docs, for contributors framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants