Skip to content

Commit

Permalink
Fix analyzer issue with properties with dot or space in name (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
olsh authored Nov 6, 2022
1 parent 0fed007 commit de7d4b0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static bool IsValidInPropertyTag(char c)
c == ':';
}

static bool IsValidInPropertyName(char c) => char.IsLetterOrDigit(c) || c == '_';
static bool IsValidInPropertyName(char c) => char.IsLetterOrDigit(c) || c == '_' || c == '.' || c == ' ';

static bool TryGetDestructuringHint(char c, out Destructuring destructuring)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Serilog;

namespace ConsoleApp
{
public static class Program
{
public static void Main()
{
Log.Logger.Information("{My.Property}", 1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Serilog;

namespace ConsoleApp
{
public static class Program
{
public static void Main()
{
Log.Logger.Information("|{My.Property}|(0)", 1);
}
}
}

---------------------------------------------------------
(0): ReSharper Warning: Property name 'My.Property' does not match naming rules. Suggested name is 'MyProperty'.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Serilog;

namespace ConsoleApp
{
public static class Program
{
public static void Main()
{
Log.Logger.Information("{My Property}", 1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Serilog;

namespace ConsoleApp
{
public static class Program
{
public static void Main()
{
Log.Logger.Information("|{My Property}|(0)", 1);
}
}
}

---------------------------------------------------------
(0): ReSharper Warning: Property name 'My Property' does not match naming rules. Suggested name is 'MyProperty'.
4 changes: 4 additions & 0 deletions test/src/Analyzer/PropertiesNamingAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ public class PropertiesNamingAnalyzerTests : MessageTemplateAnalyzerTestBase
[Test] public void TestSerilogValidDestructuredNamedProperty() => DoNamedTest2();

[Test] public void TestSerilogContextInvalidNamedProperty() => DoNamedTest2();

[Test] public void TestSerilogInvalidNamedPropertyWithDot() => DoNamedTest2();

[Test] public void TestSerilogInvalidNamedPropertyWithSpace() => DoNamedTest2();
}
}

0 comments on commit de7d4b0

Please sign in to comment.