Skip to content

Commit

Permalink
Fixing some issues. Switching to strong name signed glob
Browse files Browse the repository at this point in the history
  • Loading branch information
belav committed Jul 15, 2023
1 parent e942cbf commit cb6cb93
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageVersion Include="CliWrap" Version="3.3.3" />
<PackageVersion Include="DiffEngine" Version="6.5.7" />
<PackageVersion Include="FluentAssertions" Version="5.10.3" />
<PackageVersion Include="Glob" Version="1.1.9" />
<PackageVersion Include="DotNet.Glob" Version="3.1.3" />
<PackageVersion Include="Ignore" Version="0.1.48" />
<PackageVersion Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.6.0" />
Expand Down
3 changes: 1 addition & 2 deletions Src/CSharpier.Cli/CSharpier.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
<PackAsTool>true</PackAsTool>
<AssemblyOriginatorKeyFile>../../Nuget/csharpier.snk</AssemblyOriginatorKeyFile>
<SignAssembly>True</SignAssembly>
<!-- TODO 1 why is this signed again? Glob is not so this causes headaches-->
<PublicKey>002400000480000094000000060200000024000052534131000400000100010049d266ea1aeae09c0abfce28b8728314d4e4807126ee8bc56155a7ddc765997ed3522908b469ae133fc49ef0bfa957df36082c1c2e0ec8cdc05a4ca4dbd4e1bea6c17fc1008555e15af13a8fc871a04ffc38f5e60e6203bfaf01d16a2a283b90572ade79135801c1675bf38b7a5a60ec8353069796eb53a26ffdddc9ee1273be</PublicKey>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Glob" />
<PackageReference Include="DotNet.Glob" />
<PackageReference Include="Ignore" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="System.CommandLine" />
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.Cli/CommandLineFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ CancellationToken cancellationToken
: isDirectory
? directoryOrFilePath
: string.Empty;
// TODO 1 if single file don't look in subtree? just look for the one for this file

var optionsProvider = await OptionsProvider.Create(
directoryName,
commandLineOptions.ConfigPath,
Expand Down
26 changes: 21 additions & 5 deletions Src/CSharpier.Cli/EditorConfig/EditorConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,31 @@ public static List<EditorConfigSections> FindForDirectoryName(
IFileSystem fileSystem
)
{
// TODO 1 this may not actually find things above the current directory
if (directoryName is "")
{
return new List<EditorConfigSections>();
}

var editorConfigFiles = fileSystem.DirectoryInfo
.FromDirectoryName(directoryName)
.EnumerateFiles(".editorconfig", SearchOption.AllDirectories);
var directoryInfo = fileSystem.DirectoryInfo.FromDirectoryName(directoryName);
var editorConfigFiles = directoryInfo
.EnumerateFiles(".editorconfig", SearchOption.AllDirectories)
.ToList();

// already found any in this directory above
directoryInfo = directoryInfo.Parent;

while (directoryInfo is not null)
{
var file = fileSystem.FileInfo.FromFileName(
fileSystem.Path.Combine(directoryInfo.FullName, ".editorconfig")
);
if (file.Exists)
{
editorConfigFiles.Add(file);
}

directoryInfo = directoryInfo.Parent;
}

return editorConfigFiles
.Select(
Expand All @@ -29,7 +45,7 @@ IFileSystem fileSystem
SectionsIncludingParentFiles = FindSections(o.FullName, fileSystem)
}
)
.OrderBy(o => o.DirectoryName)
.OrderByDescending(o => o.DirectoryName.Length)
.ToList();
}

Expand Down
8 changes: 4 additions & 4 deletions Src/CSharpier.Cli/EditorConfig/Section.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
namespace CSharpier.Cli.EditorConfig;

using GlobExpressions;
using DotNet.Globbing;

public class Section
{
private readonly Glob matcher;
public string Glob { get; }
public string Pattern { get; }
public string? IndentStyle { get; }
public string? IndentSize { get; }
public string? TabWidth { get; }
public string? MaxLineLength { get; }

public Section(string name, string directory, Dictionary<string, string?> properties)
{
this.Glob = FixGlob(name, directory);
this.matcher = new Glob(name);
this.Pattern = FixGlob(name, directory);
this.matcher = Glob.Parse(this.Pattern);
this.IndentStyle = properties.TryGetValue("indent_style", out var indentStyle)
? indentStyle
: null;
Expand Down
8 changes: 4 additions & 4 deletions Src/CSharpier.Cli/Options/OptionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public PrinterOptions GetPrinterOptionsFor(string filePath)

var directoryName = this.fileSystem.Path.GetDirectoryName(filePath);
var resolvedEditorConfig = this.configs.FirstOrDefault(
o => o.DirectoryName.StartsWith(directoryName)
o => directoryName.StartsWith(o.DirectoryName)
);
var resolvedCSharpierConfig = this.csharpierConfigs.FirstOrDefault(
o => o.DirectoryName.StartsWith(directoryName)
o => directoryName.StartsWith(o.DirectoryName)
);

if (resolvedEditorConfig is null && resolvedCSharpierConfig is null)
Expand All @@ -80,8 +80,8 @@ public PrinterOptions GetPrinterOptionsFor(string filePath)
}

if (
(resolvedCSharpierConfig?.DirectoryName.Length ?? int.MaxValue)
< (resolvedEditorConfig?.DirectoryName.Length ?? int.MaxValue)
(resolvedCSharpierConfig?.DirectoryName.Length ?? int.MinValue)
>= (resolvedEditorConfig?.DirectoryName.Length ?? int.MinValue)
)
{
return ConfigurationFileOptions.ConvertToPrinterOptions(
Expand Down
Loading

0 comments on commit cb6cb93

Please sign in to comment.