如何将Flutter Lint规则设置为错误并防止应用程序构建

发布于 2025-01-17 16:58:06 字数 586 浏览 1 评论 0原文

我的目标是实施一套 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余生共白头 2025-01-24 16:58:06

您可以在构建之前在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文