Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a linting rule inline in flutter

Tags:

Is there a way to disable a linting rule for a line in flutter?

I have a specific use case where I want to disable linting for two lines. I have a lot of business logic already written so I cannot change the code.

abstract class ReviewName {   static final NEW = 'NEW';   static final OLD = 'OLD'; } 

The above code will have linting errors: Name non-constant identifiers using lowerCamelCase.dart(non_constant_identifier_names)

Is there any way I avoid the lint error for only the two lines?

like image 213
SRAVAN Avatar asked May 30 '19 16:05

SRAVAN


People also ask

How do you turn on lint in Flutter?

Enabling default Lint Rules. You can use the Dart linter (Which is a recommendation from the Dart Team), or the Flutter_lints package which extends the dart linter for Flutter, it contains recommended sets of lints for your Flutter Applications and packages.

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

General answer

To ignore a single line, you can add a comment above the line:

// ignore: non_constant_identifier_names final NEW = 'NEW'; 

To ignore for the whole file, you can add a comment at the top of the file:

// ignore_for_file: non_constant_identifier_names 

To ignore for the whole project, you can set the rule to false in your analysis_options.yaml file:

include: package:lints/recommended.yaml  linter:   rules:     non_constant_identifier_names: false 

See also

  • Customizing static analysis
  • Setting up Lint Rules in Dart-Flutter
like image 182
Suragch Avatar answered Sep 20 '22 01:09

Suragch