aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Add StringSyntax formats throughout source code

Open JamesNK opened this issue 3 years ago • 11 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

StringSyntaxAttribute is placed on strings to tell tooling what format the string will take. For example, regex, JSON, XML, date format string, etc. This is then used to provide helpful features such as completion of date format strings, regex/JSON/XML highlighting, analyzers, etc.

We should ensure all the ASP.NET Core strings have this attribute where appropriate, so ASP.NET Core APIs get tooling enhancements.

Describe the solution you'd like

Audit dotnet/aspnetcore source and add StringSyntax attribute with format strings as needed:

  • [x] CompositeFormat - The syntax identifier for strings containing composite formats for string formatting.
  • [ ] DateOnlyFormat - The syntax identifier for strings containing date format specifiers.
  • [ ] DateTimeFormat - The syntax identifier for strings containing date and time format specifiers.
  • [ ] EnumFormat - The syntax identifier for strings containing enum format specifiers.
  • [ ] GuidFormat - The syntax identifier for strings containing GUID format specifiers.
  • [ ] Json - The syntax identifier for strings containing JavaScript Object Notation (JSON).
  • [ ] NumericFormat - The syntax identifier for strings containing numeric format specifiers.
  • [ ] Regex - The syntax identifier for strings containing regular expressions. https://github.com/dotnet/aspnetcore/pull/40589
  • [ ] TimeOnlyFormat - The syntax identifier for strings containing time format specifiers.
  • [ ] TimeSpanFormat - The syntax identifier for strings containing TimeSpan format specifiers.
  • [ ] Uri - The syntax identifier for strings containing URIs.
  • [ ] Xml - The syntax identifier for strings containing XML.

This list is from https://github.com/dotnet/runtime/blob/664d7c68d53f2465b79de25fdd6827007216239f/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/StringSyntaxAttribute.cs#L38-L72

I expect many of these won't have any usage - e.g. the format strings (except CompositeFormat) - but we should have Regex, Uri, Json and Xml.

Additional context

No response

JamesNK avatar Oct 14 '22 01:10 JamesNK

Example of this kind of thing done previously in runtime https://github.com/dotnet/runtime/pull/67621

danmoseley avatar Oct 14 '22 04:10 danmoseley

I would love to help here.

blouflashdb avatar Oct 14 '22 09:10 blouflashdb

I have assigned to you @blouflashdb

danmoseley avatar Oct 14 '22 15:10 danmoseley

#44555 PR for CompositeFormat

more will follow soon.

blouflashdb avatar Oct 14 '22 19:10 blouflashdb

@JamesNK I have a question about StringSyntaxAttribute.Uri.

There are some places where a RelativeIUri is passed as an parameter. I saw that optinal arguments can be added to StringSyntaxAttribute for example uriKind. How should the StringSyntaxAttribute look like for relative uri?

There is also one place in the code where a relative or absolute url can be passed to the methode. For Example WebViewManager.Navigate . How to handle this case?

blouflashdb avatar Oct 15 '22 09:10 blouflashdb

Good question. Thanks for thinking about this.

I think StringSyntaxAttribute.Uri should be used for both relative and absolute URLs. For UriKind, an example of it is on the Uri ctor, and it looks like it the parameter named is passed as an argument on the attribute - https://github.com/dotnet/runtime/blob/9bcbf50d9ebe60cd83ed724179a5a503cbf03702/src/libraries/System.Private.Uri/src/System/Uri.cs#L405-L414

@stephentoub I see you added Uri throughout dotnet/runtime in https://github.com/dotnet/runtime/pull/67621. Any extra input on these StringSyntaxAttribute usages?

JamesNK avatar Oct 15 '22 12:10 JamesNK

btw @CyrusNajmabadi just curious what the status of tooling support for these is? Do you expect them to all have an experience like regex has?

danmoseley avatar Oct 15 '22 12:10 danmoseley

Does StringSyntaxAttribute also works on parameters like this? params string[] urls ?

blouflashdb avatar Oct 15 '22 13:10 blouflashdb

I tested it, and yes it does:

image

However, looks like there is a bug in Roslyn where it only applies it to the first string. New Roslyn issue: https://github.com/dotnet/roslyn/issues/64756

JamesNK avatar Oct 15 '22 13:10 JamesNK

Do you expect them to all have an experience like regex has?

We can add support if the language provides a suitable parser we can depend on.

CyrusNajmabadi avatar Oct 15 '22 15:10 CyrusNajmabadi

My preference though would be to treat it like asp route strings. Have the bcl team own the integration points, not Roslyn.

CyrusNajmabadi avatar Oct 15 '22 15:10 CyrusNajmabadi

There are no public api parameters where StringFormatAttribute Xml can be added.

blouflashdb avatar Oct 20 '22 17:10 blouflashdb

There are some for DateOnlyFormat & DateTimeFormat. Others I haven't checked yet.

blouflashdb avatar Oct 20 '22 18:10 blouflashdb

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

ghost avatar Oct 20 '22 18:10 ghost

@stephentoub I see you added Uri throughout dotnet/runtime in https://github.com/dotnet/runtime/pull/67621. Any extra input on these StringSyntaxAttribute usages?

@JamesNK, what are you looking for feedback on here?

stephentoub avatar Oct 24 '22 01:10 stephentoub

Original question was about arguments to URI strings. We figured it out.

JamesNK avatar Oct 24 '22 01:10 JamesNK

@blouflashdb is there more to do here, after your last changes? if so any interest in doing the last ones?

danmoseley avatar Jan 24 '23 02:01 danmoseley

@danmoseley I will look into the remaining things aswell.

blouflashdb avatar Jan 24 '23 14:01 blouflashdb

Thanks @blouflashdb

danmoseley avatar Jan 24 '23 16:01 danmoseley

Hi @danmoseley @JamesNK, I notice this issue hasn't had activity for a while. Do you still need someone to take on the remaining tasks (e.g. GuidFormat)? Thanks.

abc516 avatar May 22 '23 17:05 abc516

It's already assigned but it has been idle for a while. @blouflashdb Do you plan to keep looking at this?

JamesNK avatar May 23 '23 02:05 JamesNK

Sorry, I cant work on it anymore.

blouflashdb avatar May 23 '23 07:05 blouflashdb

@blouflashdb thanks for the part you did. @abc516 thanks for taking on the rest!

danmoseley avatar May 23 '23 16:05 danmoseley

I wonder if NumericFormat is already done.

cansozbir avatar Aug 26 '23 19:08 cansozbir

@danmoseley I noticed that the last PR that addressed this issue was closed. Would it be okay if I tried to work on this issue?

ShirAvneri avatar Dec 01 '23 21:12 ShirAvneri