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

Convert Binding to SLOOP Dto #5237

Merged

Conversation

ugras-ergun-sonarsource
Copy link
Contributor

Fixes #5229

@ugras-ergun-sonarsource
Copy link
Contributor Author

Most of the files are packages changes they're in different commits. Look at the 2nd commit for the real changes.


public IEnumerable<T> GetServerConnectionConfiguration<T>() where T : ServerConnectionConfiguration
{
if (bindingList == null) { InitBindingList(); }

Choose a reason for hiding this comment

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

How is this going to handle new connections added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am going to handle that while doing the handle new binding ticket.

Choose a reason for hiding this comment

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

But why make this class stateful in the first place then? You can make it always get the most relevant data, and then add caching later if you need to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was planning to have an add method later and add to list (if the conn does not exist already). I don't want to do IO operation everytime we call this class, I know probably I won't be that much but still.

Choose a reason for hiding this comment

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

Why add that method here and not create a caching wrapper for IBindingRepository?

return true;
}

if (x == null && y == null) { return true; }
Copy link
Contributor

Choose a reason for hiding this comment

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

is null everywhere around


if (x == null && y == null) { return true; }

if (x == null ^ y == null)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is intuitively easier to understand, and does the same thing.

Suggested change
if (x == null ^ y == null)
if (x == null || y == null)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but they are not the same I want to XOR them it should be true when they're both null.

return true;
}

if (x == null && y == null) { return true; }
Copy link
Contributor

Choose a reason for hiding this comment

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

The formatting is inconsistent around (single-line if vs. multi-line if)

{
return true;
}
//XOR it's true only when one of them is true

Choose a reason for hiding this comment

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

why xor when you check that both are true in the condition above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think having an OR there would be misleading when the intended behaviour is XOR is confusing, even the case when both true are covered by the expression before.

Choose a reason for hiding this comment

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

No, it's not misleading. You don't just forget the condition above when you read code. XOR is so infrequently used that it's actually more confusing to see it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not agree but it's a so trivial issue that doesn't deserve any more discussion about it.

return false;
}

return x.ServerUri == y.ServerUri;

Choose a reason for hiding this comment

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

I would use Equals instead just to be safe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

== is already overridden for Uri, so it wouldn't be safer also if the ServerUri of the first Uri were null somehow (It shouldn't be), it would create an exception.

Choose a reason for hiding this comment

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

The fact that == is overriden is an additional knowledge that is not apparent at the first glance. It's more natural to see Equals delegation inside Equals. Also, the uri is never null there. There's a check in the constructor

}
}

return bindingList.OfType<T>();

Choose a reason for hiding this comment

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

This doesn't make much sense after you removed caching. I would return the list of ServerConnectionConfiguration and let the caller filter that instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

caller can still do it if they pass ServerConnectionConfiguration as T.

Choose a reason for hiding this comment

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

But if they don't, they will do IO twice. There's no need for this generic now.


public int GetHashCode(BoundSonarQubeProject obj)
{
return obj.ServerUri.GetHashCode();

Choose a reason for hiding this comment

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

You check for null in Equals, but not here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to here it's the expected behaviour.

namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.Binding
{
[TestClass]
public class ServerConnectionConfigurationProviderTests

Choose a reason for hiding this comment

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

Missing MEF tests

Copy link

@georgii-borovinskikh-sonarsource georgii-borovinskikh-sonarsource merged commit e593fa9 into feature/sloop-rule-meta-data Feb 21, 2024
7 checks passed
@georgii-borovinskikh-sonarsource georgii-borovinskikh-sonarsource deleted the ue/bindingToDto branch February 21, 2024 10:44
ugras-ergun-sonarsource added a commit that referenced this pull request Feb 28, 2024
ugras-ergun-sonarsource added a commit that referenced this pull request Apr 3, 2024
ugras-ergun-sonarsource added a commit that referenced this pull request Apr 3, 2024
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.

Convert Binding to SLOOP Dto
3 participants