Flutter Dart 分析器不应用我的 linter 规则
Flutter Dart analyzer not applying my linter rules
我正在做一个非常标准的 Flutter 项目。因为我是 Flutter 和 Dart 的新手,所以我希望我的工具尽可能有用。所以我把 pedantic: ^1.9.0
添加到 dev_dependencies
并这样写 analysis_options.yaml
:
include: package:pedantic/analysis_options.yaml
analyzer:
exclude: [build/**]
strong-mode:
implicit-casts: false
implicit-dynamic: false
根据 https://dart-lang.github.io/linter/lints/,pedantic
应该启用 avoid_empty_else
和 avoid_relative_lib_imports
lints,作为错误。但是当我写这样的代码时:
import '../model/model.dart';
或者这个:
if (context == null) {
print('context is null');
} else {
}
我在 IntelliJ IDEA 中没有收到任何错误,手动 运行 flutter analyze
时也没有收到任何错误:
$ flutter analyze
Analyzing app...
No issues found! (ran in 5.0s)
我已尝试明确启用这些 lints:
linter:
rules:
- avoid_empty_else
- avoid_relative_lib_imports
这没有任何区别。
我尝试向该列表添加一个不存在的 lint foo
以验证该文件是否正在使用,它是:
$ flutter analyze
Analyzing app...
warning • 'foo' is not a recognized lint rule • analysis_options.yaml:12:7 • undefined_lint_warning
1 issue found. (ran in 4.9s)
我什至尝试 运行直接从 Flutter 安装目录中安装 dartanalyzer
,使用我能找到的所有详细选项:
$ ~/flutter/bin/cache/dart-sdk/bin/dartanalyzer --lints --verbose --log --options analysis_options.yaml .
Analyzing app...
Loaded analysis options from analysis_options.yaml
Analysis options: lints = true
No issues found!
为了完整起见,这是我的医生输出:
$ flutter doctor -v
[✓] Flutter (Channel stable, v1.17.1, on Linux, locale en_US.UTF-8)
• Flutter version 1.17.1 at /home/thomas/flutter
• Framework revision f7a6a7906b (5 days ago), 2020-05-12 18:39:00 -0700
• Engine revision 6bc433c6b6
• Dart version 2.8.2
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /opt/android-sdk
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = /opt/android-sdk
• ANDROID_SDK_ROOT = /opt/android-sdk
• Java binary at: /usr/lib/jvm/default/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-b08)
• All Android licenses accepted.
[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
[✓] IntelliJ IDEA Community Edition (version 2019.3)
• IntelliJ at /usr/share/jetbrains-idea-ce
• Flutter plugin version 44.0.3
• Dart plugin version 193.6911.31
[✓] Connected device (1 available)
• FP2 • 1e95f6f3 • android-arm • Android 7.1.2 (API 25)
! Doctor found issues in 1 category.
我还应该做些什么来让 linter 工作吗?
啊,所以... linter 工作正常;只是我的假设被打破了。
avoid_empty_else
不检查空的 {}
块,而只检查 else
之后的 ;
,这就是它没有触发的原因。
avoid_relative_lib_imports
literally only checks 用于路径名称中包含 /lib/
的相对导入,不适用于其目标解析为 lib/
.[=19 中的某个文件的相对导入=]
无赖。我希望完全禁止相对导入,但是 that's still unimplemented.
我正在做一个非常标准的 Flutter 项目。因为我是 Flutter 和 Dart 的新手,所以我希望我的工具尽可能有用。所以我把 pedantic: ^1.9.0
添加到 dev_dependencies
并这样写 analysis_options.yaml
:
include: package:pedantic/analysis_options.yaml
analyzer:
exclude: [build/**]
strong-mode:
implicit-casts: false
implicit-dynamic: false
根据 https://dart-lang.github.io/linter/lints/,pedantic
应该启用 avoid_empty_else
和 avoid_relative_lib_imports
lints,作为错误。但是当我写这样的代码时:
import '../model/model.dart';
或者这个:
if (context == null) {
print('context is null');
} else {
}
我在 IntelliJ IDEA 中没有收到任何错误,手动 运行 flutter analyze
时也没有收到任何错误:
$ flutter analyze
Analyzing app...
No issues found! (ran in 5.0s)
我已尝试明确启用这些 lints:
linter:
rules:
- avoid_empty_else
- avoid_relative_lib_imports
这没有任何区别。
我尝试向该列表添加一个不存在的 lint foo
以验证该文件是否正在使用,它是:
$ flutter analyze
Analyzing app...
warning • 'foo' is not a recognized lint rule • analysis_options.yaml:12:7 • undefined_lint_warning
1 issue found. (ran in 4.9s)
我什至尝试 运行直接从 Flutter 安装目录中安装 dartanalyzer
,使用我能找到的所有详细选项:
$ ~/flutter/bin/cache/dart-sdk/bin/dartanalyzer --lints --verbose --log --options analysis_options.yaml .
Analyzing app...
Loaded analysis options from analysis_options.yaml
Analysis options: lints = true
No issues found!
为了完整起见,这是我的医生输出:
$ flutter doctor -v
[✓] Flutter (Channel stable, v1.17.1, on Linux, locale en_US.UTF-8)
• Flutter version 1.17.1 at /home/thomas/flutter
• Framework revision f7a6a7906b (5 days ago), 2020-05-12 18:39:00 -0700
• Engine revision 6bc433c6b6
• Dart version 2.8.2
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /opt/android-sdk
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = /opt/android-sdk
• ANDROID_SDK_ROOT = /opt/android-sdk
• Java binary at: /usr/lib/jvm/default/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-b08)
• All Android licenses accepted.
[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).
[✓] IntelliJ IDEA Community Edition (version 2019.3)
• IntelliJ at /usr/share/jetbrains-idea-ce
• Flutter plugin version 44.0.3
• Dart plugin version 193.6911.31
[✓] Connected device (1 available)
• FP2 • 1e95f6f3 • android-arm • Android 7.1.2 (API 25)
! Doctor found issues in 1 category.
我还应该做些什么来让 linter 工作吗?
啊,所以... linter 工作正常;只是我的假设被打破了。
avoid_empty_else
不检查空的 {}
块,而只检查 else
之后的 ;
,这就是它没有触发的原因。
avoid_relative_lib_imports
literally only checks 用于路径名称中包含 /lib/
的相对导入,不适用于其目标解析为 lib/
.[=19 中的某个文件的相对导入=]
无赖。我希望完全禁止相对导入,但是 that's still unimplemented.