dart-lang / dart_style

An opinionated formatter/linter for Dart code
https://pub.dev/packages/dart_style
BSD 3-Clause "New" or "Revised" License
645 stars 118 forks source link

Treat `as` expressions as block-formattable if the subexpression is #1542

Open dcharkes opened 3 weeks ago

dcharkes commented 3 weeks ago

Update: awaits are fixed, as is not yet.

        final result = await buildDryRun(
          packageUri,
          createCapturingLogger(logMessages, level: Level.SEVERE),
          dartExecutable,
          linkingEnabled: false,
        );

->

        final result =
            await buildDryRun(
              packageUri,
              createCapturingLogger(logMessages, level: Level.SEVERE),
              dartExecutable,
              linkingEnabled: false,
            );

I'm not sure why the extra indentation is needed here. I expect this to be indented like it would be without an await

        final result = buildDryRun(
          packageUri,
          createCapturingLogger(logMessages, level: Level.SEVERE),
          dartExecutable,
          linkingEnabled: false,
        );

Is the await significant here? Or is it simply that the formatter deems the expression getting too big?

Source: https://github.com/dart-lang/native/blob/main/pkgs/native_assets_builder/test/build_runner/build_runner_cycle_test.dart

dcharkes commented 3 weeks ago
      final buildConfig = BuildConfig.build(
        outputDirectory: outputDirectory,
        packageName: await _packageName(),
        packageRoot: Directory.current.uri,
        buildMode: buildMode ?? BuildMode.release,
        targetArchitecture: targetArchitecture ?? Architecture.current,
        targetOS: targetOS ?? OS.current,
        linkModePreference: linkModePreference ?? LinkModePreference.dynamic,
        linkingEnabled: linkingEnabled ?? true,
        cCompiler: cCompiler,
        supportedAssetTypes: supportedAssetTypes,
        targetAndroidNdkApi: targetAndroidNdkApi,
        targetIOSSdk: targetIOSSdk,
        targetIOSVersion: targetIOSVersion,
        targetMacOSVersion: targetMacOSVersion,
      ) as BuildConfigImpl;

->

    final buildConfig =
        BuildConfig.build(
              outputDirectory: outputDirectory,
              packageName: await _packageName(),
              packageRoot: Directory.current.uri,
              buildMode: buildMode ?? BuildMode.release,
              targetArchitecture: targetArchitecture ?? Architecture.current,
              targetOS: targetOS ?? OS.current,
              linkModePreference:
                  linkModePreference ?? LinkModePreference.dynamic,
              linkingEnabled: linkingEnabled ?? true,
              cCompiler: cCompiler,
              supportedAssetTypes: supportedAssetTypes,
              targetAndroidNdkApi: targetAndroidNdkApi,
              targetIOSSdk: targetIOSSdk,
              targetIOSVersion: targetIOSVersion,
              targetMacOSVersion: targetMacOSVersion,
            )
            as BuildConfigImpl;

Is this similar as to the await? that an as prevents no indentation?

Source: https://github.com/dart-lang/native/blob/main/pkgs/native_assets_cli/lib/src/api/test.dart

dcharkes commented 3 weeks ago

Duplicate: https://github.com/dart-lang/dart_style/issues/1531

dcharkes commented 3 weeks ago

awaits are fixed as of https://github.com/dart-lang/dart_style/pull/1538 ❤️

as expressions are not block-formatted.