0

I would like to write a new custom linter rule.

Especially, I want to write a rule that forbids the use of the setState function in flutter.

Is there any solution to customize your linter rules out there?

andrewJames
  • 19,570
  • 8
  • 19
  • 51
  • I have no experience with it, but there is a [custom_lint](https://pub.dev/packages/custom_lint) package that allows creating custom rules. However, using it requires running a separate command and not the usual `dart analyze`/`flutter analyze` commands. – jamesdlin Jul 14 '22 at 07:28

2 Answers2

0

Yes, you can certainly do that. But why would you want to ban setState?

Randal Schwartz
  • 39,428
  • 4
  • 43
  • 70
  • I agree, why would you do that? However, you can't customize the analyzer to do what the question asked via analysis_options.yaml. It would require custom hooks into the analysis server which is much more involved. But again... why would you ban `setState`? – Nico Spencer Jul 14 '22 at 03:52
0

Doing this kind of analysis would require an analysis server plugin. There's is an API and a Analyzer Plugin Package to do this as well as a view examples of projects using it.

Examples:

Nico Spencer
  • 940
  • 6
  • 11