flutter_corelibrary icon indicating copy to clipboard operation
flutter_corelibrary copied to clipboard

Add linter rule to disallow string literals in `Widget` classes

Open bdmendes opened this issue 3 months ago • 1 comments

Closes #260 This linter rule makes code review easier for internationalized apps, by preventing the usage of string literals in widgets.

This may be annoying, since we need string literals for things other than UI inside a widget's class, and it's not possible (at least from what I've seen from the analyzer API) to guarantee with a 100% certainty that they are being used in that context. As such, I added 2 simple exceptions:

  • When handling an exception: so that we can log it/send to a server
  • When throwing an exception: so that we can define a proper message

Furthermore, there are some things we should discuss:

  • Should we make these ancestor exceptions configurable?
  • Should the exceptions be related instead to e.g. the name of the function that is being invoked?

bdmendes avatar Mar 22 '24 19:03 bdmendes