Skip to content

Commit

Permalink
Fix naming analyzer cast issue (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
olsh authored Mar 2, 2023
1 parent d792c4e commit cf868bb
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SdkVersion>2022.3.1</SdkVersion>
<SdkVersion>2022.3.2</SdkVersion>
</PropertyGroup>
<!-- https://jetbrains.slack.com/archives/CBZ36NH7C/p1628090127002200 -->
<PropertyGroup>
Expand Down
20 changes: 20 additions & 0 deletions src/.run/Pack ReSharper.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Pack ReSharper" type="NukeBuildTarget" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/../build/bin/Debug/_build.exe" />
<option name="PROGRAM_PARAMETERS" value="Pack" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/../" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/../build/_build.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="net6.0" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
20 changes: 20 additions & 0 deletions src/.run/Pack Rider.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Pack Rider" type="NukeBuildTarget" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/../build/bin/Debug/_build.exe" />
<option name="PROGRAM_PARAMETERS" value="PackRiderPlugin --is-rider-host" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/../" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/../build/_build.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="net6.0" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
20 changes: 20 additions & 0 deletions src/.run/Test ReSharper.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Test ReSharper" type="NukeBuildTarget" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/../build/bin/Debug/_build.exe" />
<option name="PROGRAM_PARAMETERS" value="Test" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/../" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/../build/_build.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="net6.0" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
20 changes: 20 additions & 0 deletions src/.run/Test Rider.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Test Rider" type="NukeBuildTarget" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/../build/bin/Debug/_build.exe" />
<option name="PROGRAM_PARAMETERS" value="Test --is-rider-host" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/../" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/../build/_build.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="net6.0" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ private void CheckPropertiesInContext(
}

var propertyArgument = element.ArgumentList.Arguments[0];
var propertyName = propertyArgument.Value?.ConstantValue.StringValue;

var propertyName = string.Empty;
propertyArgument.Value?.ConstantValue.IsString(out propertyName);
if (string.IsNullOrEmpty(propertyName))
{
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Serilog;
using Serilog.Context;

namespace ConsoleApp
{
public static class Program
{
public static void Main()
{
var s = "world";
LogContext.PushProperty($"Hello{s}", 1);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Serilog;
using Serilog.Context;

namespace ConsoleApp
{
public static class Program
{
public static void Main()
{
var s = "world";
LogContext.PushProperty($"Hello{s}", 1);
}
}
}

---------------------------------------------------------
2 changes: 2 additions & 0 deletions test/src/Analyzer/PropertiesNamingAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class PropertiesNamingAnalyzerTests : MessageTemplateAnalyzerTestBase

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

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

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

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

0 comments on commit cf868bb

Please sign in to comment.