Skip to content

Commit 0d6473c

Browse files
committed
Ensure that internal code is never exposed through InternalsVisibleTo
1 parent fb8a019 commit 0d6473c

File tree

12 files changed

+499
-437
lines changed

12 files changed

+499
-437
lines changed

.packageguard/cache.bin

283 Bytes
Binary file not shown.

Build/_build.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<PackageReference Include="Nuke.Components" Version="9.0.4" />
1717
<PackageDownload Include="ReportGenerator" Version="[5.2.0]" />
1818
<PackageDownload Include="GitVersion.Tool" Version="[6.0.2]" />
19-
<PackageDownload Include="PackageGuard" Version="[1.4.1]" />
19+
<PackageDownload Include="PackageGuard" Version="[1.6.0]" />
2020
</ItemGroup>
2121

2222
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Pathy.Specs")]
2+
namespace Pathy
3+
{
4+
public static class ChainablePathExtensions
5+
{
6+
public static Pathy.ChainablePath[] GlobFiles(this Pathy.ChainablePath path, string globPattern) { }
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Pathy.Specs")]
2+
namespace Pathy
3+
{
4+
public static class ChainablePathExtensions
5+
{
6+
public static Pathy.ChainablePath[] GlobFiles(this Pathy.ChainablePath path, string globPattern) { }
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Pathy.Specs")]
2+
namespace Pathy
3+
{
4+
public static class ChainablePathExtensions
5+
{
6+
public static Pathy.ChainablePath[] GlobFiles(this Pathy.ChainablePath path, string globPattern) { }
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Pathy.Specs")]
2+
namespace Pathy
3+
{
4+
public static class ChainablePathExtensions
5+
{
6+
public static Pathy.ChainablePath[] GlobFiles(this Pathy.ChainablePath path, string globPattern) { }
7+
}
8+
}

Pathy.ApiVerificationTests/Pathy.ApiVerificationTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</PackageReference>
1414
<PackageReference Include="PublicApiGenerator" Version="11.4.6" />
1515
<PackageReference Include="Verify.DiffPlex" Version="3.1.2" />
16-
<PackageReference Include="Verify.Xunit" Version="30.5.0" />
16+
<PackageReference Include="Verify.Xunit" Version="30.7.2" />
1717
</ItemGroup>
1818

1919
<ItemGroup>

Pathy.Globbing/Pathy.Globbing.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ImplicitUsings>disable</ImplicitUsings>
88
<NuSpecFile>.nuspec</NuSpecFile>
99
<NuspecProperties>version=$(Version)</NuspecProperties>
10-
<DefineConstants>MYPACKAGE_COMPILE</DefineConstants>
10+
<DefineConstants>PATHY_PUBLIC</DefineConstants>
1111
<NoWarn>1591;1573</NoWarn>
1212
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
1313
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>

Pathy.Globbing/PathyGlobbing.cs

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// <autogenerated />
22

33
using System;
4+
using System.Diagnostics.CodeAnalysis;
45
using System.Linq;
56
using Microsoft.Extensions.FileSystemGlobbing;
67
using Microsoft.Extensions.FileSystemGlobbing.Abstractions;
@@ -10,32 +11,48 @@
1011
#nullable disable
1112

1213
// ReSharper disable once CheckNamespace
13-
namespace Pathy;
14-
14+
namespace Pathy
15+
{
1516
#if PATHY_PUBLIC
16-
public static class ChainablePathExtensions
17+
public static class ChainablePathExtensions
1718
#else
18-
internal static class ChainablePathExtensions
19+
[global::Microsoft.CodeAnalysis.Embedded]
20+
internal static class ChainablePathExtensions
1921
#endif
22+
{
23+
/// <summary>
24+
/// Matches files in the specified directory or subdirectories according to the provided glob pattern
25+
/// and returns them as an array of <see cref="ChainablePath"/> objects.
26+
/// </summary>
27+
/// <remarks>
28+
/// See also <seealso href="https://learn.microsoft.com/en-us/dotnet/core/extensions/file-globbing"/>
29+
/// </remarks>
30+
/// <param name="path">The base directory path to start the glob search from.</param>
31+
/// <param name="globPattern">The glob pattern used to match file paths, e.g. **/*.md or dir/**/*</param>
32+
public static ChainablePath[] GlobFiles(this ChainablePath path, string globPattern)
33+
{
34+
Matcher matcher = new(StringComparison.OrdinalIgnoreCase);
35+
matcher.AddInclude(globPattern);
36+
37+
return matcher
38+
.Execute(new DirectoryInfoWrapper(path.ToDirectoryInfo()))
39+
.Files
40+
.Select(file => ChainablePath.From(path / file.Path))
41+
.ToArray();
42+
}
43+
}
44+
}
45+
46+
// Licensed to the .NET Foundation under one or more agreements.
47+
// The .NET Foundation licenses this file to you under the MIT license.
48+
namespace Microsoft.CodeAnalysis
2049
{
2150
/// <summary>
22-
/// Matches files in the specified directory or subdirectories according to the provided glob pattern
23-
/// and returns them as an array of <see cref="ChainablePath"/> objects.
51+
/// A special attribute recognized by Roslyn, that marks a type as "embedded", meaning it won't ever be visible from other assemblies.
2452
/// </summary>
25-
/// <remarks>
26-
/// See also <seealso href="https://learn.microsoft.com/en-us/dotnet/core/extensions/file-globbing"/>
27-
/// </remarks>
28-
/// <param name="path">The base directory path to start the glob search from.</param>
29-
/// <param name="globPattern">The glob pattern used to match file paths, e.g. **/*.md or dir/**/*</param>
30-
public static ChainablePath[] GlobFiles(this ChainablePath path, string globPattern)
53+
[AttributeUsage(AttributeTargets.All)]
54+
[ExcludeFromCodeCoverage]
55+
internal sealed class EmbeddedAttribute : Attribute
3156
{
32-
Matcher matcher = new(StringComparison.OrdinalIgnoreCase);
33-
matcher.AddInclude(globPattern);
34-
35-
return matcher
36-
.Execute(new DirectoryInfoWrapper(path.ToDirectoryInfo()))
37-
.Files
38-
.Select(file => ChainablePath.From(path / file.Path))
39-
.ToArray();
4057
}
4158
}

Pathy.Specs/ChainablePathSpecs.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.IO;
3-
using System.Linq;
43
using System.Reflection;
54
using FluentAssertions;
65
using Xunit;

0 commit comments

Comments
 (0)