Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit b7b7695

Browse files
committed
Add a way to opt a file out of Dart formatting
1 parent 5306c02 commit b7b7695

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

script/tool/lib/src/format_command.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ class FormatCommand extends PluginCommand {
206206

207207
final String fromPath = relativeTo.path;
208208

209+
const String handFormattedPragma = '// This file is hand-formatted.';
210+
209211
return files
212+
.where((File file) =>
213+
!file.readAsLinesSync().contains(handFormattedPragma))
210214
.map((File file) => path.relative(file.path, from: fromPath))
211215
.where((String path) =>
212216
// Ignore files in build/ directories (e.g., headers of frameworks)

script/tool/test/format_command_test.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:args/command_runner.dart';
88
import 'package:file/file.dart';
99
import 'package:file/memory.dart';
1010
import 'package:flutter_plugin_tools/src/common/core.dart';
11+
import 'package:flutter_plugin_tools/src/common/file_utils.dart';
1112
import 'package:flutter_plugin_tools/src/format_command.dart';
1213
import 'package:path/path.dart' as p;
1314
import 'package:test/test.dart';
@@ -85,12 +86,21 @@ void main() {
8586
'lib/src/b.dart',
8687
'lib/src/c.dart',
8788
];
89+
const String fileWithOptOut = 'lib/src/d.dart';
8890
final Directory pluginDir = createFakePlugin(
8991
'a_plugin',
9092
packagesDir,
91-
extraFiles: files,
93+
extraFiles: <String>[
94+
...files,
95+
fileWithOptOut,
96+
],
9297
);
9398

99+
final p.Context posixContext = p.posix;
100+
childFileWithSubcomponents(pluginDir, posixContext.split(fileWithOptOut))
101+
.writeAsStringSync(
102+
'// copyright bla bla\n// This file is hand-formatted.\ncode...');
103+
94104
await runCapturingPrint(runner, <String>['format']);
95105

96106
expect(

0 commit comments

Comments
 (0)