[Analyzer Proposal]: Propagate StringSyntaxAttribute

Open
#110,305 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
38/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
csharp

Research direction

Start with the analyzer's invocation analysis, then trace IParameterReferenceOperation handling and how parameter attributes are inspected. Verify the behavior against calls whose callee parameter has StringSyntaxAttribute: the referenced parameter should require a matching attribute, with analyzer tests covering the supported cases.

Written by the indexing model from the issue text.

Description

api-suggestion area-System.Runtime.CompilerServices code-analyzer
Background and motivation

StringSyntaxAttribute was introduced to support IDE highlighting scenarios, such as Regex.

Often, users have existing helper methods that may be forwarding a parameter to a method (likely a BCL method, e.g Regex.IsMatch) that has the attribute, but the user doesn't add the attribute.

API Proposal

An analyzer is introduced that will analyze invocations and roughly have the following functionality

  1. Look at the parameters of the invoked method for a parameter with StringSyntaxAttribute
  2. If found, look at the argument corresponding to that parameter.
  3. If the argument is an IParameterReferenceOperation, look into the attributes of that parameter and require a matching attribute.
API Usage

N/A

Alternative Designs

No response

Risks

No response

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.