Dart:如何忽略omit_local_variable_types警告? [英] Dart : How to ignore omit_local_variable_types warning?
问题描述
我正在使用IntelliJ Idea与Dart / Flutter开发移动应用程序以及Web前端。 Dart的当前版本警告正确键入局部变量。有Dart样式指南 https://dart-lang.github.io/ linter / lints / omit_local_variable_types.html 说:通常,可以很容易地推断出局部变量的类型,因此不必对它们进行注释。
I'm developing a mobile app plus web frontend with Dart / Flutter with IntelliJ Idea. The current version of Dart warns about correctly typing local variables. There is a Dart style guide https://dart-lang.github.io/linter/lints/omit_local_variable_types.html saying "Usually, the types of local variables can be easily inferred, so it isn't necessary to annotate them."
这对于编译器可能是正确的,但对于人类读者来说肯定不是正确的。由于它特别使类型使用问题推迟到变量的使用部分,因此错误检测和代码读取变得越来越昂贵。
This might be true for a compiler but it sure is not true for human readers. Since it especially defers type problems to the usage part of a variable, bug detection and code reading is becoming more expensive.
那么如何在编译器/项目级别禁用此警告?
So how can I disable this warning on compiler / project level?
甚至更好:如果未设置类型,如何强制警告?
Even better: how can I force a warning if the type is not set?
推荐答案
我知道这有点旧,但是我看不到答案,所以现在在此处添加以供将来使用。
I know this is a bit old, but I see there isn’t an answer, so adding here now for future use.
在项目文件夹的根目录中,添加一个 analysis_options.yaml文件,并包含以下代码。在以下位置进一步阅读: https://dart.dev/guides/language/analysis-options
In the root of your project folder, add an "analysis_options.yaml" file, and include the below code. Read further at: https://dart.dev/guides/language/analysis-options
analysis _options.yaml:
analysis _options.yaml:
linter:
rules:
always_specify_types: true
omit_local_variable_types: false
不确定两者始终指定类型时必须使用,但请放手。
Unsure if both are required when always specifying types, but give it a go.
这篇关于Dart:如何忽略omit_local_variable_types警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!