lines_longer_than_80_chars
Avoid lines longer than 80 characters.
此规则自 Dart 2.0 版本起可用。
详情
#AVOID lines longer than 80 characters
Readability studies show that long lines of text are harder to read because your eye has to travel farther when moving to the beginning of the next line. This is why newspapers and magazines use multiple columns of text.
If you really find yourself wanting lines longer than 80 characters, our experience is that your code is likely too verbose and could be a little more compact. The main offender is usually VeryLongCamelCaseClassNames
. Ask yourself, “Does each word in that type name tell me something critical or prevent a name collision?” If not, consider omitting it.
Note that dart format
does 99% of this for you, but the last 1% is you. It does not split long string literals to fit in 80 columns, so you have to do that manually.
We make an exception for URIs and file paths. When those occur in comments or strings (usually in imports and exports), they may remain on a single line even if they go over the line limit. This makes it easier to search source files for a given path.
使用方法
#要启用 lines_longer_than_80_chars
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 lines_longer_than_80_chars
:
linter:
rules:
- lines_longer_than_80_chars
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.