-
Notifications
You must be signed in to change notification settings - Fork 564
[build] enable CA1305 for most projects #7993
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
Changes from all commits
a675045
15fd519
5ae588c
5cbf0f5
cd8d1aa
0dd338f
4fcbed9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [*.{cs,vb}] | ||
| dotnet_diagnostic.CA1305.severity = error # Specify IFormatProvider | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Globalization; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
| using System.Runtime.Versioning; | ||
|
|
@@ -165,7 +166,7 @@ public override IntPtr ReleaseLocalReference (ref JniObjectReference value, ref | |
|
|
||
| public override void WriteGlobalReferenceLine (string format, params object?[] args) | ||
| { | ||
| RuntimeNativeMethods._monodroid_gref_log (string.Format (format, args)); | ||
| RuntimeNativeMethods._monodroid_gref_log (string.Format (CultureInfo.InvariantCulture, format, args)); | ||
| } | ||
|
|
||
| public override JniObjectReference CreateGlobalReference (JniObjectReference value) | ||
|
|
@@ -530,7 +531,7 @@ public void RegisterNativeMembers (JniType nativeClass, Type type, ReadOnlySpan< | |
| } | ||
|
|
||
| if (minfo == null) | ||
| throw new InvalidOperationException (String.Format ("Specified managed method '{0}' was not found. Signature: {1}", mname.ToString (), signature.ToString ())); | ||
| throw new InvalidOperationException (FormattableString.Invariant ($"Specified managed method '{mname.ToString ()}' was not found. Signature: {signature.ToString ()}")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this should either use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For these two you have to call For some reason you can't string interpolate these like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example, "playing around" in CultureInfo.CurrentCulture = new CultureInfo("de-DE");
double d = 42.5;
d.ToString(); // "42,5"
FormattableString.Invariant($"{d}"); // "42.5"
FormattableString.Invariant($"{d.ToString()}"); // "42,5"
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this change, we'd get a CA1305 build error if these were wrong. https://learn.microsoft.com/en-us/dotnet/api/system.readonlyspan-1.tostring?view=net-8.0
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In such cases we should use code like this |
||
| callback = CreateDynamicCallback (minfo); | ||
| needToRegisterNatives = true; | ||
| } else { | ||
|
|
@@ -659,9 +660,8 @@ internal void AddPeer (IJavaPeerable value, JniObjectReference reference, IntPtr | |
| if (JniEnvironment.Types.IsSameObject (value.PeerReference, target!.PeerReference)) { | ||
| found = true; | ||
| if (Logger.LogGlobalRef) { | ||
| Logger.Log (LogLevel.Info, "monodroid-gref", | ||
| string.Format ("warning: not replacing previous registered handle {0} with handle {1} for key_handle 0x{2}", | ||
| target.PeerReference.ToString (), reference.ToString (), hash.ToString ("x"))); | ||
| Logger.Log (LogLevel.Info, "monodroid-gref", FormattableString.Invariant ( | ||
| $"warning: not replacing previous registered handle {target.PeerReference} with handle {reference} for key_handle 0x{hash:x}")); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -704,10 +704,9 @@ internal void AddPeer (IJavaPeerable value, IntPtr handle, JniHandleOwnership tr | |
| } | ||
|
|
||
| if (Logger.LogGlobalRef) { | ||
| RuntimeNativeMethods._monodroid_gref_log ("handle 0x" + handleField.ToString ("x") + | ||
| "; key_handle 0x" + hash.ToString ("x") + | ||
| ": Java Type: `" + JNIEnv.GetClassNameFromInstance (handleField) + "`; " + | ||
| "MCW type: `" + value.GetType ().FullName + "`\n"); | ||
| RuntimeNativeMethods._monodroid_gref_log ( | ||
| FormattableString.Invariant ( | ||
| $"handle 0x{handleField:x}; key_handle 0x{hash:x}: Java Type: `{JNIEnv.GetClassNameFromInstance (handleField)}`; MCW type: `{value.GetType ().FullName}`\n")); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why enable this just in
srcand not repo-wide?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the suggestion here: #7993 (comment)
There were a lot of tests, build-tools, Mono.Options, etc. that would also need to be addressed or use
$(NoWarn).