Skip to content

Commit

Permalink
Merge template/faithlife-build.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejball committed Jan 22, 2024
2 parents 448d3c1 + e36eb2d commit fcb02e4
Show file tree
Hide file tree
Showing 22 changed files with 90 additions and 49 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ resharper_comment_typo_highlighting = none
resharper_identifier_typo_highlighting = none
resharper_string_literal_typo_highlighting = none

[Directory.Packages.props]
insert_final_newline = false

[dotnet-tools.json]
insert_final_newline = false

Expand Down Expand Up @@ -87,6 +90,7 @@ csharp_style_prefer_local_over_anonymous_function = true : suggestion
csharp_style_prefer_not_pattern = true : suggestion
csharp_style_prefer_null_check_over_type_check = true : suggestion
csharp_style_prefer_pattern_matching = true : suggestion
csharp_style_prefer_primary_constructors = true : suggestion
csharp_style_prefer_range_operator = true : suggestion
csharp_style_prefer_switch_expression = true : suggestion
csharp_style_prefer_tuple_swap = true : warning
Expand Down Expand Up @@ -203,7 +207,9 @@ dotnet_diagnostic.IDE0160.severity = suggestion
dotnet_diagnostic.IDE0161.severity = suggestion
dotnet_diagnostic.IDE0170.severity = suggestion
dotnet_diagnostic.IDE0180.severity = warning
dotnet_diagnostic.IDE0290.severity = suggestion
dotnet_diagnostic.IDE1005.severity = suggestion
dotnet_diagnostic.NUnit2045.severity = suggestion
dotnet_diagnostic.SA0001.severity = none
dotnet_diagnostic.SA1003.severity = none
dotnet_diagnostic.SA1008.severity = none
Expand Down Expand Up @@ -326,6 +332,7 @@ resharper_arrange_missing_parentheses_highlighting = hint
resharper_arrange_trailing_comma_in_multiline_lists_highlighting = warning
resharper_comment_typo_highlighting = none
resharper_compare_of_floats_by_equality_operator_highlighting = suggestion
resharper_convert_to_primary_constructor_highlighting = hint
resharper_csharp_align_first_arg_by_paren = false
resharper_csharp_align_linq_query = false
resharper_csharp_align_multiline_argument = false
Expand Down
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
.vs/
.idea/
artifacts/
bin/
obj/
release/
.vs/
.idea/
Thumbs.db

*.cache
*.user
*.userprefs
*.log
*.ncrunchproject
*.ncrunchsolution
*.user
launchSettings.json
nCrunchTemp*
_ReSharper*
.DS_Store
launchSettings.json
18 changes: 9 additions & 9 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

<PropertyGroup>
<VersionPrefix>2.11.0</VersionPrefix>
<LangVersion>11.0</LangVersion>
<PackageValidationBaselineVersion>2.10.1</PackageValidationBaselineVersion>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);1591;1998;CA1510;CA1865;NU1507;NU5105</NoWarn>
<NeutralLanguage>en-US</NeutralLanguage>
<NoWarn>$(NoWarn);1591;1998;NU5105</NoWarn>
<DebugType>embedded</DebugType>
<GitHubOrganization>FacilityApi</GitHubOrganization>
<RepositoryName>Facility</RepositoryName>
Expand All @@ -20,22 +21,21 @@
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<AnalysisLevel>latest-all</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>false</IsPackable>
<IsTestProject>false</IsTestProject>
<SelfContained>false</SelfContained>
<UseArtifactsOutput>true</UseArtifactsOutput>
<EnableStrictModeForCompatibleFrameworksInPackageValidation>true</EnableStrictModeForCompatibleFrameworksInPackageValidation>
<EnableStrictModeForCompatibleTfms>true</EnableStrictModeForCompatibleTfms>
<DisablePackageBaselineValidation Condition=" $(PackageValidationBaselineVersion) == $(VersionPrefix) or $(PackageValidationBaselineVersion) == '0.0.0' ">true</DisablePackageBaselineValidation>
</PropertyGroup>

<PropertyGroup Condition=" '$(BuildNumber)' != '' ">
<AssemblyVersion>$(VersionPrefix).$(BuildNumber)</AssemblyVersion>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Faithlife.Analyzers" Version="1.4.0" PrivateAssets="All" IncludeAssets="runtime; build; native; contentfiles; analyzers" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507" PrivateAssets="All" IncludeAssets="runtime; build; native; contentfiles; analyzers" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="ArgsReading" Version="2.3.2" />
<PackageVersion Include="Faithlife.Parsing" Version="3.5.1" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="NUnit" Version="4.0.1" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="XmlDocMarkdown.Core" Version="2.9.0" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Faithlife.Analyzers" Version="1.4.0" />
<GlobalPackageReference Include="NUnit.Analyzers" Version="3.10.0" />
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion Facility.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
build.ps1 = build.ps1
.github\workflows\build.yaml = .github\workflows\build.yaml
Directory.Build.props = Directory.Build.props
dotnet-tools.json = dotnet-tools.json
Directory.Packages.props = Directory.Packages.props
global.json = global.json
example\ExampleApi.fsd = example\ExampleApi.fsd
example\ExampleApi.fsd.md = example\ExampleApi.fsd.md
fsd\FacilityCore.fsd = fsd\FacilityCore.fsd
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright 2022 Ed Ball
Copyright 2024 Ed Ball

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestFeature"
}
}
3 changes: 2 additions & 1 deletion nuget.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<configuration>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ArgsReading" Version="2.3.2" />
<PackageReference Include="ArgsReading" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/Facility.Definition/CodeGen/FileGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private static IEnumerable<string> FindNamesMatchingPatterns(DirectoryInfo direc

private static IEnumerable<string> FindNamesMatchingPattern(DirectoryInfo directoryInfo, CodeGenPattern patternToClean)
{
var parts = patternToClean.NamePattern.Split(new[] { '/' }, 2);
var parts = patternToClean.NamePattern.Split(s_oneSlash, 2);
if (parts[0].Length == 0)
throw new InvalidOperationException("Invalid name pattern.");

Expand All @@ -190,4 +190,6 @@ private static IEnumerable<string> FindNamesMatchingPattern(DirectoryInfo direct
}
}
}

private static readonly char[] s_oneSlash = ['/'];
}
2 changes: 1 addition & 1 deletion src/Facility.Definition/Facility.Definition.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Faithlife.Parsing" Version="3.5.1" />
<PackageReference Include="Faithlife.Parsing" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions src/Facility.Definition/Fsd/FsdParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override bool TryParseDefinitionCore(ServiceDefinitionText text, out S

targetMember.Remarks = targetMember.Remarks.Count == 0
? remarksSection.Lines
: targetMember.Remarks.Concat(new[] { "" }).Concat(remarksSection.Lines).ToList();
: targetMember.Remarks.Concat(s_oneEmptyString).Concat(remarksSection.Lines).ToList();
}
}
}
Expand Down Expand Up @@ -144,7 +144,7 @@ void AddRemarksSection()
{
var position = new ServiceDefinitionPosition(source.Name, remarksLineNumber, 1);
remarksSections.Add(new FsdRemarksSection(remarksLines, position));
remarksLines = new List<string>();
remarksLines = [];
}
}
}
Expand Down Expand Up @@ -188,7 +188,7 @@ private static void ReadRemarksAfterDefinition(ServiceDefinitionText source, Lis
break;

name = line!.Substring(match.Index + match.Length).Trim();
lines = new List<string>();
lines = [];
headingLineNumber = lineNumber;
}
else
Expand All @@ -200,4 +200,5 @@ private static void ReadRemarksAfterDefinition(ServiceDefinitionText source, Lis

private static readonly Regex s_interleavedMarkdown = new(@"^```fsd\b", RegexOptions.Multiline);
private static readonly Regex s_markdownHeading = new(@"^#\s+");
private static readonly string[] s_oneEmptyString = [""];
}
2 changes: 1 addition & 1 deletion src/Facility.Definition/Http/HttpElementInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public IEnumerable<ServiceDefinitionError> GetValidationErrors(bool recurse = tr

private protected HttpElementInfo()
{
m_validationErrors = new List<ServiceDefinitionError>();
m_validationErrors = [];
}

private protected void AddValidationError(ServiceDefinitionError error) => m_validationErrors.Add(error);
Expand Down
9 changes: 5 additions & 4 deletions src/Facility.Definition/Http/HttpMethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private IEnumerable<HttpResponseInfo> GetValidResponses(ServiceInfo serviceInfo,

private static bool IsNoContentStatusCode(HttpStatusCode? statusCode) => statusCode is HttpStatusCode.NoContent or HttpStatusCode.NotModified;

private static IReadOnlyList<string> GetPathParameterNames(string routePath) =>
private static List<string> GetPathParameterNames(string routePath) =>
s_regexPathParameterRegex.Matches(routePath).Cast<Match>().Select(x => x.Groups[1].ToString()).ToList();

private sealed class NestedByRouteComparer : IComparer<HttpMethodInfo>
Expand All @@ -311,8 +311,8 @@ public int Compare(HttpMethodInfo? left, HttpMethodInfo? right)
if (right is null)
return 1;

var leftParts = left.Path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
var rightParts = right.Path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
var leftParts = left.Path.Split(s_oneSlash, StringSplitOptions.RemoveEmptyEntries);
var rightParts = right.Path.Split(s_oneSlash, StringSplitOptions.RemoveEmptyEntries);
var partIndex = 0;
while (true)
{
Expand Down Expand Up @@ -353,6 +353,7 @@ public int Compare(HttpMethodInfo? left, HttpMethodInfo? right)
}
}

private static readonly List<string> s_httpMethods = new() { "GET", "POST", "PUT", "PATCH", "DELETE" };
private static readonly List<string> s_httpMethods = ["GET", "POST", "PUT", "PATCH", "DELETE"];
private static readonly Regex s_regexPathParameterRegex = new(@"\{([^\}]+)\}", RegexOptions.CultureInvariant);
private static readonly char[] s_oneSlash = ['/'];
}
2 changes: 1 addition & 1 deletion src/Facility.Definition/ServiceElementInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected internal void AddValidationError(ServiceDefinitionError error)
private protected ServiceElementInfo(IEnumerable<ServicePart> parts)
{
m_parts = parts.ToReadOnlyList();
m_validationErrors = new List<ServiceDefinitionError>();
m_validationErrors = [];
}

private protected void AddValidationErrors(IEnumerable<ServiceDefinitionError> errors)
Expand Down
4 changes: 3 additions & 1 deletion src/Facility.Definition/ServiceFieldValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal ServiceFieldValidation(ServiceAttributeInfo attribute)
return null;
}

var bounds = parameter.Value.Split(new[] { ".." }, 2, StringSplitOptions.None);
var bounds = parameter.Value.Split(s_oneDoubleDot, 2, StringSplitOptions.None);
var first = bounds[0];
var second = bounds.Length > 1 ? bounds[1] : null;

Expand Down Expand Up @@ -133,4 +133,6 @@ internal ServiceFieldValidation(ServiceAttributeInfo attribute)

return new ServiceFieldValidationRange(minimum, maximum);
}

private static readonly string[] s_oneDoubleDot = [".."];
}
14 changes: 7 additions & 7 deletions src/Facility.Definition/ServiceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public bool TryExcludeTag(string tagName, out ServiceInfo service, out IReadOnly
attributes: Attributes,
summary: Summary,
remarks: Remarks,
parts: GetParts().ToArray());
parts: [.. GetParts()]);

errors = service.GetValidationErrors()
.Select(x => new ServiceDefinitionError($"{x.Message} ('{tagName}' tags are excluded.)", x.Position))
Expand All @@ -131,7 +131,7 @@ ServiceMemberInfo DoExcludeTag(ServiceMemberInfo member)
attributes: method.Attributes,
summary: method.Summary,
remarks: method.Remarks,
parts: method.GetParts().ToArray());
parts: [.. method.GetParts()]);
}
else if (member is ServiceDtoInfo dto)
{
Expand All @@ -141,7 +141,7 @@ ServiceMemberInfo DoExcludeTag(ServiceMemberInfo member)
attributes: dto.Attributes,
summary: dto.Summary,
remarks: dto.Remarks,
parts: dto.GetParts().ToArray());
parts: [.. dto.GetParts()]);
}
else if (member is ServiceEnumInfo @enum)
{
Expand All @@ -151,7 +151,7 @@ ServiceMemberInfo DoExcludeTag(ServiceMemberInfo member)
attributes: @enum.Attributes,
summary: @enum.Summary,
remarks: @enum.Remarks,
parts: @enum.GetParts().ToArray());
parts: [.. @enum.GetParts()]);
}
else if (member is ServiceErrorSetInfo errorSet)
{
Expand All @@ -161,7 +161,7 @@ ServiceMemberInfo DoExcludeTag(ServiceMemberInfo member)
attributes: errorSet.Attributes,
summary: errorSet.Summary,
remarks: errorSet.Remarks,
parts: errorSet.GetParts().ToArray());
parts: [.. errorSet.GetParts()]);
}
else if (member is ServiceExternalDtoInfo externalDto)
{
Expand All @@ -170,7 +170,7 @@ ServiceMemberInfo DoExcludeTag(ServiceMemberInfo member)
attributes: externalDto.Attributes,
summary: externalDto.Summary,
remarks: externalDto.Remarks,
parts: externalDto.GetParts().ToArray());
parts: [.. externalDto.GetParts()]);
}
else if (member is ServiceExternalEnumInfo externalEnum)
{
Expand All @@ -179,7 +179,7 @@ ServiceMemberInfo DoExcludeTag(ServiceMemberInfo member)
attributes: externalEnum.Attributes,
summary: externalEnum.Summary,
remarks: externalEnum.Remarks,
parts: externalEnum.GetParts().ToArray());
parts: [.. externalEnum.GetParts()]);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/Facility.Definition/ServiceTypeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private ServiceTypeInfo(ServiceTypeKind kind, ServiceDtoInfo? dto = null, Servic
}

private static readonly (ServiceTypeKind Kind, string Name)[] s_primitives =
{
[
(ServiceTypeKind.String, "string"),
(ServiceTypeKind.Boolean, "boolean"),
(ServiceTypeKind.Double, "double"),
Expand All @@ -188,5 +188,5 @@ private static readonly (ServiceTypeKind Kind, string Name)[] s_primitives =
(ServiceTypeKind.Object, "object"),
(ServiceTypeKind.Error, "error"),
(ServiceTypeKind.DateTime, "datetime"),
};
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/Facility.Definition.UnitTests/TestUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public static string[] GenerateFsd(ServiceInfo service, FsdGeneratorSettings? se
var generator = new FsdGenerator { GeneratorName = "TestUtility" };
if (settings is not null)
generator.ApplySettings(settings);
return generator.GenerateOutput(service).Files[0].Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
return generator.GenerateOutput(service).Files[0].Text.Split(Environment.NewLine);
}
}
Loading

0 comments on commit fcb02e4

Please sign in to comment.