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

[New rule] Ensure dispose/close called #1229

Closed
1 task
Ravensof opened this issue May 3, 2023 · 18 comments
Closed
1 task

[New rule] Ensure dispose/close called #1229

Ravensof opened this issue May 3, 2023 · 18 comments
Assignees
Labels
area-rules type: enhancement New feature or request

Comments

@Ravensof
Copy link

Ravensof commented May 3, 2023

Rule details

i want to be sure that my classes canceled/disposed, like Sink`s

What type of rule is this?

Warns about a potential problem

Example code

class CustomClass {
  void disposeFunction()
}

// bad

final custom = CustomClass() // lint, forgot to use disposeFunction

// good

final custom = CustomClass() // no lint
...
custom.disposeFunction()

Participation

  • I am willing to submit a pull request to implement this rule.

Additional comments

No response

@incendial
Copy link
Member

@Ravensof can you elaborate on when exactly dispose is supposed to be called? Right now it's not clear at all.

@Ravensof
Copy link
Author

Ravensof commented May 3, 2023

@incendial
sorry, dont know how to say it correct.
i want it works something like lint rule for sinks https://dart-lang.github.io/linter/lints/close_sinks.html

just defines in analysis_options.yaml something like

dart_code_metrics:
  rules:
    close_disposable:
      -  DisposableMixin.dispose

then create class

class CustomClass with DisposableMixin { }

and when i create new object which is DisposableMixin there should be check that dispose ever called for that new object (or for variable where it was created)

@incendial
Copy link
Member

Called where?

@incendial
Copy link
Member

I mean there are multiple places where dispose can be called. For example, if it's a local variable and it is passed to another function, it can be disposed in two places. So it's not clear where the warning should appear.

Or you mean only class fields?

@Ravensof
Copy link
Author

Ravensof commented May 3, 2023

warning should be appear in places where disposable object were created

image

@incendial
Copy link
Member

incendial commented May 3, 2023

Got it, the fields.
This rule is available in the Teams version https://dcm.dev/docs/rules/flutter/dispose-fields/. No plans to add to the free version.

@incendial incendial closed this as not planned Won't fix, can't repro, duplicate, stale May 3, 2023
@Ravensof
Copy link
Author

Ravensof commented May 3, 2023

i dont know how its better in cases when disposable passed to another function.

in one side you have to dispose object in that level where you create it.
but dont know how to be here:

          Provider<Repository>(
            create: (context) => Repository(),
            dispose: (context, value) => value.dispose(),
          ),

maybe passing to another function should be counted as call dispose (like with lint close_sinks rule)

@incendial
Copy link
Member

The case with providers is also covered by another Teams rule, that will become available in few days.

@Ravensof
Copy link
Author

Ravensof commented May 3, 2023

Got it, the fields. This rule is available in the Teams version https://dcm.dev/docs/rules/flutter/dispose-fields/. No plans to add to the free version.

thanks, that was fast, but how to apply it to my class? it just checking method named dispose?

@incendial
Copy link
Member

Yes. After the release of 1.4.0, it will also check for 'close' and 'cancel'.

@Ravensof
Copy link
Author

Ravensof commented May 3, 2023

okay, thanks again

@incendial
Copy link
Member

incendial commented May 8, 2023

@Ravensof and the second part you've asked for https://dcm.dev/docs/rules/provider/dispose-providers/, covers the dispose calls in Provider's dispose.

@Ravensof
Copy link
Author

Ravensof commented May 9, 2023

@incendial thanks, im appreciate it. it could be very useful, but we cant use teams version, i didnt even knew it exists -_-'

@incendial
Copy link
Member

but we cant use teams version,

What stops you from it?

@Ravensof
Copy link
Author

Ravensof commented May 9, 2023

but we cant use teams version,

What stops you from it?

because of politics visa/master_card not working in our country.
even it works, for my application (which is hobby) its expensive,
and for job i just cant say to my employeer that we need to buy teams version because of one rule :[

@incendial
Copy link
Member

and for job i just cant say to my employeer that we need to buy teams version because of one rule :[

Is it really only one rule?

@Ravensof
Copy link
Author

Ravensof commented May 9, 2023

Is it really only one rule?

we're feeling fine with free version. as i said we didnt knew about teams version and didnt check its benefits

@Ravensof
Copy link
Author

Ravensof commented May 9, 2023

i found some useful rules for myself, but im a regular programmer and i dont feel i have a chance to suggest it for business.
btw thanks for help 😅

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

2 participants