Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore a lint rule for entire file in Flutter?

Tags:

flutter

dart

I am able to ignore the rule for individual variables like this:

class Class {
  // ignore: prefer_final_fields
  var _count = 0;

  // ignore: prefer_final_fields
  var _count2 = 0;
}

I want to use something like this but it doesn't work. How can I ignore the lint for entire class?

// ignore: prefer_final_fields (DOESN'T WORK)
class Class {
  var _count = 0;

  var _count2 = 0;
}
like image 341
iDecode Avatar asked May 19 '20 11:05

iDecode


People also ask

What are linters flutter?

Linting is the process of checking the source code for Programmatic as well as Stylistic errors and unformatted code. It's helpful in identifying some common and uncommon mistakes that are made during coding like logical errors, unused variables, empty if-else statements among others.

What is Linter in Dart?

The linter gives you feedback to help you catch potential errors and keep your code in line with the published Dart Style Guide. Enforceable lint rules (or "lints") are cataloged here and can be configured via an analysis options file.


1 Answers

To ignore a rule

  • For entire file:

    Use ignore_for_file instead of simple ignore:

    // ignore_for_file: prefer_final_fields (WORKS)
    class Class {
      var _count = 0;
    
      var _count2 = 0;
    }
    
  • For whole project:

    Open analysis.options.yaml file located at the root of your project and add the following lines:

    linter:
      rules:
        prefer_final_fields: false
    
like image 101
iDecode Avatar answered Oct 03 '22 11:10

iDecode