-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[tool] Add a way to opt a file out of formatting #4292
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,7 +206,27 @@ class FormatCommand extends PluginCommand { | |
|
||
final String fromPath = relativeTo.path; | ||
|
||
// Dart files are allowed to have a pragma to disable auto-formatting. This | ||
// was added because Hixie hurts when dealing with what dartfmt does to | ||
// artisanally-formatted Dart, while Stuart gets really frustrated when | ||
// dealing with PRs from newer contributors who don't know how to make Dart | ||
// readable. After much discussion, it was decided that files in the plugins | ||
// and packages repos that really benefit from hand-formatting (e.g. files | ||
// with large blobs of hex literals) could be opted-out of the requirement | ||
// that they be autoformatted, so long as the code's owner was willing to | ||
// bear the cost of this during code reviews. | ||
// In the event that code ownership moves to someone who does not hold the | ||
// same views as the original owner, the pragma can be removed and the file | ||
// auto-formatted. | ||
const String handFormattedExtension = '.dart'; | ||
const String handFormattedPragma = '// This file is hand-formatted.'; | ||
stuartmorgan-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return files | ||
.where((File file) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I would much rather this apply only to Dart, as this is strictly worse than What's the issue with just adding a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seemed weird to have this code know about file extensions too, but i'm happy to add it if you like |
||
// See comment above near [handFormattedPragma]. | ||
return path.extension(file.path) != handFormattedExtension || | ||
!file.readAsLinesSync().contains(handFormattedPragma); | ||
}) | ||
.map((File file) => path.relative(file.path, from: fromPath)) | ||
.where((String path) => | ||
// Ignore files in build/ directories (e.g., headers of frameworks) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣 Well, I did ask.
(I was just thinking something like "Allow package maintainers to opt out of Dart autoformatting in order to use Flutter's manual formatting style instead.", but this certainly works.)