Skip to content

Commit

Permalink
Get rid of build warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
adams85 committed Nov 16, 2024
1 parent 20604c1 commit 035bb77
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 49 deletions.
10 changes: 6 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,18 @@ csharp_prefer_simple_using_statement = false:none
csharp_prefer_braces = when_multiline:warning
csharp_style_namespace_declarations = file_scoped:warning
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_primary_constructors = false:silent
csharp_style_prefer_top_level_statements = true:silent

# Code Style / Expression-bodied members
csharp_style_expression_bodied_methods = true:silent
csharp_style_expression_bodied_constructors = true:silent
csharp_style_expression_bodied_operators = true:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = true:silent
csharp_style_expression_bodied_local_functions = false:silent

# Code Style / Expression-level preferences
dotnet_style_coalesce_expression = true:suggestion
Expand Down Expand Up @@ -119,6 +120,7 @@ csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
dotnet_style_prefer_collection_expression = false:silent

# Code Style / Field preferences
dotnet_style_readonly_field = true:warning
Expand Down
7 changes: 6 additions & 1 deletion src/Acornima/Tokenizer.RegExpParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,12 @@ static bool IsWordChar(char ch)

internal static string EncodeGroupName(string groupName)
{
return "__utf8_" + BitConverter.ToString(Encoding.UTF8.GetBytes(groupName)).Replace("-", "");
return "__utf8_"
#if NET5_0_OR_GREATER
+ Convert.ToHexString(Encoding.UTF8.GetBytes(groupName));
#else
+ BitConverter.ToString(Encoding.UTF8.GetBytes(groupName)).Replace("-", "");
#endif
}

private readonly bool TryAdjustBackreference(ref ParsePatternContext context, int startIndex, out RegExpConversionError? conversionError)
Expand Down
88 changes: 47 additions & 41 deletions test/Acornima.Tests.Test262/Acornima.Tests.Test262.csproj
Original file line number Diff line number Diff line change
@@ -1,52 +1,58 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
<GeneratedTestSuiteDir>Generated</GeneratedTestSuiteDir>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
<GeneratedTestSuiteDir>Generated</GeneratedTestSuiteDir>
</PropertyGroup>

<PropertyGroup Label="Code Analysis">
<AnalysisLevel>latest-Recommended</AnalysisLevel>
<NoWarn>$(NoWarn);CA1305</NoWarn> <!-- Specify IFormatProvider -->
<NoWarn>$(NoWarn);CA1861</NoWarn> <!-- Avoid constant arrays as arguments -->
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Spectre.Console" />
<PackageReference Include="Test262Harness" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Acornima\Acornima.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>

<ItemGroup>
<Content Include=".config\dotnet-tools.json" />
</ItemGroup>

<!-- Based on the idea presented at https://mhut.ch/journal/2015/06/30/build-time-code-generation-in-msbuild -->
<Target Name="GenerateTestSuite" DependsOnTargets="_GenerateTestSuite" BeforeTargets="BeforeBuild" Condition="!Exists($([System.IO.Path]::Combine($(MSBuildThisFileDirectory), $(GeneratedTestSuiteDir))))">
<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Spectre.Console" />
<PackageReference Include="Test262Harness" />
<Compile Include="$(GeneratedTestSuiteDir)\**\*.cs" />
</ItemGroup>
</Target>

<ItemGroup>
<ProjectReference Include="..\..\src\Acornima\Acornima.csproj" />
</ItemGroup>
<Target Name="_GenerateTestSuite">
<Exec Command="dotnet tool restore" />
<Exec Command="dotnet test262 generate" />
</Target>

<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
<Target Name="DeleteTestSuite" DependsOnTargets="_DeleteTestSuite" AfterTargets="AfterClean" Condition="Exists($([System.IO.Path]::Combine($(MSBuildThisFileDirectory), $(GeneratedTestSuiteDir))))">
<RemoveDir Directories="$(GeneratedTestSuiteDir)" />
</Target>

<Target Name="_DeleteTestSuite">
<ItemGroup>
<Content Include=".config\dotnet-tools.json" />
<Compile Remove="$(GeneratedTestSuiteDir)\**\*.cs" />
</ItemGroup>

<!-- Based on the idea presented at https://mhut.ch/journal/2015/06/30/build-time-code-generation-in-msbuild -->
<Target Name="GenerateTestSuite" DependsOnTargets="_GenerateTestSuite" BeforeTargets="BeforeBuild" Condition="!Exists($([System.IO.Path]::Combine($(MSBuildThisFileDirectory), $(GeneratedTestSuiteDir))))">
<ItemGroup>
<Compile Include="$(GeneratedTestSuiteDir)\**\*.cs" />
</ItemGroup>
</Target>

<Target Name="_GenerateTestSuite">
<Exec Command="dotnet tool restore" />
<Exec Command="dotnet test262 generate" />
</Target>

<Target Name="DeleteTestSuite" DependsOnTargets="_DeleteTestSuite" AfterTargets="AfterClean" Condition="Exists($([System.IO.Path]::Combine($(MSBuildThisFileDirectory), $(GeneratedTestSuiteDir))))">
<RemoveDir Directories="$(GeneratedTestSuiteDir)" />
</Target>

<Target Name="_DeleteTestSuite">
<ItemGroup>
<Compile Remove="$(GeneratedTestSuiteDir)\**\*.cs" />
</ItemGroup>
</Target>
</Target>

</Project>
2 changes: 1 addition & 1 deletion test/Acornima.Tests.Test262/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static void Report(TestExecutionSummary testExecutionSummary)

foreach (var (tests, title, label) in items)
{
if (tests.Count == 0)
if (tests.IsEmpty)
{
continue;
}
Expand Down
4 changes: 4 additions & 0 deletions test/Acornima.Tests/Helpers/JavaScriptString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ public class JavaScriptString
{
private static readonly ParserOptions s_parserOptions = new() { RegExpParseMode = RegExpParseMode.Skip, Tolerant = false };

#pragma warning disable CA1865 // Use char overload
public static bool IsStringLiteral(string value) => value.Length > 2
&& (value.StartsWith("\"", StringComparison.Ordinal) && value.EndsWith("\"", StringComparison.Ordinal)
|| value.StartsWith("'", StringComparison.Ordinal) && value.EndsWith("'", StringComparison.Ordinal));
#pragma warning restore CA1865 // Use char overload

public static Expression ParseAsExpression(string value) => new Parser(s_parserOptions).ParseExpression(value);

Expand Down Expand Up @@ -116,6 +118,7 @@ static bool CharRequiresJavaScriptEncoding(char c) =>

static void AppendCharAsUnicodeJavaScript(StringBuilder builder, char c)
{
#pragma warning disable CA1305 // Specify IFormatProvider
if (c <= byte.MaxValue)
{
builder.Append(@$"\x{(int)c:x2}");
Expand All @@ -124,6 +127,7 @@ static void AppendCharAsUnicodeJavaScript(StringBuilder builder, char c)
{
builder.Append(@$"\u{(int)c:x4}");
}
#pragma warning restore CA1305 // Specify IFormatProvider
}
}
}
4 changes: 2 additions & 2 deletions test/Acornima.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void ShouldPreserveUserOnNodeHandler(bool registerUserHandler)
var parser = new Parser(options);
var script = parser.ParseScript(code);

Assert.Empty(script.DescendantNodesAndSelf().Where(node => node.UserData is not null));
Assert.DoesNotContain(script.DescendantNodesAndSelf(), node => node.UserData is not null);
Assert.Equal(registerUserHandler, userHandlerCalled);
}

Expand Down Expand Up @@ -1924,7 +1924,7 @@ class aa {

var program = new Parser().ParseScript(code);

var objectExpression = Assert.Single(program.DescendantNodes().OfType<PropertyDefinition>().Where(pd => pd.Key is PrivateIdentifier));
var objectExpression = Assert.Single(program.DescendantNodes().OfType<PropertyDefinition>(), pd => pd.Key is PrivateIdentifier);
Assert.Equal("bb", objectExpression.Key.As<PrivateIdentifier>().Name);

var binaryExpression = Assert.Single(program.DescendantNodes().OfType<BinaryExpression>());
Expand Down

0 comments on commit 035bb77

Please sign in to comment.