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

Allow disabling formatting for a region of code. #1522

Merged
merged 6 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* Allow passing a language version to `DartFomatter()`. Formatted code will be
parsed at that version. If omitted, defaults to the latest version. In a
future release, this parameter will become required.
* Allow opting out of formatting for a region of code using `// dart format off`
and `// dart format on` comments. Note: This only works using the new tall
style and requires passing the `--enable-experiment=tall-style` experiment
flag (#361).
* Preserve type parameters on old-style function-typed formals that also use
`this.` or `super.` (#1321).
* Remove temporary work around for analyzer 6.2.0 from dart_style 2.3.6.
Expand Down
2 changes: 1 addition & 1 deletion benchmark/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ double _runTrial(DartFormatter formatter, ParseStringResult parseResult,
result = visitor.run(parseResult.unit).text;
} else {
var visitor = AstNodeVisitor(formatter, parseResult.lineInfo, source);
result = visitor.run(parseResult.unit).text;
result = visitor.run(source, parseResult.unit).text;
}
}

Expand Down
4 changes: 2 additions & 2 deletions example/format.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main(List<String> args) {
class C {}
''');

_runTest('selection/selection.stmt', 2);
_runTest('other/selection.stmt', 2);
}

void _formatStmt(String source, {bool tall = true, int pageWidth = 40}) {
Expand Down Expand Up @@ -68,7 +68,7 @@ void _drawRuler(String label, int width) {
/// directory.
Future<void> _runTest(String path, int line,
{int pageWidth = 40, bool tall = true}) async {
var testFile = await TestFile.read(path);
var testFile = await TestFile.read('${tall ? 'tall' : 'short'}/$path');
var formatTest = testFile.tests.firstWhere((test) => test.line == line);

var formatter = DartFormatter(
Expand Down
Loading