Skip to content

Commit de7d4b0

Browse files
authored
Fix analyzer issue with properties with dot or space in name (#79)
1 parent 0fed007 commit de7d4b0

6 files changed

+59
-1
lines changed

src/ReSharper.Structured.Logging/Serilog/Parsing/MessageTemplateParser.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static bool IsValidInPropertyTag(char c)
217217
c == ':';
218218
}
219219

220-
static bool IsValidInPropertyName(char c) => char.IsLetterOrDigit(c) || c == '_';
220+
static bool IsValidInPropertyName(char c) => char.IsLetterOrDigit(c) || c == '_' || c == '.' || c == ' ';
221221

222222
static bool TryGetDestructuringHint(char c, out Destructuring destructuring)
223223
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Serilog;
2+
3+
namespace ConsoleApp
4+
{
5+
public static class Program
6+
{
7+
public static void Main()
8+
{
9+
Log.Logger.Information("{My.Property}", 1);
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Serilog;
2+
3+
namespace ConsoleApp
4+
{
5+
public static class Program
6+
{
7+
public static void Main()
8+
{
9+
Log.Logger.Information("|{My.Property}|(0)", 1);
10+
}
11+
}
12+
}
13+
14+
---------------------------------------------------------
15+
(0): ReSharper Warning: Property name 'My.Property' does not match naming rules. Suggested name is 'MyProperty'.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Serilog;
2+
3+
namespace ConsoleApp
4+
{
5+
public static class Program
6+
{
7+
public static void Main()
8+
{
9+
Log.Logger.Information("{My Property}", 1);
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Serilog;
2+
3+
namespace ConsoleApp
4+
{
5+
public static class Program
6+
{
7+
public static void Main()
8+
{
9+
Log.Logger.Information("|{My Property}|(0)", 1);
10+
}
11+
}
12+
}
13+
14+
---------------------------------------------------------
15+
(0): ReSharper Warning: Property name 'My Property' does not match naming rules. Suggested name is 'MyProperty'.

test/src/Analyzer/PropertiesNamingAnalyzerTests.cs

+4
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ public class PropertiesNamingAnalyzerTests : MessageTemplateAnalyzerTestBase
1313
[Test] public void TestSerilogValidDestructuredNamedProperty() => DoNamedTest2();
1414

1515
[Test] public void TestSerilogContextInvalidNamedProperty() => DoNamedTest2();
16+
17+
[Test] public void TestSerilogInvalidNamedPropertyWithDot() => DoNamedTest2();
18+
19+
[Test] public void TestSerilogInvalidNamedPropertyWithSpace() => DoNamedTest2();
1620
}
1721
}

0 commit comments

Comments
 (0)