Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

[New rule] annotation-on-invalid-class #1071

Open
3 tasks
fzyzcjy opened this issue Nov 6, 2022 · 4 comments
Open
3 tasks

[New rule] annotation-on-invalid-class #1071

fzyzcjy opened this issue Nov 6, 2022 · 4 comments
Assignees
Labels
area-rules type: enhancement New feature or request

Comments

@fzyzcjy
Copy link
Contributor

fzyzcjy commented Nov 6, 2022

Please describe what the rule should do:

Just a tiny rule, recorded here in case someone else is also interested in it :)

For example, in https://github.com/mobxjs/mobx.dart, we should use @observable, @computed, etc, only on a subclass of Store. If not, we have a bug because that annotation will not generate code needed for an observable/computed, and we will not see any compile time error, but only runtime error.

Other library with annotations may have the same problem I guess.

If your rule is inspired by other please provide link to it:

What category of rule is this? (place an "X" next to just one item)

  • Warns about a potential error (problem)
  • Suggests an alternate way of doing something (suggestion)
  • Other (please specify:)

Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):

class _Hello with Store {
  @observable int a=10;
  @computed double get b=> ...;
}

class Another {
  @observable int a=10; // LINT, it is used on non-Store
  @computed double get b=> ...; // LINT, it is used on non-Store
}

Are you willing to submit a pull request to implement this rule?

@incendial
Copy link
Member

@fzyzcjy interesting use-case, maybe we should have a separate rules set for flutter-mobx? Do you have other rule ideas?

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Nov 6, 2022

@incendial Not sure whether this idea is useful: In mobx, we should write down the following boilerplate

class Counter = CounterBase with _$Counter;

abstract class CounterBase with Store {
...
}

(Or, in the old days CounterBase used to be _Counter by convention).

So maybe if the user names the class wrongly, we can lint it?

@incendial
Copy link
Member

This might be a good stylistic rule, do you have anything else?

@fzyzcjy
Copy link
Contributor Author

fzyzcjy commented Nov 6, 2022

Not sure about this one: https://github.com/mobxjs/mobx.dart#readonly

A stylistic rule may be, forbid @observable and only allow @readonly (because we may want things not to be modifiable from outside without actions)

@incendial incendial added type: enhancement New feature or request area-rules labels Dec 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-rules type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants