更改 Dart 格式样式
Change Dart Formatting style
好的,所以标题可能有点误导,这只是我的最终目标。
那么,我刚刚进入 Dart 的世界。到目前为止它看起来不错,但我最大的问题是愚蠢的默认格式化程序。特别是你无法摆脱它。我使用 WebStorm 主要是因为这些东西的可定制性。但是我还没有找到任何方法来更改飞镖的格式化程序(请参阅随附的屏幕截图)。 Dart 格式化程序强制执行 2-space 缩进和许多其他仅由它强制执行的令人恼火的代码样式。
是否可以通过某种方式同时更改配置选项或格式化程序?如果必须对源进行更改,那是可行的,或者只是玩弄一些 WebStorm 配置,那也很好,我只想更改它。
谢谢
您无法更改 dartfmt
使用的格式样式,这是一个非常有意的设计决定。如果您查看 FAQ for package:dart_style,您会在“为什么我不能配置它?”下面找到以下内容。部分:
The formatter supports very few tweakable settings, by design. If you look up at the list of priorities above, you'll see configurability goes directly against the first two priorities, and halfway against the third (you have to think about it, but not apply it).
This may be surprising, but the goal of dartfmt is not to automatically make your code look the way you like. It's to make everyone's Dart code look the same. The primary goal of dartfmt is to improve the quality of the Dart ecosystem. That transitively improves the live's of each Dart developer as well—you get more code to reuse, more consistent code, it's easier to read and contribute to each other's code, etc. But it does that at the expense of individual preference.
Dart 格式化程序遵循 "analysis_options.yaml" 文件中规定的 linter 样式规则。可以找到文件的描述 here. A complete list of linter rules can be found here.
您还可以订阅通用风格指南,例如 pedantic, a package with the style guide used internally by Google, or lint,这是另一个支持所有既不矛盾也不自以为是的规则的软件包。
话虽这么说,但我认为您无法更改诸如 two-space 缩进之类的内容。为了尽可能保持 Dart 代码库之间的样式一致性,dartfmt 强制执行某些样式选择。
好的,所以标题可能有点误导,这只是我的最终目标。
那么,我刚刚进入 Dart 的世界。到目前为止它看起来不错,但我最大的问题是愚蠢的默认格式化程序。特别是你无法摆脱它。我使用 WebStorm 主要是因为这些东西的可定制性。但是我还没有找到任何方法来更改飞镖的格式化程序(请参阅随附的屏幕截图)。 Dart 格式化程序强制执行 2-space 缩进和许多其他仅由它强制执行的令人恼火的代码样式。
是否可以通过某种方式同时更改配置选项或格式化程序?如果必须对源进行更改,那是可行的,或者只是玩弄一些 WebStorm 配置,那也很好,我只想更改它。
谢谢
您无法更改 dartfmt
使用的格式样式,这是一个非常有意的设计决定。如果您查看 FAQ for package:dart_style,您会在“为什么我不能配置它?”下面找到以下内容。部分:
The formatter supports very few tweakable settings, by design. If you look up at the list of priorities above, you'll see configurability goes directly against the first two priorities, and halfway against the third (you have to think about it, but not apply it).
This may be surprising, but the goal of dartfmt is not to automatically make your code look the way you like. It's to make everyone's Dart code look the same. The primary goal of dartfmt is to improve the quality of the Dart ecosystem. That transitively improves the live's of each Dart developer as well—you get more code to reuse, more consistent code, it's easier to read and contribute to each other's code, etc. But it does that at the expense of individual preference.
Dart 格式化程序遵循 "analysis_options.yaml" 文件中规定的 linter 样式规则。可以找到文件的描述 here. A complete list of linter rules can be found here.
您还可以订阅通用风格指南,例如 pedantic, a package with the style guide used internally by Google, or lint,这是另一个支持所有既不矛盾也不自以为是的规则的软件包。
话虽这么说,但我认为您无法更改诸如 two-space 缩进之类的内容。为了尽可能保持 Dart 代码库之间的样式一致性,dartfmt 强制执行某些样式选择。