Skip to content

Commit e7c9291

Browse files
authored
♻️ Fighting with the Dart formatter (#697)
## What does this change? Generated files are being formatted based on confusing conditions. The PR refactored how we construct the Dart formatter in a more elegant manner. 1. The formatter will try to find a valid Dart SDK constraint from `pubspec.yaml` / `pubspec.lock`. Otherwise, it will fall back to using the current Dart SDK version as the constraint. The behavior is like: 1. When the user is using Dart SDK 3.8.0, `pubspec.yaml` has `^3.4.0`, and `pubspec.lock` resolves `^3.7.0`, the formatter will format like 3.4.0. 2. When the runner is being used for testing purposes, which the specified pubspec file does not contain `environment - sdk` (and likely does not have a `pubspec.lock`), the formatter will format based on the current Dart SDK version. 2. The formatter will try to find a valid page width from `analysis_options.yaml - formatter - page_width` / `pubspec.yaml - flutter_gen - line_length`, then prepend the format width header to make all format tools respect the config. - Fixes #685 (comment) - Fixes #659 (comment) - Fixes #620 ## Type of change - [x] New feature (non-breaking change which adds functionality)
2 parents 12ea28d + 8200369 commit e7c9291

File tree

89 files changed

+719
-733
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+719
-733
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ body:
5252
5353
flutter_gen:
5454
output: lib/gen/
55-
line_length: 80
55+
# line_length: 80
5656
5757
integrations:
5858
flutter_svg: true

.idea/runConfigurations/build_runner_build_example.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/build_runner_build_example_resources.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Default configuration can be found [here](https://github.com/FlutterGen/flutter_
143143
144144
flutter_gen:
145145
output: lib/gen/ # Optional (default: lib/gen/)
146-
line_length: 80 # Optional (default: 80)
146+
# line_length: 80 # Optional
147147
148148
# Optional
149149
integrations:
@@ -184,7 +184,7 @@ targets:
184184
flutter_gen_runner: # or flutter_gen
185185
options:
186186
output: lib/build_gen/ # Optional (default: lib/gen/)
187-
line_length: 120 # Optional (default: 80)
187+
line_length: 120 # Optional
188188
```
189189

190190
## Available Parsers

examples/example/lib/gen/assets.gen.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
// dart format width=80
2+
13
/// GENERATED CODE - DO NOT MODIFY BY HAND
24
/// *****************************************************
35
/// FlutterGen
46
/// *****************************************************
57
68
// coverage:ignore-file
79
// ignore_for_file: type=lint
8-
// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use
10+
// ignore_for_file: deprecated_member_use,directives_ordering,implicit_dynamic_list_literal,unnecessary_import
911

1012
import 'package:flutter/services.dart';
1113
import 'package:flutter/widgets.dart';

examples/example/lib/gen/colors.gen.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
// dart format width=80
12
/// GENERATED CODE - DO NOT MODIFY BY HAND
23
/// *****************************************************
34
/// FlutterGen
45
/// *****************************************************
56
67
// coverage:ignore-file
78
// ignore_for_file: type=lint
8-
// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use
9+
// ignore_for_file: deprecated_member_use,directives_ordering,implicit_dynamic_list_literal,unnecessary_import
910

1011
import 'package:flutter/painting.dart';
1112
import 'package:flutter/material.dart';

examples/example/lib/gen/fonts.gen.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
// dart format width=80
12
/// GENERATED CODE - DO NOT MODIFY BY HAND
23
/// *****************************************************
34
/// FlutterGen
45
/// *****************************************************
56
67
// coverage:ignore-file
78
// ignore_for_file: type=lint
8-
// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use
9+
// ignore_for_file: deprecated_member_use,directives_ordering,implicit_dynamic_list_literal,unnecessary_import
910

1011
class MyFontFamily {
1112
MyFontFamily._();

examples/example/pubspec.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ dependencies:
1414

1515
flutter_svg: ^2.0.0
1616
lottie: ^3.0.0
17-
rive: ^0.11.0
17+
rive: ^0.13.20
1818

1919
dev_dependencies:
20+
lints: any
2021
flutter_test:
2122
sdk: flutter
23+
2224
flutter_gen_runner:
2325
path: ../../packages/runner
2426

25-
lints: ^2.0.0
2627
build_runner: ^2.0.0
2728

2829
flutter_gen:
2930
output: lib/gen/ # Optional (default: lib/gen/)
30-
line_length: 80 # Optional (default: 80)
31+
# line_length: 80 # Optional
3132

3233
integrations:
3334
flutter_svg: true

examples/example_resources/lib/gen/assets.gen.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
// dart format width=80
2+
13
/// GENERATED CODE - DO NOT MODIFY BY HAND
24
/// *****************************************************
35
/// FlutterGen
46
/// *****************************************************
57
68
// coverage:ignore-file
79
// ignore_for_file: type=lint
8-
// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use
10+
// ignore_for_file: deprecated_member_use,directives_ordering,implicit_dynamic_list_literal,unnecessary_import
911

1012
import 'package:flutter/services.dart';
1113
import 'package:flutter/widgets.dart';

examples/example_resources/lib/gen/colors.gen.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
// dart format width=80
12
/// GENERATED CODE - DO NOT MODIFY BY HAND
23
/// *****************************************************
34
/// FlutterGen
45
/// *****************************************************
56
67
// coverage:ignore-file
78
// ignore_for_file: type=lint
8-
// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use
9+
// ignore_for_file: deprecated_member_use,directives_ordering,implicit_dynamic_list_literal,unnecessary_import
910

1011
import 'package:flutter/painting.dart';
1112
import 'package:flutter/material.dart';

0 commit comments

Comments
 (0)