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

too long line without obvious reason. #573

Closed
zoechi opened this issue Jan 4, 2017 · 7 comments
Closed

too long line without obvious reason. #573

zoechi opened this issue Jan 4, 2017 · 7 comments

Comments

@zoechi
Copy link

zoechi commented Jan 4, 2017

part of app_code_generator;

LibraryBuilder createRootProvidersLibrary(List<DataSource> dataSources) {
  final providers = <dynamic>[]
    ..add(AngularCore.provideFunction.call([
      FhirClientBrowser.dataConnectionsService
    ], {
      'useClass': reference(
          'AppDataConnections', GeneratedApplication.dataConnectionsImportPath)
    }))
    ..add(AngularRouter.routerProvidersReference)
    ..add(AngularCore.provideFunction.call(
        [AngularLocation.appBaseHrefReference], {'useValue': literal('/')}))
    ..add(AngularCore.provideFunction.call([AngularLocation.locationStrategy],
        {'useClass': AngularLocation.locationStrategy}))
    ..add(AngularCore.provideFunction.call([FhirClientUtil.runModeEnum],
        {'useValue': GeneratedApplication.runModeReference}))
    ..add(AngularCore.provideFunction.call(
        [FhirClientUtil.jsonPrettyPrintService],
        {'useClass': FhirClientUtilBrowser.jsonPrettyPrintService}))
    ..add(AngularCore.provideFunction.call([FhirClientWebui.alertService],
        {'useClass': FhirClientWebui.alertServiceBrowser}))
    ..add(AngularCore.provideFunction.call([HttpClient.baseClient], {'useClass': HttpClient.browserClient}));

  return new LibraryBuilder.scope(scope: new Scope.dedupe())
    ..addMember(list(providers).asFinal('rootProviders', lib$core.List));
}

When I move {'useClass': HttpClient.browserClient})); to the next line dartfmt moves it back to where it is.

Dart VM version: 1.22.0-edge.d591b59fcd01519076d84ce22362552265d34d0e (Tue Jan 3 01:25:48 2017) on "linux_x64"

@munificent
Copy link
Member

munificent commented Jan 6, 2017

Your expression is too complex and the formatter is giving up after too many tries to find an optional solution to it. :(

I'll leave this open because I would like to improve the heuristics around ...

But, in this case, I don't see why you are creating an empty list literal and then calling ..add() on it a dozen times in the first place. Why not do:

part of app_code_generator;

LibraryBuilder createRootProvidersLibrary(List<DataSource> dataSources) {
  final providers = [
    AngularCore.provideFunction.call([
      FhirClientBrowser.dataConnectionsService
    ], {
      'useClass': reference(
          'AppDataConnections', GeneratedApplication.dataConnectionsImportPath)
    }),
    AngularRouter.routerProvidersReference,
    AngularCore.provideFunction.call(
        [AngularLocation.appBaseHrefReference], {'useValue': literal('/')}),
    AngularCore.provideFunction.call([AngularLocation.locationStrategy],
        {'useClass': AngularLocation.locationStrategy}),
    AngularCore.provideFunction.call([FhirClientUtil.runModeEnum],
        {'useValue': GeneratedApplication.runModeReference}),
    AngularCore.provideFunction.call([FhirClientUtil.jsonPrettyPrintService],
        {'useClass': FhirClientUtilBrowser.jsonPrettyPrintService}),
    AngularCore.provideFunction.call([FhirClientWebui.alertService],
        {'useClass': FhirClientWebui.alertServiceBrowser}),
    AngularCore.provideFunction
        .call([HttpClient.baseClient], {'useClass': HttpClient.browserClient})
  ];

  return new LibraryBuilder.scope(scope: new Scope.dedupe())
    ..addMember(list(providers).asFinal('rootProviders', lib$core.List));
}

?

@zoechi
Copy link
Author

zoechi commented Jan 6, 2017

Thanks for the hint. Was focusing on other stuff 😄
It didn't occur to me that this is complex for dartfmt.

@gabrc
Copy link

gabrc commented Nov 17, 2017

This code is also formatted wrongly:

class Foo {
  void foo() {
    _value
      ..register(
          'apple-picker',
          () => new StructureSelectionFilterType<Structure, String>(
              new FilterEditorSelectionContext(
                  new SelectionOptions.fromList([_entity.currentStructure]),
                  itemRenderer: (Structure structure) => structure.displayName),
              predicateValueCallback: (String value) =>
                  _entity.currentStructure,
              serializableValueCallback: (Structure) => 'current',
              defaultPredicateValue: _entity.currentStructure))
      ..register(
          'banana-picker',
          () => new StructureSelectionFilterType<String, String>(
              new StructureFilterSelectionContext(pictureTypes)))
      ..register(
          'cherry-picker',
          () => new StructureSelectionFilterType<String, String>(
              new StructureFilterSelectionContext(_derivedFeatures.isStructure
                  ? pictureTypesForStructure
                  : pictureTypes)))
      ..register(
          'dragon-picker',
          () =>
              _filterUtils.createStructureIdFilterType(new DelegatingSearchFunction<StructureRef, Set>(_getStructures), compareSerializableValue: true))
      ..register('eggfruit-picker', () => _filterUtils.createStructureRefFilterType(new DelegatingSearchFunction<StructureRef, Set>(_getStructures), compareSerializableValue: false, allowedOperators: [containsAnyOfOperator]));
  }
}

@zoechi
Copy link
Author

zoechi commented Nov 15, 2018

Should this be merged with #456 ?

@munificent
Copy link
Member

Yeah, may as well. I can find this bug from that one to add it to the regression tests.

@BrutalCoding
Copy link

Hey @munificent, I think it would be nice if you could update your FAQ found here: https://github.com/dart-lang/dart_style/wiki/FAQ

At the very bottom of your FAQ, you refer to this ticket (#573) for example but it's been closed and completed back in 2018 🤓

Nonetheless, thanks for your work and writeup.

@munificent
Copy link
Member

Good catch! Now that cascades are much faster, most of the remaining performance failure cases are around argument lists. I updated that section of the FAQ to point to the relevant issue. Thanks!

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

4 participants