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

Remove Regex from analyzers #81

Merged
merged 7 commits into from
Jun 12, 2024

Conversation

MattKotsenas
Copy link
Collaborator

@MattKotsenas MattKotsenas commented Jun 12, 2024

Replace using a Regex on string-ified type names with the proper Roslyn API (usually Identifier.Name) and do some 'straightening' of the code using early-returns and pattern matching to reduce the triangle-ness.

This is effectively a rewrite of AsShouldBeUsedOnlyForInterfaceAnalyzer. There's a smaller refactor for CallbackSignatureShouldMatchMockedMethod* as that code needs to be shared between the analyzer and the code fix provider (will be handled later)

This refactor has a few benefits:

  1. It addresses the bug mentioned in Upgrade (or at least test) with a newer version of Moq #58 (testing with a newer version is coming in another PR to keep code reviewable)
  2. It improves performance a good amount using very basic Visual Studio tracing (e.g. ~20 fewer string allocations and saves 30% [20 ms] on a single call to Analyzer.Analyze())
  3. It plumbs the CancellationToken into more places to be a good IDE citizen

This PR also starts to break apart the monolithic Helpers class into smaller components. In order to support the .TryXXX pattern I needed to bring in a polyfill for [NotNullWhen] for nullability analysis. I'm using PolySharp because, in addition to being the most popular polyfill, it uses a source generator to add polyfills to the current assembly, which avoid assembly loading overhead and the hassle of adding dependencies to the analyzer.

@MattKotsenas MattKotsenas force-pushed the refactor/remove-regex branch from 53e1081 to a4bb21e Compare June 12, 2024 07:06
@MattKotsenas MattKotsenas requested a review from rjmurillo June 12, 2024 07:08
@MattKotsenas MattKotsenas enabled auto-merge (squash) June 12, 2024 17:19
@MattKotsenas MattKotsenas requested a review from rjmurillo June 12, 2024 18:51
@MattKotsenas MattKotsenas merged commit dad8699 into rjmurillo:main Jun 12, 2024
4 checks passed
@github-actions github-actions bot added dependencies Pull requests that update a dependency file build labels Jun 24, 2024
@MattKotsenas MattKotsenas deleted the refactor/remove-regex branch October 23, 2024 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build dependencies Pull requests that update a dependency file enhancement housekeeping
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants