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

Suggestion: when including SponsorLink in a project, call the integration project something other than <ProjectName>.CodeAnalyzers #60

Closed
stakx opened this issue Aug 25, 2023 · 11 comments
Labels
enhancement New feature or request

Comments

@stakx
Copy link

stakx commented Aug 25, 2023

Not actually a bug but a suggestion that I think could further help along acceptance of SponsorLink.

When SponsorLink got briefly introduced to Moq, people complained about it being obfuscated & closed-source. This has since been addressed, the point to take away here is that it was perceived as something that's got something to hide.

I noticed that SponsorLink was included in Moq as a project called Moq.CodeAnalyzers. This likewise seemed a little... disingenuous to me. Pardon the term, I don't mean to offend, but the point I'm trying to make is that it's once again easy to perceive this as an attempt to hide something.

While technically a Roslyn analyzer, SponsorLink doesn't really analyze code. The <ProjectName>.CodeAnalyzers project name ought to be reserved for actual code analysis; the SponsorLink integration would perhaps better be named more transparently, e.g. <ProjectName>.SponsorLinkIntegration. (Assuming you're free to name Roslyn analyzer projects whatever you want.)

@stakx stakx added the bug Something isn't working label Aug 25, 2023
@stakx stakx changed the title Suggestion: when including SponsorLink in a project, call the integrqtion project something other than <ProjectName>.CodeAnalyzers Suggestion: when including SponsorLink in a project, call the integration project something other than <ProjectName>.CodeAnalyzers Aug 25, 2023
@jeroenwalter
Copy link

jeroenwalter commented Aug 25, 2023

Well, I wouldn't put it past @kzu to actually start code analyzing and add red squiggly lines for each Moq call in case you didn't sponsor the project and an additional tooltip with a link to the sponsor page. He certainly has the know-how, reading his nice post in https://www.cazzulino.com/smart-libraries.html

@kzu
Copy link
Member

kzu commented Aug 25, 2023

Agreed with @jeroenwalter. The reason for having IDE-level features that enhance the experience is a good one where users might opt-in to sponsoring. Hence the generic name.

Moving forward, the SL check will not even involve any package dependency or the like, and will be entirely up to each package author how to implement it (could be a build task, analyzer, source generator, whatever).

SL itself will just provide the CLI tool to generate a manifest that can be checked by any tool from any language at any time, without involving network calls, and for whatever purposes the library author may deem useful. See https://github.com/devlooped/gh-sponsors for more info on that part of the experience.

@kzu kzu added enhancement New feature or request and removed bug Something isn't working labels Aug 25, 2023
@stakx
Copy link
Author

stakx commented Aug 25, 2023

@kzu, apologies if perhaps my issue wasn't opened in quite the right place, I understand that SL is flexible enough to be used in a variety of ways. I was mostly thinking about the specific instances where you will reintroduce SL to your projects in the future... such as Moq. Perhaps I should've opened the issue at the Moq repo even. I just wanted to raise awareness about naming the project (if there's gonna be one) since people might be sensitive even about that. :)

@kzu
Copy link
Member

kzu commented Aug 25, 2023

I think in general, since the goal is to provide enhanced functionality via analyzers/codefixers/codegen, the SL check will make no sense as a separate project decoupled from the main analyzers. I just need to come up with a great one to kickststart the analyzers project again 😉 .

BTW, entire analyzers project gone now: #65

@stakx
Copy link
Author

stakx commented Aug 25, 2023

I just need to come up with a great one to kickststart the analyzers project again 😉 .

Regarding Moq in particular, code analyzers have been discussed a few times before. One obvious use case for them would be to warn at compile-time about those cases where the library will throw ArgumentExceptions due to usage mistakes. Such as trying to setup any unsupported / non-overridable type member (extension methods!) or when providing lambas to setup.Callback or setup.Returns with a non-matching method signature. (The C# type system isn't powerful enough to catch that.) Just some ideas to get you started, I could probably dig up the Moq issue about it if needed.

@kzu
Copy link
Member

kzu commented Aug 25, 2023

Those are awesome ideas! I was thinking of a codefix that could transform a lengthy set of Setup(...).Returns(...) into the more idiomatic Linq to Mocks too, for example.

@jeroenwalter
Copy link

Those are awesome ideas! I was thinking of a codefix that could transform a lengthy set of Setup(...).Returns(...) into the more idiomatic Linq to Mocks too, for example.

Then take a look at how NSubstitute does that. No lengthy Setups with a ton of lambdas, I found that really much nicer than how Moq works.

Also, NSubstitute has really helpful analyzers :)
https://nsubstitute.github.io/help/nsubstitute-analysers/

@kzu
Copy link
Member

kzu commented Aug 26, 2023

That's the direction v5 was going too, yeah. It may still happen, we'll see. Also, absolutely nobody has Linq to Mocks.

Mock.Of(x => x.This == 42 && x.That.Other(true, 25) == "yeah")

Perhaps you just aren't using Moq's full feature set ;)

@jeroenwalter
Copy link

No, I just never found the syntax of linq to mock intuitive or readable.
Also it's not well documented.
For instance, how do you use linq to mock with mocks that throw exceptions, or use callbacks?

@kzu
Copy link
Member

kzu commented Aug 26, 2023

You don't. It's for stubs, which is the way I personally use Moq the most.

@kzu
Copy link
Member

kzu commented Sep 2, 2023

I'm closing this for now. Proof that doing this will only make it trivial for unethical straight re-packaging is https://github.com/nike4613/unnugetizer. I don't think making it straightforward for folks that don't give a damn about OSS sustainability to strip off SL is a good thing for package authors that are struggling with precisely that issue.

@kzu kzu closed this as completed Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants