Browse Source
Merge pull request #9190 from workgroupengineering/features/NetAnalyzers/CA1847
feat: Enable Rule CA1847
pull/9228/head
Max Katz
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with
29 additions and
15 deletions
-
.editorconfig
-
src/Avalonia.Base/AvaloniaProperty.cs
-
src/Avalonia.Base/AvaloniaPropertyRegistry.cs
-
src/Avalonia.Base/Compatibility/StringCompatibilityExtensions.cs
-
src/Avalonia.Base/Media/UnicodeRange.cs
-
src/Avalonia.Controls/Flyouts/FlyoutBase.cs
-
src/Avalonia.Controls/NumericUpDown/NumericUpDown.cs
-
src/Avalonia.Remote.Protocol/MetsysBson.cs
-
src/Markup/Avalonia.Markup.Xaml/Converters/TimeSpanTypeConverter.cs
|
|
|
@ -143,6 +143,8 @@ dotnet_diagnostic.CA1802.severity = warning |
|
|
|
dotnet_diagnostic.CA1825.severity = warning |
|
|
|
# CA1821: Remove empty finalizers |
|
|
|
dotnet_diagnostic.CA1821.severity = warning |
|
|
|
#CA1847: Use string.Contains(char) instead of string.Contains(string) with single characters |
|
|
|
dotnet_diagnostic.CA1847.severity = warning |
|
|
|
|
|
|
|
# Wrapping preferences |
|
|
|
csharp_wrap_before_ternary_opsigns = false |
|
|
|
|
|
|
|
@ -41,7 +41,7 @@ namespace Avalonia |
|
|
|
{ |
|
|
|
_ = name ?? throw new ArgumentNullException(nameof(name)); |
|
|
|
|
|
|
|
if (name.Contains(".")) |
|
|
|
if (name.Contains('.')) |
|
|
|
{ |
|
|
|
throw new ArgumentException("'name' may not contain periods."); |
|
|
|
} |
|
|
|
|
|
|
|
@ -228,7 +228,7 @@ namespace Avalonia |
|
|
|
_ = type ?? throw new ArgumentNullException(nameof(type)); |
|
|
|
_ = name ?? throw new ArgumentNullException(nameof(name)); |
|
|
|
|
|
|
|
if (name.Contains(".")) |
|
|
|
if (name.Contains('.')) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("Attached properties not supported."); |
|
|
|
} |
|
|
|
|
|
|
|
@ -0,0 +1,12 @@ |
|
|
|
using System.Runtime.CompilerServices; |
|
|
|
|
|
|
|
namespace System; |
|
|
|
|
|
|
|
#if !NET6_0_OR_GREATER
|
|
|
|
public static class StringCompatibilityExtensions |
|
|
|
{ |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static bool Contains(this string str, char search) => |
|
|
|
str.Contains(search.ToString()); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
@ -163,7 +163,7 @@ namespace Avalonia.Media |
|
|
|
throw new FormatException("Could not parse specified Unicode range segment."); |
|
|
|
} |
|
|
|
|
|
|
|
if (!single.Value.Contains("?")) |
|
|
|
if (!single.Value.Contains('?')) |
|
|
|
{ |
|
|
|
start = int.Parse(single.Groups[1].Value, System.Globalization.NumberStyles.HexNumber); |
|
|
|
end = start; |
|
|
|
|
|
|
|
@ -597,7 +597,7 @@ namespace Avalonia.Controls.Primitives |
|
|
|
for (int i = presenter.Classes.Count - 1; i >= 0; i--) |
|
|
|
{ |
|
|
|
if (!classes.Contains(presenter.Classes[i]) && |
|
|
|
!presenter.Classes[i].Contains(":")) |
|
|
|
!presenter.Classes[i].Contains(':')) |
|
|
|
{ |
|
|
|
presenter.Classes.RemoveAt(i); |
|
|
|
} |
|
|
|
|
|
|
|
@ -1151,8 +1151,8 @@ namespace Avalonia.Controls |
|
|
|
if (PIndex >= 0) |
|
|
|
{ |
|
|
|
//stringToTest contains a "P" between 2 "'", it's considered as text, not percent
|
|
|
|
var isText = stringToTest.Substring(0, PIndex).Contains("'") |
|
|
|
&& stringToTest.Substring(PIndex, FormatString.Length - PIndex).Contains("'"); |
|
|
|
var isText = stringToTest.Substring(0, PIndex).Contains('\'') |
|
|
|
&& stringToTest.Substring(PIndex, FormatString.Length - PIndex).Contains('\''); |
|
|
|
|
|
|
|
return !isText; |
|
|
|
} |
|
|
|
|
|
|
|
@ -1364,13 +1364,13 @@ namespace Metsys.Bson |
|
|
|
var optionsString = ReadName(); |
|
|
|
|
|
|
|
var options = RegexOptions.None; |
|
|
|
if (optionsString.Contains("e")) options = options | RegexOptions.ECMAScript; |
|
|
|
if (optionsString.Contains("i")) options = options | RegexOptions.IgnoreCase; |
|
|
|
if (optionsString.Contains("l")) options = options | RegexOptions.CultureInvariant; |
|
|
|
if (optionsString.Contains("m")) options = options | RegexOptions.Multiline; |
|
|
|
if (optionsString.Contains("s")) options = options | RegexOptions.Singleline; |
|
|
|
if (optionsString.Contains("w")) options = options | RegexOptions.IgnorePatternWhitespace; |
|
|
|
if (optionsString.Contains("x")) options = options | RegexOptions.ExplicitCapture; |
|
|
|
if (optionsString.Contains('e')) options = options | RegexOptions.ECMAScript; |
|
|
|
if (optionsString.Contains('i')) options = options | RegexOptions.IgnoreCase; |
|
|
|
if (optionsString.Contains('l')) options = options | RegexOptions.CultureInvariant; |
|
|
|
if (optionsString.Contains('m')) options = options | RegexOptions.Multiline; |
|
|
|
if (optionsString.Contains('s')) options = options | RegexOptions.Singleline; |
|
|
|
if (optionsString.Contains('w')) options = options | RegexOptions.IgnorePatternWhitespace; |
|
|
|
if (optionsString.Contains('x')) options = options | RegexOptions.ExplicitCapture; |
|
|
|
|
|
|
|
return new Regex(pattern, options); |
|
|
|
} |
|
|
|
|
|
|
|
@ -15,7 +15,7 @@ namespace Avalonia.Markup.Xaml.Converters |
|
|
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) |
|
|
|
{ |
|
|
|
var valueStr = (string)value; |
|
|
|
if (!valueStr.Contains(":")) |
|
|
|
if (!valueStr.Contains(':')) |
|
|
|
{ |
|
|
|
// shorthand seconds format (ie. "0.25")
|
|
|
|
var secs = double.Parse(valueStr, CultureInfo.InvariantCulture); |
|
|
|
@ -25,4 +25,4 @@ namespace Avalonia.Markup.Xaml.Converters |
|
|
|
return base.ConvertFrom(context, culture, value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|