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

Add configurable line length section #6371

Merged
merged 8 commits into from
Jan 31, 2025
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
9 changes: 9 additions & 0 deletions src/content/tools/analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,13 @@ analyzer:
dead_code: info
```

## Configuring `dart format`

You can configure the behavior of [`dart format`][] by adding a
`formatter` section to the analysis options file
specifying your preferred `page_width`.

For more information, read [Configuring formatter page width][].

## Resources

Expand All @@ -603,3 +610,5 @@ Use the following resources to learn more about static analysis in Dart:
[dead_code]: /tools/diagnostic-messages#dead_code
[disable individual rules]: #disabling-individual-rules
[Effective Dart]: /effective-dart
[`dart format`]: /tools/dart-format
[Configuring formatter page width]: /tools/dart-format#configuring-formatter-page-width
35 changes: 33 additions & 2 deletions src/content/tools/dart-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,42 @@ $ dart format -o none --set-exit-if-changed bin/my_app.dart

* Removes whitespace.
* Wraps every line to 80 characters long or shorter.
* Adds trailing commas to any argument or parameter list.
* Adds trailing commas to any argument or parameter list
that splits across multiple lines, and removes them from ones that don't.
* Might move comments before or after a comma.

To learn more about best practices for writing and styling Dart code,
check out the [Dart style guide][].

### Configuring formatter page width

When you run `dart format`, the formatter defaults to
80 character line length or shorter.
If you'd like to configure the line length for your project,
you can add a top-level `formatter` section to the
[`analysis_options.yaml`][] file, like so:

```yaml title="analysis_options.yaml"
formatter:
page_width: 123
```

With the analysis options file typically at the root,
the configured line length will apply to everything in the package.

You can also configure individual files' line length,
overriding the analysis options file,
with a marker comment at the top of the file before any other code:

```dart
// dart format width=123
```

:::version-note
Configurable page width requires
a [language version][] of at least 3.7.
:::

## Learn more

To learn about additional command-line options,
Expand All @@ -94,4 +123,6 @@ Check out the [formatter FAQ][] for more context behind formatting decisions.
[Dart style guide]: /effective-dart/style
[dart_style]: {{site.pub-pkg}}/dart_style
[dart-guidelines]: /effective-dart/style#formatting
[formatter FAQ]: {{site.repo.dart.org}}/dart_style/wiki/FAQ
[`analysis_options.yaml`]: /tools/analysis
[language version]: /resources/language/evolution#language-versioning
[formatter FAQ]: {{site.repo.dart.org}}/dart_style/wiki/FAQ
Loading