Skip to content

Commit

Permalink
Upgrade packages and enable code analysis (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahma authored May 19, 2024
1 parent e3c7c64 commit 22837e0
Show file tree
Hide file tree
Showing 18 changed files with 103 additions and 61 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "nuget" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>

<AnalysisLevel>latest-Recommended</AnalysisLevel>

<VersionPrefix>1.0.0</VersionPrefix>

<CLSCompliant>true</CLSCompliant>
Expand Down
22 changes: 11 additions & 11 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="Fluid.Core" Version="2.5.0" />
<PackageVersion Include="Fluid.Core" Version="2.10.0" />
<PackageVersion Include="Glob" Version="1.1.9" />
<PackageVersion Include="JavaScriptEngineSwitcher.Jint" Version="3.23.9" />
<PackageVersion Include="JavaScriptEngineSwitcher.Jurassic" Version="3.23.3" />
<PackageVersion Include="JavaScriptEngineSwitcher.NiL" Version="3.23.5" />
<PackageVersion Include="JavaScriptEngineSwitcher.Jint" Version="3.25.0" />
<PackageVersion Include="JavaScriptEngineSwitcher.Jurassic" Version="3.24.1" />
<PackageVersion Include="JavaScriptEngineSwitcher.NiL" Version="3.24.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="Nuke.Components" Version="8.0.0" />
<PackageVersion Include="NUnit" Version="4.0.1" />
<PackageVersion Include="NUnit.Analyzers" Version="4.0.1" />
<PackageVersion Include="NUnit" Version="4.1.0" />
<PackageVersion Include="NUnit.Analyzers" Version="4.2.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="SharpZipLib" Version="1.4.2" />
<PackageVersion Include="Spectre.Console.Cli" Version="0.48.0" />
<PackageVersion Include="Spectre.Console.Cli" Version="0.49.1" />
<PackageVersion Include="System.Memory" Version="4.5.5" />
<PackageVersion Include="YamlDotNet" Version="15.1.1" />
<PackageVersion Include="YamlDotNet" Version="15.1.4" />
<PackageVersion Include="Zio" Version="0.17.0" />
<PackageVersion Include="ZString" Version="2.5.1" />
<PackageVersion Include="ZString" Version="2.6.0" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="GitHubActionsTestLogger" Version="2.3.3" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>
</Project>
</Project>
2 changes: 2 additions & 0 deletions Test262Harness.sln
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ Global
{2DA14BAF-34DA-409B-942E-5CEB4EF6B9E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2DA14BAF-34DA-409B-942E-5CEB4EF6B9E0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
EndGlobalSection
EndGlobal
5 changes: 4 additions & 1 deletion build/_build.csproj.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ANONYMOUSMETHOD_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=4a98fdf6_002D7d98_002D4f5a_002Dafeb_002Dea44ad98c70c/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Instance" AccessRightKinds="Private" Description="Instance fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;Kind Name="READONLY_FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/UserRules/=f9fce829_002De6f4_002D4cb2_002D80f1_002D5497c44f51df/@EntryIndexedValue">&lt;Policy&gt;&lt;Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static fields (private)"&gt;&lt;ElementKinds&gt;&lt;Kind Name="FIELD" /&gt;&lt;/ElementKinds&gt;&lt;/Descriptor&gt;&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
Expand All @@ -24,4 +26,5 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EPredefinedNamingRulesToUserRulesUpgrade/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
27 changes: 14 additions & 13 deletions src/Test262Harness.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text.Json;
using Spectre.Console;
using Spectre.Console.Cli;
Expand All @@ -16,6 +17,11 @@
[Description("Generates test suite")]
internal sealed class GenerateCommand : AsyncCommand<GenerateCommand.Settings>
{
private static readonly JsonSerializerOptions _serializerOptions = new()
{
ReadCommentHandling = JsonCommentHandling.Skip
};

public sealed class Settings : CommandSettings
{
[Description("GitHub SHA for test262 repository commit")]
Expand Down Expand Up @@ -53,20 +59,15 @@ public override async Task<int> ExecuteAsync([NotNull] CommandContext context, [

if (File.Exists(settingsFilePath))
{
var serializerOptions = new JsonSerializerOptions
{
ReadCommentHandling = JsonCommentHandling.Skip
};

await using var stream = File.OpenRead(settingsFilePath);
options = await JsonSerializer.DeserializeAsync<TestSuiteGeneratorOptions>(stream, serializerOptions);
options = await JsonSerializer.DeserializeAsync<TestSuiteGeneratorOptions>(stream, _serializerOptions);
usedSettingsFilePath = settingsFilePath;

AnsiConsole.MarkupLine("Read settings from [yellow]{0}[/]", settingsFilePath);
AnsiConsole.MarkupLine(CultureInfo.InvariantCulture, "Read settings from [yellow]{0}[/]", settingsFilePath);
}
else
{
AnsiConsole.MarkupLine("Settings file [yellow]{0}[/] not found, using command line options", settingsFilePath);
AnsiConsole.MarkupLine(CultureInfo.InvariantCulture, "Settings file [yellow]{0}[/] not found, using command line options", settingsFilePath);
}

options ??= new TestSuiteGeneratorOptions();
Expand All @@ -78,13 +79,13 @@ public override async Task<int> ExecuteAsync([NotNull] CommandContext context, [
options.LogInfo = (s, objects) =>
{
s = s.Replace("{0}", "[yellow]{0}[/]").Replace("{1}", "[yellow]{1}[/]");
AnsiConsole.MarkupLine(s, objects);
AnsiConsole.MarkupLine(CultureInfo.InvariantCulture, s, objects);
};
options.LogError = (s, objects) =>
{
s = "[red]" + s + "[/]";
s = $"[red]{s}[/]";
s = s.Replace("{0}", "[yellow]{0}[/]").Replace("{1}", "[yellow]{1}[/]");
AnsiConsole.MarkupLine(s, objects);
AnsiConsole.MarkupLine(CultureInfo.InvariantCulture, s, objects);
};
};

Expand Down Expand Up @@ -154,9 +155,9 @@ private static async Task FinalizeOptions(Settings settings, TestSuiteGeneratorO
var lines = await File.ReadAllLinesAsync(options.ExcludedFilesSource);

var valid = lines
.Where(x => !string.IsNullOrWhiteSpace(x) && !x.StartsWith("#"))
.Where(x => !string.IsNullOrWhiteSpace(x) && !x.StartsWith('#'))
// support esprima format
.Select(x => x.StartsWith("test/") ? x.Substring("test/".Length) : x);
.Select(x => x.StartsWith("test/", StringComparison.OrdinalIgnoreCase) ? x.Substring("test/".Length) : x);

options.ExcludedFiles = options.ExcludedFiles.Concat(valid).ToArray();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Test262Harness.Generator/ConversionUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static string Capitalize(string input)

private static string ConvertDashesToCamelCase(string input)
{
if (input.IndexOf('-') == -1)
if (!input.Contains('-'))
{
// no conversion necessary
return input;
Expand Down
4 changes: 2 additions & 2 deletions src/Test262Harness.Generator/GeneratorModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public TestCaseGroup(string name, List<TestCase> testCases)
{
// ignore the whole method
var reasons = testCases.Select(x => x.IgnoreReason).Distinct().ToList();
if (reasons.Count > 1 && reasons.All(r => r != null && r.StartsWith("File ")))
if (reasons.Count > 1 && reasons.TrueForAll(r => r != null && r.StartsWith("File ", StringComparison.OrdinalIgnoreCase)))
{
IgnoreReason = "All files ignored";
}
Expand All @@ -43,7 +43,7 @@ public class TestCase
{
public TestCase(Test262File file, string? ignoreReason)
{
FileName = file.FileName.StartsWith("test/") ? file.FileName[5..] : file.FileName;
FileName = file.FileName.StartsWith("test/", StringComparison.OrdinalIgnoreCase) ? file.FileName[5..] : file.FileName;
Category = file.Features.Length > 0 || file.Flags.Length > 0
? string.Join(",", file.Features.ToArray().Concat(file.Flags.ToArray()))
: null;
Expand Down
10 changes: 5 additions & 5 deletions src/Test262Harness.Generator/TestSuiteGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public TestSuiteGenerator(TestSuiteGeneratorOptions options, string? usedSetting
// translate esprima format
.SelectMany(x =>
{
if (x.EndsWith("(default)"))
if (x.EndsWith("(default)", StringComparison.Ordinal))
{
return new (string Name, bool Strict)[] { (x.Substring(0, x.Length - "(default)".Length), false) };
}

if (x.EndsWith("(strict mode)"))
if (x.EndsWith("(strict mode)", StringComparison.Ordinal))
{
return new (string Name, bool Strict)[] { (x.Substring(0, x.Length - "(strict mode)".Length), true) };
}
Expand Down Expand Up @@ -103,7 +103,7 @@ public TestSuiteGenerator(TestSuiteGeneratorOptions options, string? usedSetting

var model = new GeneratorModel
{
TestClassName = ConversionUtilities.ConvertToUpperCamelCase(item) + "Tests",
TestClassName = $"{ConversionUtilities.ConvertToUpperCamelCase(item)}Tests",
Namespace = _options.Namespace,
TestCaseGroupings = tests
.GroupBy(x =>
Expand Down Expand Up @@ -179,7 +179,7 @@ private void SetCommonInfo(TemplateContext context, string templateHash)
private string? GetExcludeReason(Test262File file)
{
const string TestPrefix = "test/";
var fileName = file.FileName.StartsWith(TestPrefix) ? file.FileName.Substring(TestPrefix.Length) : file.FileName;
var fileName = file.FileName.StartsWith(TestPrefix, StringComparison.OrdinalIgnoreCase) ? file.FileName.Substring(TestPrefix.Length) : file.FileName;
fileName = fileName.ToLowerInvariant();

_excludedFiles.TryGetValue((fileName, file.Strict), out var excludeReason);
Expand Down Expand Up @@ -227,7 +227,7 @@ private void SetCommonInfo(TemplateContext context, string templateHash)
var manifestResourceStream = type.Assembly.GetManifestResourceStream(resourceName);
if (manifestResourceStream is null)
{
throw new Exception("Could not find template " + resourceName);
throw new ArgumentException($"Could not find template {resourceName}");
}

string template;
Expand Down
21 changes: 11 additions & 10 deletions src/Test262Harness.Runner/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Concurrent;
using System.Globalization;
using System.Reflection;
using JavaScriptEngineSwitcher.Core;
using JavaScriptEngineSwitcher.Jint;
Expand All @@ -15,7 +16,7 @@ public static int Main(string[] args)
var rootTestDirectory = Path.Combine(projectRoot, "node_modules", "test262");
if (!Directory.Exists(rootTestDirectory))
{
AnsiConsole.Markup("[red]Could not find test262 test suite from {0}, did you forget to run npm ci?[/]", rootTestDirectory);
AnsiConsole.Markup(CultureInfo.InvariantCulture, "[red]Could not find test262 test suite from {0}, did you forget to run npm ci?[/]", rootTestDirectory);
return -1;
}

Expand All @@ -24,13 +25,13 @@ public static int Main(string[] args)
options.LogInfo = (s, objects) =>
{
s = s.Replace("{0}", "[yellow]{0}[/]").Replace("{1}", "[yellow]{1}[/]");
AnsiConsole.MarkupLine(s, objects);
AnsiConsole.MarkupLine(CultureInfo.InvariantCulture, s, objects);
};
options.LogError = (s, objects) =>
{
s = "[red]" + s + "[/]";
s = $"[red]{s}[/]";
s = s.Replace("{0}", "[yellow]{0}[/]").Replace("{1}", "[yellow]{1}[/]");
AnsiConsole.MarkupLine(s, objects);
AnsiConsole.MarkupLine(CultureInfo.InvariantCulture, s, objects);
};
});

Expand Down Expand Up @@ -67,7 +68,7 @@ public static int Main(string[] args)
readTask.StopTask();

AnsiConsole.WriteLine();
AnsiConsole.MarkupLine("Found [green]{0}[/] test cases to test against", test262Files.Count);
AnsiConsole.MarkupLine(CultureInfo.InvariantCulture, "Found [green]{0}[/] test cases to test against", test262Files.Count);

foreach (var pair in targets)
{
Expand Down Expand Up @@ -140,10 +141,10 @@ private static void Report(TestExecutionSummary testExecutionSummary)
AnsiConsole.WriteLine();
AnsiConsole.WriteLine("Summary:");

AnsiConsole.MarkupLine(" [green]:check_mark: {0}[/] valid programs parsed without error", testExecutionSummary.Allowed.Success.Count);
AnsiConsole.MarkupLine(" [green]::check_mark: {0}[/] invalid programs produced a parsing error", testExecutionSummary.Allowed.Failure.Count);
AnsiConsole.MarkupLine(" [green]::check_mark: {0}[/] invalid programs did not produce a parsing error (and in allow file)", testExecutionSummary.Allowed.FalsePositive.Count);
AnsiConsole.MarkupLine(" [green]::check_mark: {0}[/] valid programs produced a parsing error (and in allow file)", testExecutionSummary.Allowed.FalseNegative.Count);
AnsiConsole.MarkupLine(CultureInfo.InvariantCulture, " [green]:check_mark: {0}[/] valid programs parsed without error", testExecutionSummary.Allowed.Success.Count);
AnsiConsole.MarkupLine(CultureInfo.InvariantCulture, " [green]::check_mark: {0}[/] invalid programs produced a parsing error", testExecutionSummary.Allowed.Failure.Count);
AnsiConsole.MarkupLine(CultureInfo.InvariantCulture, " [green]::check_mark: {0}[/] invalid programs did not produce a parsing error (and in allow file)", testExecutionSummary.Allowed.FalsePositive.Count);
AnsiConsole.MarkupLine(CultureInfo.InvariantCulture, " [green]::check_mark: {0}[/] valid programs produced a parsing error (and in allow file)", testExecutionSummary.Allowed.FalseNegative.Count);

var items = new (ConcurrentBag<Test262File> Tests, string Label)[]
{
Expand All @@ -158,7 +159,7 @@ private static void Report(TestExecutionSummary testExecutionSummary)

foreach (var (tests, label) in items)
{
if (tests.Count == 0)
if (tests.IsEmpty)
{
continue;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Test262Harness/MemoryReader.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CA1513

namespace System.IO;

internal sealed class MemoryReader : TextReader
Expand Down
18 changes: 18 additions & 0 deletions src/Test262Harness/Polyfills.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Test262Harness;

internal static class Polyfills
{
#if !NET6_0_OR_GREATER
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
internal static bool Contains(this string source, char c) => source.IndexOf(c) != -1;

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
internal static bool Contains(this string source, string value, StringComparison comparisonType) => source.IndexOf(value, comparisonType) != -1;

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
internal static bool StartsWith(this string source, char c) => source.Length > 0 && source[0] == c;

[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
internal static bool EndsWith(this string source, char c) => source.Length > 0 && source[source.Length - 1] == c;
#endif
}
4 changes: 2 additions & 2 deletions src/Test262Harness/Test262File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class Test262File : IEquatable<Test262File>

private static readonly YamlScalarNode _phaseNode = new("phase");
private static readonly YamlScalarNode _typeNode = new("type");
private static readonly string _useStrictWithNewLine = "\"use strict\";" + Environment.NewLine;
private static readonly string _useStrictWithNewLine = $"\"use strict\";{Environment.NewLine}";

private string[] _features = Array.Empty<string>();
private string[] _flags = Array.Empty<string>();
Expand Down Expand Up @@ -163,7 +163,7 @@ public static IEnumerable<Test262File> FromStream(Stream stream, string fileName
}
catch (Exception ex)
{
throw new ArgumentException($"Could not lod YAML content from file {fileName}: " + ex.Message, ex);
throw new ArgumentException($"Could not lod YAML content from file {fileName}: {ex.Message}", ex);
}

var onlyStrict = false;
Expand Down
Loading

0 comments on commit 22837e0

Please sign in to comment.