app icon indicating copy to clipboard operation
app copied to clipboard

Enable static analysis using pedantic for client flutter code

Open myiremark opened this issue 4 years ago • 27 comments

myiremark avatar Mar 26 '20 15:03 myiremark

https://pub.dev/packages/pedantic

myiremark avatar Mar 26 '20 16:03 myiremark

@myiremark please elaborate a bit on what you mean with this issue!

SamMousa avatar Mar 26 '20 19:03 SamMousa

I'm not an expert in Dart/Pedantic, so I won't be able to perfectly elaborate on their differences.

We'd like to not just make sure the code is styled consistently and the way we want it written ala linter e.g Pedantic, we'd like to make sure it evaluates as intended securely and avoids common vulnerabilities at minimum.

It looks like Pedantic is actually built into Dart's static analysis tool in their SDK.

https://github.com/dart-lang/sdk/tree/master/pkg/analyzer

I can't speak to its abilities.

One suggestion I'm more familiar with was https://www.sonarqube.org/.

Dart is not immediately available as being a supported language.

Dart's analyzer may provide equivalent capabilities.

Perhaps a flutter expert can.expound?

myiremark avatar Mar 26 '20 19:03 myiremark

Pedantic provides a common set of analysis lints (code style rules) that are "recommended" for larger team projects. It's also possible to just provide custom analysis rules in your analysis_options.yaml, but the advantage of pedantic is that people are likely familiar with it and it's easy to just drop in.

dnfield avatar Mar 26 '20 21:03 dnfield

And it's maintained by the Googler who manages what lints are applied on Google's Dart based projects.

dnfield avatar Mar 26 '20 21:03 dnfield

I'm a fan of using an opinionated tool chosen by an expert over us spinning our own. Recommend: Go with pedantic.

advayDev1 avatar Mar 26 '20 21:03 advayDev1

Already a PR open for pedantic btw

SamMousa avatar Mar 26 '20 21:03 SamMousa

I use this analysis rule "pedantic_mono" that derives from pedantic: https://pub.dev/packages/pedantic_mono

https://github.com/dart-lang/pedantic + https://github.com/flutter/samples

Its strict rules will provide consistent formatting among wide range of contributors.

suztomo avatar Mar 27 '20 12:03 suztomo

It lacks a bit of documentation though; @suztomo could you summarize the reasoning behind those rules?

SamMousa avatar Mar 27 '20 12:03 SamMousa

The reasoning is that the more static analysis rules (that Google's Flutter team uses) more consistent the code will become.

While I don't care the reasoning behind each rule; for example, I don't believe constructors should come first (sort_constructors_first), I do think consistency matters, especially when there are many contributors with many backgrounds.

suztomo avatar Mar 27 '20 13:03 suztomo

I follow your reasoning, are you up for making a PR?

SamMousa avatar Mar 27 '20 13:03 SamMousa

Yes, aiming for this weekend. Note that my suggestion does not block onboarding to pedantic.

suztomo avatar Mar 27 '20 13:03 suztomo

Yes, aiming for this weekend. Note that my suggestion does not block onboarding to pedantic.

That's already been merged. Will leave this open for someone else to pick up, be sure to check back here before you start on your implementation!

Thanks!

SamMousa avatar Mar 27 '20 13:03 SamMousa

There is already a PR for basic pedantic, that part is good. The addition would the rules in the mono package.

SamMousa avatar Mar 27 '20 15:03 SamMousa

@dnfield would love your opinion on adding the rules from the mono package mentioned earlier.

SamMousa avatar Mar 27 '20 15:03 SamMousa

@SamMousa I cannot seem to find that PR.

I think that the rules in mono are somewhat arbitrarily chosen by the author. Considering, pedantic is maintained by the Dart team, it seems like a more reasonable choice. Custom rules can also be added manually.

I think that the rules in mono are somewhat arbitrarily chosen by the author.

I agree

Considering, pedantic is maintained by the Dart team, it seems like a more reasonable choice. Custom rules can also be added manually.

What's your recommendation? Sticking with default pedantic, with or without adding extra rules? What do you think about the arguments given above?

SamMousa avatar Mar 27 '20 15:03 SamMousa

I actually think that pedantic is already fairly strict and some rules like curly_braces_in_flow_control_structures are poorly implemented and should be excluded.

There are also other extended rule sets, like extra_pedantic, which is actually more popular than pedantic_mono, but they both have a low popularity score.

I'll discuss this during engineering standup, my recommendation based on your comments will be to use default pedantic for now.

(This is always a bit of personal preference, so I'd rather stick with the standard)

Thanks for adding to the discussion!

SamMousa avatar Mar 27 '20 15:03 SamMousa

@creativecreatorormaybenot

For my learning, would you be willing to explain the detail of this poor implementation?

curly_braces_in_flow_control_structures are poorly implemented

suztomo avatar Mar 27 '20 15:03 suztomo

@suztomo Sure, I opened an issue about this https://github.com/dart-lang/site-www/issues/1994. This will probably be more insightful: https://github.com/dart-lang/linter/issues/1763

I realized now that the pedantic dependency was recently added: https://github.com/WorldHealthOrganization/app/pull/339

Any insight on why they are not using the latest version?

It would probably be best to just add or remove lints as the project sees fit beyond pedantic. I am not familiar with pedantic_mono.

dnfield avatar Mar 27 '20 16:03 dnfield

@creativecreatorormaybenot Thank you.

suztomo avatar Mar 27 '20 16:03 suztomo

https://github.com/flutter/flutter/blob/master/analysis_options.yaml These are the rules used in the Flutter repo, hopefully we can tighten up on code style soon by copying these in where appropriate.

britannio avatar Apr 10 '20 19:04 britannio

Let's keep issues focused, updated title

advayDev1 avatar Apr 20 '20 14:04 advayDev1

This item has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 01 '20 04:12 stale[bot]