如何将Flutter Lint规则设置为错误并防止应用程序构建
我的目标是实施一套 lint 规则。在分析器中设置为错误的规则,因此在 Dart Analysis 中被评估为错误,必须阻止应用程序构建。
我在analysis_options.yaml中实现了很多lint规则:
analyzer:
errors:
always_use_package_imports: error
avoid_empty_else: error
...
linter:
rules:
always_use_package_imports: true
avoid_empty_else: true
...
每当不遵循这些规则之一时,Dart Analysis就会正确地将其显示为错误。一旦触发新的构建,它就会成功构建。在这种特殊情况下,我的目的是阻止 ios 或 android 成功构建。
我尝试添加此 app/build.gradle 文件,但没有成功。
android {
lintOptions {
abortOnError true
}
}
有其他方法可以解决 Android 或 iOS 的此问题吗?
My goal is to implement set of lint rules. Rule which is set in analyzer as an error and therefore in Dart Analysis is evaluated as error has to prevent application to build.
I have implemented lot of lint rules in analysis_options.yaml:
analyzer:
errors:
always_use_package_imports: error
avoid_empty_else: error
...
linter:
rules:
always_use_package_imports: true
avoid_empty_else: true
...
Everytime one of these rule is not followed, Dart Analysis correctly shows it as an error. Once a new build is triggered it successfully builds. In this particular case my intention is to prevent ios or android from successful build.
I have tried to add this app/build.gradle file, but it didn't work.
android {
lintOptions {
abortOnError true
}
}
Is there any other approach how to resolve this issue for Android or iOS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在构建之前在 CI 中执行flutteranalyze --no-fatal-infos --no-fatal-warnings,如果代码中存在错误,它应该在构建之前停止。
You could execute
flutter analyze --no-fatal-infos --no-fatal-warnings
in your CI before your build, it should stop before building if there are errors in your code.