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

Enforce dart_style's non-whitespace style fixes, i.e., dart format . --fix #1086

Open
bradyt opened this issue Aug 7, 2021 · 3 comments
Open
Assignees

Comments

@bradyt
Copy link

bradyt commented Aug 7, 2021

I have my *.g.dart files committed in git, and I have dart format . --fix running in CI. I would like it if the code generated by built_value followed the advice found in dart format's --fix rules.

> dart help format
...
    --fix                      Apply all style fixes.

To see what this looks like, try a fresh clone of built_value and try dart format . --fix there.

For example,

modified   example/lib/values.g.dart
@@ -6,16 +6,16 @@ part of values;
 // BuiltValueGenerator
 // **************************************************************************
 
-Serializer<SimpleValue> _$simpleValueSerializer = new _$SimpleValueSerializer();
+Serializer<SimpleValue> _$simpleValueSerializer = _$SimpleValueSerializer();

I didn't attempt to dig deep into the issue, I don't know if a related issue can be filed with source_gen, for example.

I'll try the following as a quick fix:

dart format $(find . \( -name '*.dart' ! -name '*.g.dart' \)) --fix
@davidmorgan
Copy link
Collaborator

I think this would be for source_gen to implement; the formatting isn't handled in built_value.

@bradyt
Copy link
Author

bradyt commented Mar 8, 2022

Not suggesting any urgency here, just summarizing the relevant and recent decision at source_gen.

I still don't even know if this could be addressed at built_value.dart.

Are you opposed to doing even just the cascade fix? All the others are things that builder authors really could fix on their own I think.

dart-lang/source_gen#552 (comment)

So I think source_gen is only applying single-cascade-statements. For example, they are not applying optional-new.

Summary of options:

Fwiw this is the list of fixes:

  static const docComments = StyleFix._(
      'doc-comments', 'Use triple slash for documentation comments.');

  static const functionTypedefs = StyleFix._(
      'function-typedefs', 'Use new syntax for function type typedefs.');

  static const namedDefaultSeparator = StyleFix._('named-default-separator',
      'Use "=" as the separator before named parameter default values.');

  static const optionalConst = StyleFix._(
      'optional-const', 'Remove "const" keyword inside constant context.');

  static const optionalNew =
      StyleFix._('optional-new', 'Remove "new" keyword.');

  static const singleCascadeStatements = StyleFix._('single-cascade-statements',
      'Remove unnecessary single cascades from expression statements.');

-- dart-lang/source_gen#552 (comment).

@bradyt
Copy link
Author

bradyt commented Mar 8, 2022

I've experimented with removing "new" from parts of the source code, and realized perhaps a better description of the issue is required. Rather than point at the entire project as being effected by dart format . --fix, I guess I should point at something dependent on the project, emphasizing the generating output, using example projects embedded here. For example:

> cd example
> dart format . --fix
> # note the diff representing the "fixed" output
> dart run build_runner build
> # note the "fixed" diff is removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants