[英]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!
為了完整起見,這是我的醫生 output:
$ 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 工作嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.