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

dart format causes lines to exceed 80 character limit in Dart 3.7 #60173

Open
felangel opened this issue Feb 19, 2025 · 2 comments
Open

dart format causes lines to exceed 80 character limit in Dart 3.7 #60173

felangel opened this issue Feb 19, 2025 · 2 comments
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. dart-cli-format Issues related to the 'dart format' tool

Comments

@felangel
Copy link

felangel commented Feb 19, 2025

Description

Running dart format with Dart 3.7 reformats code such that some lines exceed the 80 character limit and trigger the lines_longer_than_80_chars lint. I would expect the new formatter to adhere to the max line length configured (by default 80 characters).

Reproduction Steps

pubspec.yaml

name: example
publish_to: none

environment:
  sdk: ^3.7.0

dev_dependencies:
  mocktail: ^1.0.0
  test: ^1.0.0

analysis_options.yaml

linter:
  rules:
    - lines_longer_than_80_chars
formatter:
    page_width: 80

main.dart

import 'dart:convert';
import 'dart:io';

import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

class BuildProcess {
  Stream<List<int>> get stdout => throw UnimplementedError();
}

class MockBuildProcess extends Mock implements BuildProcess {}

void main() {
  group('Root Group', () {
    group('Nested Group', () {
      test('Test', () {
        final buildProcess = MockBuildProcess();
        when(() => buildProcess.stdout).thenAnswer(
          (_) => Stream.fromIterable(
            [
              '[  +10 ms] Generating /Users/bryanoltman/Documents/sandbox/notification_extension/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java',
              '[  +50 ms] executing: [/Users/bryanoltman/Documents/sandbox/notification_extension/ios/] /usr/bin/arch -arm64e xcrun xcodebuild -list',
              '[+32333 ms] Command line invocation:',
              '[   +6 ms] Exit code 0 from: mkfifo /var/folders/64/dj6krpq1093dmx08dy4r1cwh0000gn/T/flutter_tools.WDvaE9/flutter_ios_build_temp_dirUAyStV/pipe_to_stdout',
              '[+62601 ms] Running Xcode build... (completed in 62.6s)',
              '[        ]  └─Compiling, linking and signing...',
              '[+5925 ms] Command line invocation:',
              '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -configuration Release VERBOSE_SCRIPT_LOGGING=YES -workspace Runner.xcworkspace -scheme Runner -sdk iphoneos -destination generic/platform=iOS SCRIPT_OUTPUT_STREAM_FILE=/var/folders/64/dj6krpq1093dmx08dy4r1cwh0000gn/T/flutter_tools.WDvaE9/flutter_ios_build_temp_dirUAyStV/pipe_to_stdout -resultBundlePath /var/folders/64/dj6krpq1093dmx08dy4r1cwh0000gn/T/flutter_tools.WDvaE9/flutter_ios_build_temp_dirUAyStV/temporary_xcresult_bundle -resultBundleVersion 3 FLUTTER_SUPPRESS_ANALYTICS=true COMPILER_INDEX_STORE_ENABLE=NO -archivePath /Users/bryanoltman/Documents/sandbox/notification_extension/build/ios/archive/Runner archive',
            ]
            .map((line) => 'prefix$line${Platform.lineTerminator}')
            .map(utf8.encode),
          ),
        );
      });
    });
  });
}
  1. Run dart format
$ dart format .
Formatted main.dart
Formatted 1 file (1 changed) in 0.12 seconds.
  1. Observe the reformatted code now exceeds 80 characters
$ dart analyze .           
Analyzing ....                         0.5s

   info • main.dart:29:81 • The line length exceeds the 80-character limit. Try breaking the line across multiple lines. • lines_longer_than_80_chars

1 issue found.

The diff from running dart format:

import 'dart:convert';
import 'dart:io';

import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

class BuildProcess {
  Stream<List<int>> get stdout => throw UnimplementedError();
}

class MockBuildProcess extends Mock implements BuildProcess {}

void main() {
  group('Root Group', () {
    group('Nested Group', () {
      test('Test', () {
        final buildProcess = MockBuildProcess();
        when(() => buildProcess.stdout).thenAnswer(
          (_) => Stream.fromIterable(
            [
              '[  +10 ms] Generating /Users/bryanoltman/Documents/sandbox/notification_extension/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java',
              '[  +50 ms] executing: [/Users/bryanoltman/Documents/sandbox/notification_extension/ios/] /usr/bin/arch -arm64e xcrun xcodebuild -list',
              '[+32333 ms] Command line invocation:',
              '[   +6 ms] Exit code 0 from: mkfifo /var/folders/64/dj6krpq1093dmx08dy4r1cwh0000gn/T/flutter_tools.WDvaE9/flutter_ios_build_temp_dirUAyStV/pipe_to_stdout',
              '[+62601 ms] Running Xcode build... (completed in 62.6s)',
              '[        ]  └─Compiling, linking and signing...',
              '[+5925 ms] Command line invocation:',
              '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -configuration Release VERBOSE_SCRIPT_LOGGING=YES -workspace Runner.xcworkspace -scheme Runner -sdk iphoneos -destination generic/platform=iOS SCRIPT_OUTPUT_STREAM_FILE=/var/folders/64/dj6krpq1093dmx08dy4r1cwh0000gn/T/flutter_tools.WDvaE9/flutter_ios_build_temp_dirUAyStV/pipe_to_stdout -resultBundlePath /var/folders/64/dj6krpq1093dmx08dy4r1cwh0000gn/T/flutter_tools.WDvaE9/flutter_ios_build_temp_dirUAyStV/temporary_xcresult_bundle -resultBundleVersion 3 FLUTTER_SUPPRESS_ANALYTICS=true COMPILER_INDEX_STORE_ENABLE=NO -archivePath /Users/bryanoltman/Documents/sandbox/notification_extension/build/ios/archive/Runner archive',
-            ]
-            .map((line) => 'prefix$line${Platform.lineTerminator}')
-            .map(utf8.encode),
+            ].map((line) => 'prefix$line${Platform.lineTerminator}').map(utf8.encode),
          ),
        );
      });
    });
  });
}
}
$ dart --version
Dart SDK version: 3.7.0 (stable) (Wed Feb 5 04:53:58 2025 -0800) on "macos_arm64"
@felangel
Copy link
Author

Tagging @munificent since I believe you were heavily involved in the new Dart formatter changes.

@lrhn lrhn added area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. dart-cli-format Issues related to the 'dart format' tool labels Feb 20, 2025
@ChunhThanhDe
Copy link

I had the same issue and reported it on Flutter, hope it will be fixed soon

flutter/flutter#163827

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. dart-cli-format Issues related to the 'dart format' tool
Projects
None yet
Development

No branches or pull requests

3 participants