-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow a comment in code to explicitly configure the page width. (#1574)
Allow a comment in code to explicitly configure the page width. If the code being formatted begins with a comment like: ``` // dart format width=123 ``` Then the code is formatted at that width instead of the default width. The intent is that tools that generate code and then format it will put this comment in the generated code. That way, the tool doesn't have to handle the complex logic to find a surrounding analysis_options.yaml file and get the user's project-wide page width configuration. End users may also want to use this comment in rare cases. For example, maybe they have a library that contains a large value of data that looks better as a big wide table but they don't want their entire project to have a wider page width.
- Loading branch information
1 parent
a5ec37d
commit fb00aab
Showing
5 changed files
with
277 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
40 columns | | ||
### Tests for the comment to set formatting width. | ||
>>> Comment sets page width. | ||
// dart format width=30 | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
<<< | ||
// dart format width=30 | ||
main() { | ||
fitsUnsplitAt40 + | ||
butNotAt30; | ||
} | ||
>>> Comment only takes effect if it appears before code. | ||
main() { | ||
// dart format width=30 | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
<<< | ||
main() { | ||
// dart format width=30 | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
>>> If there are multiple comments, first one wins. | ||
// dart format width=30 | ||
// dart format width=60 | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
<<< | ||
// dart format width=30 | ||
// dart format width=60 | ||
main() { | ||
fitsUnsplitAt40 + | ||
butNotAt30; | ||
} | ||
>>> Does nothing if width is not an integer. | ||
// dart format width=wat | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
<<< | ||
// dart format width=wat | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
>>> Can't have trailing text. | ||
// dart format width=30 some more text | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
<<< | ||
// dart format width=30 some more text | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
>>> Whitespace must match exactly. | ||
//dart format width=30 | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
<<< | ||
//dart format width=30 | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
>>> Whitespace must match exactly. | ||
// dart format width=30 | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
<<< | ||
// dart format width=30 | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
>>> Whitespace must match exactly. | ||
// dart format width = 30 | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
<<< | ||
// dart format width = 30 | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
>>> Can't be a doc comment. | ||
/// dart format width=30 | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
<<< | ||
/// dart format width=30 | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
>>> Can't be nested inside another comment. | ||
/* // dart format width=30 */ | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
<<< | ||
/* // dart format width=30 */ | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
>>> Can't be inside a string literal. | ||
var c = '// dart format width=30'; | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} | ||
<<< | ||
var c = '// dart format width=30'; | ||
main() { | ||
fitsUnsplitAt40 + butNotAt30; | ||
} |