dart-code-metrics icon indicating copy to clipboard operation
dart-code-metrics copied to clipboard

[Rule change] When excluding files in `check-unnecessary-nullable`, such as `.g.dart`, should take their method *calls* into consideration, while ignoring methods *defined* there

Open fzyzcjy opened this issue 3 years ago • 5 comments

What rule do you want to change?

Hi thanks for the wonderful package!

A very common example is json_serializable. We may have a class class A {final int? field; A(this.field); } that is json serializable. With excluding .g.dart, the linter warns that the field is unnecessarily null, while we all know it is meaningful to be nullable because it deserializes some data from the network which is often nullable in many specific use cases.

How will the change be implemented? (New option, new default behavior, etc.)?

Please provide some example code that this change will affect:

What does the rule currently do for this code?

What will the rule do after it's changed?

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

fzyzcjy avatar Aug 25 '22 12:08 fzyzcjy

That's interesting, this should be handled, will take a look

incendial avatar Aug 28 '22 11:08 incendial

@fzyzcjy hm, looking closer to that and it seems that's an edge case. Could you provide the code example so I could write tests for it and correctly handle what needs to be excluded?

incendial avatar Sep 09 '22 11:09 incendial

I also cannot provide a very good example without giving you a ton of code...

Anyway, I workaround by letting it output in json, and write down a python postprocessor to filter unneeded things. Thanks all the same!

fzyzcjy avatar Sep 09 '22 11:09 fzyzcjy

A ton of code is alright for me, if it doesn't bother you to share. I think that's a valid use-case to be ignored, so a ton of code is not a blocker 😄

incendial avatar Sep 09 '22 11:09 incendial

Well those code are not open-source yet :/ Anyway I will share if I later see it in my open source projects. Thanks :)

fzyzcjy avatar Sep 09 '22 11:09 fzyzcjy

@fzyzcjy I'll close this for now. Feel free to reopen when you have an example

incendial avatar Oct 09 '22 10:10 incendial