Home > other >  How to set flutter lint rules as an error and prevent application to build
How to set flutter lint rules as an error and prevent application to build

Time:03-29

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?

CodePudding user response:

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.

  • Related