Skip to content

Stop duplicating trailing period in IL2026 #2053

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

Merged
merged 4 commits into from
Jun 3, 2021

Conversation

mateoatr
Copy link
Contributor

Fixes #2052.

@@ -113,7 +113,10 @@ protected override bool ReportSpecialIncompatibleMembersDiagnostic (OperationAna
protected override string GetMessageFromAttribute (AttributeData? requiresAttribute)
{
var message = requiresAttribute?.NamedArguments.FirstOrDefault (na => na.Key == "Message").Value.Value?.ToString ();
return string.IsNullOrEmpty (message) ? "" : $" {message}.";
if (!string.IsNullOrEmpty (message))
message = $" {message}{(message!.TrimEnd ().EndsWith (".") ? "" : ".")}";
Copy link
Member

Choose a reason for hiding this comment

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

Should we just stop printing a period all-together? Examining the message string used by the code feels like an anti-pattern

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 don't have a personal opinion on this one. I agree that examining the message string feels a bit wrong, so we can stop adding the period.

Copy link
Member

Choose a reason for hiding this comment

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

That would be my preferred solution. @eerhardt Any objections?

Copy link
Member

Choose a reason for hiding this comment

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

Note that there are a lot of existing warning messages without a trailing period:

https://source.dot.net/#System.Private.CoreLib/RequiresUnreferencedCodeAttribute.cs,6e9970f8b7a80375,references

image

image

If we decide to not append a period, we should have a plan for those.

Copy link
Member

@agocke agocke May 24, 2021

Choose a reason for hiding this comment

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

My plan: so what? 😄 The lack of a period at the end doesn't really look bad to me.

Copy link
Member

Choose a reason for hiding this comment

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

Basically, I think it's important that messages from our tools don't look sloppy because it might affect how people perceive the tool (sloppy messages -> sloppy tool -> sloppy .NET).

It would be nice if we can solve this for all messages - not just our own. But if we go with fixing just our own, I think it would be really nice if there at least was a Roslyn analyzer for that, if it's not too hard to make one.

Copy link
Member

Choose a reason for hiding this comment

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

It sounds like we're converging towards the solution in this PR: always add a period, and remove any duplicates. Any objections?

Copy link
Member

Choose a reason for hiding this comment

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

No objections from me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

always add a period, and remove any duplicates

So basically the changes implemented in this PR?

The other option is to stop looking into the user-given string (needed to remove duplicates) and handle the responsibility of adding (or not -- depending on the language of the user) a period to the message.

It would be nice if we can solve this for all messages - not just our own. But if we go with fixing just our own, I think it would be really nice if there at least was a Roslyn analyzer for that, if it's not too hard to make one.

I agree we should have an analyzer do some basic string formatting validation for things that will end up being read by the user.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, what's in this PR looks good. @mateoatr thanks for hosting this discussion 😄

@mateoatr mateoatr merged commit 0f3ea71 into dotnet:main Jun 3, 2021
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
* Don't duplicate trailing periods on IL2026 warning message

* Do the same for RAF

* Run lint.cmd

Commit migrated from dotnet/linker@0f3ea71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RequiresUnreferencedCode messages have two periods
6 participants