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;
}
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.
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.
To ignore a rule
Use ignore_for_file
instead of simple ignore
:
// ignore_for_file: prefer_final_fields (WORKS)
class Class {
var _count = 0;
var _count2 = 0;
}
Open analysis.options.yaml
file located at the root of your project and add the following lines:
linter:
rules:
prefer_final_fields: false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With