Define a linter rule for flutter and dart

1.3k Views Asked by At

As you know there are some pre-defined rules for linter, but I wonder how can I define a custom linter rule for flutter and dart?

2

There are 2 best solutions below

0
On BEST ANSWER

You would need to write a plugin for the analysis server, but the docs caution:

Note: The plugin support is not currently available for general use.

Just in case you want to ignore that, look at the analyzer docs at: https://pub.dev/packages/analyzer_plugin and the linter docs at: https://github.com/dart-lang/linter/blob/master/doc/WritingLints.MD

0
On

You need to add the analyzer package to your dependencies and then make a analysis_options.yaml file in the root of your project. in there you can import other analyzer rules like effective_dart or add the ones that you need from the lint rule list.

Here is an example for analysis_options.yaml:

linter:
  rules:
    - camel_case_types
    - empty_constructor_bodies