Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BuildServiceProvider analyzer rule #192

Merged
merged 8 commits into from
Oct 17, 2024
Merged

Add BuildServiceProvider analyzer rule #192

merged 8 commits into from
Oct 17, 2024

Conversation

rannes
Copy link
Collaborator

@rannes rannes commented Oct 16, 2024

Closes #190

Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 79.66102% with 12 lines in your changes missing coverage. Please review.

Project coverage is 74.53%. Comparing base (5fe7cb1) to head (17bb2c1).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...lyzers/AgodaCustom/AG0043NoBuildServiceProvider.cs 80.70% 6 Missing and 5 partials ⚠️
...yzers/AgodaCustom/CustomRulesResources.Designer.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #192      +/-   ##
==========================================
+ Coverage   74.42%   74.53%   +0.11%     
==========================================
  Files          67       68       +1     
  Lines        2428     2486      +58     
  Branches      290      298       +8     
==========================================
+ Hits         1807     1853      +46     
- Misses        551      558       +7     
- Partials       70       75       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

DiagnosticSeverity.Error,
AnalyzerConstants.EnabledByDefault,
Description,
"https://github.com/agoda-com/AgodaAnalyzers/issues/190",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets do the documentation in the doc repo, not in issues, this will allow us to be more accurate, issues are chatty

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#193

I did another MR to update docs, i think replicate this.

Ideally these should be in our standards, but things like this is more of a bug than a standard, so i think we need a new ay to store like this

@joeldickson
Copy link
Contributor

When you make documentation, can you:

  • Provide teh reason why this is bad, and what the alternatives are to solve the problem that the developer was trying too
  • Provide example of both non-compliant and compliant code

Sonar has some good examples

https://rules.sonarsource.com/csharp/type/Code%20Smell/RSPEC-1163/

I've been trying my best like this

https://github.com/agoda-com/agoda-kraft/blob/main/doc/AG001.md

We probably need some sort of template

But look at it like this, you are a junior engineer, you see this error for the first tie in your IDE, what's the documentation you need to fix your problem? and save you from either

  • A. Escalating in Slack
  • B. Disabling the rule that you dont understand

{
var invocationExpr = (InvocationExpressionSyntax)context.Node;

// Check if it's a member access (e.g., something.BuildServiceProvider())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these comments add value? Personally I think that the code if ( something is MemberAccessExpressionSyntax) communicates well that we're checking if something is a member access (literally uses the same words).

DiagnosticSeverity.Error,
AnalyzerConstants.EnabledByDefault,
Description,
"https://github.com/agoda-com/AgodaAnalyzers/issues/190",
Copy link
Member

@szaboopeeter szaboopeeter Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting one, should we add to docs some examples for typical use-cases and how to solve them without BuildServiceProvider? Where I've seen this used most of the time is during constructing services that have their own dependencies, like in the registration of a lot of the thick-clients for agoda services. I assume the right way would be to just pass an IServiceProvider along, rather than building it?

(Ahh, I guess Joel was asking for the same, just see it in the comments after submitting, didn't notice sorry)

@joeldickson joeldickson merged commit 57aeae5 into master Oct 17, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stop usage of BuildServiceProvider()
3 participants