dart-lang/dart_style là một trong những repo mã nguồn mở mà TopGit theo dõi, hiện có 702 sao, viết chủ yếu bằng Dart. An opinionated formatter/linter for Dart code
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
The dart_style package defines an opinionated, minimally configurable
automated formatter for Dart code.
It replaces the whitespace in your program with what it deems to be the
best formatting for it. It also makes minor changes around non-semantic
punctuation like trailing commas and brackets in parameter lists.
The resulting code should follow the Dart style guide and look nice to most
human readers, most of the time.
The formatter handles indentation, inline whitespace, and (by far the most
difficult) intelligent line wrapping. It has no problems with nested
collections, function expressions, long argument lists, or otherwise tricky
code.
The formatter turns code like this:
process = await Process.start(path.join(p.pubCacheBinPath,Platform.isWindows
?'${command.first}.bat':command.first,),[...command.sublist(1),'web:0',
// Allow for binding to a random available port.
],workingDirectory:workingDir,environment:{'PUB_CACHE':p.pubCachePath,'PATH':
path.dirname(Platform.resolvedExecutable)+(Platform.isWindows?';':':')+
Platform.environment['PATH']!,},);
into:
process = await Process.start(
path.join(
p.pubCacheBinPath,
Platform.isWindows ? '${command.first}.bat' : command.first,
),
[
...command.sublist(1), 'web:0',
// Allow for binding to a random available port.
],
workingDirectory: workingDir,
environment: {
'PUB_CACHE': p.pubCachePath,
'PATH':
path.dirname(Platform.resolvedExecutable) +
(Platform.isWindows ? ';' : ':') +
Platform.environment['PATH']!,
},
);
The formatter will never break your code—you can safely invoke it
automatically from build and presubmit scripts.
Formatting files
The formatter is part of the unified dart developer tool included in the
Dart SDK, so most users run it directly from there using dart format.
IDEs and editors that support Dart usually provide easy ways to run the
formatter. For example, in Visual Studio Code, formatting Dart code will use
the dart_style formatter by default. Most users have it set to reformat every
time they save a file.
Here's a simple example of using the formatter on the command line:
$ dart format my_file.dart
This command formats the my_file.dart file and writes the result back to the
same file.
The dart format command takes a list of paths, which can point to directories
or files. If the path is a directory, it processes every .dart file in that
directory and all of its subdirectories.
By default, dart format formats each file and writes the result back to the
same files. If you pass --output show, it prints the formatted code to stdout
and doesn't modify the files.
Validating formatting
If you want to use the formatter in something like a presubmit script or
commit hook, you can pass flags to omit writing formatting changes to disk
and to update the exit code to indicate success/failure:
$ dart format --output=none --set-exit-if-changed .
Using the formatter as a library
The dart_style package exposes a simple library API for formatting code.
Basic usage looks like this:
import 'package:dart_style/dart_style.dart';
main() {
final formatter = DartFormatter(
languageVersion: DartFormatter.latestLanguageVersion,
);
try {
print(formatter.format("""
library an_entire_compilation_unit;
class SomeClass {}
"""));
print(formatter.formatStatement("aSingle(statement);"));
} on FormatterException catch (ex) {
print(ex);
}
}
Other resources
Before sending an email, see if you are asking a
frequently asked question.
Before filing a bug, or if you want to understand how work on the
formatter is managed, see how we track issues.
dart-lang/dart_style có 702 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/dart-lang/dart_style. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
dart-lang/dart_style có phải mã nguồn mở không?
Có — dart-lang/dart_style phát hành theo license BSD-3-Clause, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/dart-lang/dart_style.
dart-lang/dart_style còn đang phát triển không?
Commit gần nhất trên dart-lang/dart_style là 2 ngày trước (theo timestamp GitHub). Repo có 141 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
dart-lang/dart_style là gì?
dart-lang/dart_style (dart-lang/dart_style) là dự án Dart trên GitHub. Theo mô tả gốc: An opinionated formatter/linter for Dart code
Đọc thêm về dart-lang/dart_style ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/dart-lang/dart_style là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc dart_style có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về dart_style.