Skip to content

Commit

Permalink
Added editorconfig to enforce private and public member naming conven…
Browse files Browse the repository at this point in the history
…tion

Signed-off-by: Daniel Robinson <[email protected]>
  • Loading branch information
daniel-pebble committed Aug 10, 2024
1 parent 1f939a5 commit 4bf2a21
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 28 deletions.
40 changes: 40 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true

# C# files
[*.cs]

#### Core EditorConfig Options ####

# Indentation and spacing
indent_size = 4
indent_style = space
tab_width = 4

# New line preferences
end_of_line = crlf
insert_final_newline = false

#### .NET Coding Conventions ####

# Naming Rules
dotnet_naming_rule.private_fields_should_start_with_underscore.severity = error
dotnet_naming_rule.private_fields_should_start_with_underscore.symbols = private_fields
dotnet_naming_rule.private_fields_should_start_with_underscore.style = private_underscore_style

dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private
dotnet_naming_symbols.private_fields.required_modifiers =

dotnet_naming_style.private_underscore_style.capitalization = camel_case
dotnet_naming_style.private_underscore_style.required_prefix = _

dotnet_naming_rule.public_members_should_start_with_uppercase.severity = error
dotnet_naming_rule.public_members_should_start_with_uppercase.symbols = public_members
dotnet_naming_rule.public_members_should_start_with_uppercase.style = public_uppercase_style

dotnet_naming_symbols.public_members.applicable_kinds = property, field, method
dotnet_naming_symbols.public_members.applicable_accessibilities = public
dotnet_naming_symbols.public_members.required_modifiers =

dotnet_naming_style.public_uppercase_style.capitalization = pascal_case
56 changes: 28 additions & 28 deletions tests/OrasProject.Oras.Tests/Remote/RepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public class RepositoryTest
{
public struct TestIOStruct
{
public bool isTag;
public bool errExpectedOnHEAD;
public string serverCalculatedDigest;
public string clientSuppliedReference;
public bool errExpectedOnGET;
public bool IsTag;
public bool ErrExpectedOnHEAD;
public string ServerCalculatedDigest;
public string ClientSuppliedReference;
public bool ErrExpectedOnGET;
}

private byte[] _theAmazingBanClan = "Ban Gu, Ban Chao, Ban Zhao"u8.ToArray();
Expand Down Expand Up @@ -93,34 +93,34 @@ public static Dictionary<string, TestIOStruct> GetTestIOStructMapForGetDescripto
{
["1. Client:Tag & Server:DigestMissing"] = new TestIOStruct
{
isTag = true,
errExpectedOnHEAD = true
IsTag = true,
ErrExpectedOnHEAD = true
},
["2. Client:Tag & Server:DigestValid"] = new TestIOStruct
{
isTag = true,
serverCalculatedDigest = correctDigest
IsTag = true,
ServerCalculatedDigest = correctDigest
},
["3. Client:Tag & Server:DigestWrongButSyntacticallyValid"] = new TestIOStruct
{
isTag = true,
serverCalculatedDigest = incorrectDigest
IsTag = true,
ServerCalculatedDigest = incorrectDigest
},
["4. Client:DigestValid & Server:DigestMissing"] = new TestIOStruct
{
clientSuppliedReference = correctDigest
ClientSuppliedReference = correctDigest
},
["5. Client:DigestValid & Server:DigestValid"] = new TestIOStruct
{
clientSuppliedReference = correctDigest,
serverCalculatedDigest = correctDigest
ClientSuppliedReference = correctDigest,
ServerCalculatedDigest = correctDigest
},
["6. Client:DigestValid & Server:DigestWrongButSyntacticallyValid"] = new TestIOStruct
{
clientSuppliedReference = correctDigest,
serverCalculatedDigest = incorrectDigest,
errExpectedOnHEAD = true,
errExpectedOnGET = true
ClientSuppliedReference = correctDigest,
ServerCalculatedDigest = incorrectDigest,
ErrExpectedOnHEAD = true,
ErrExpectedOnGET = true
}
};
}
Expand Down Expand Up @@ -1489,25 +1489,25 @@ public void GenerateBlobDescriptor_WithVariousDockerContentDigestHeaders()
var tests = GetTestIOStructMapForGetDescriptorClass();
foreach ((string testName, TestIOStruct dcdIOStruct) in tests)
{
if (dcdIOStruct.isTag)
if (dcdIOStruct.IsTag)
{
continue;
}
HttpMethod[] methods = new HttpMethod[] { HttpMethod.Get, HttpMethod.Head };
foreach ((int i, HttpMethod method) in methods.Select((value, i) => (i, value)))
{
reference.ContentReference = dcdIOStruct.clientSuppliedReference;
reference.ContentReference = dcdIOStruct.ClientSuppliedReference;
var resp = new HttpResponseMessage();
if (method == HttpMethod.Get)
{
resp.Content = new ByteArrayContent(_theAmazingBanClan);
resp.Content.Headers.Add("Content-Type", new string[] { "application/vnd.docker.distribution.manifest.v2+json" });
resp.Headers.Add(_dockerContentDigestHeader, new string[] { dcdIOStruct.serverCalculatedDigest });
resp.Headers.Add(_dockerContentDigestHeader, new string[] { dcdIOStruct.ServerCalculatedDigest });
}
if (!resp.Headers.TryGetValues(_dockerContentDigestHeader, out IEnumerable<string>? values))
{
resp.Content.Headers.Add("Content-Type", new string[] { "application/vnd.docker.distribution.manifest.v2+json" });
resp.Headers.Add(_dockerContentDigestHeader, new string[] { dcdIOStruct.serverCalculatedDigest });
resp.Headers.Add(_dockerContentDigestHeader, new string[] { dcdIOStruct.ServerCalculatedDigest });
resp.RequestMessage = new HttpRequestMessage()
{
Method = method
Expand All @@ -1533,12 +1533,12 @@ public void GenerateBlobDescriptor_WithVariousDockerContentDigestHeaders()
$"[Blob.{method}] {testName}; got digest from a tag reference unexpectedly");
}

var errExpected = new bool[] { dcdIOStruct.errExpectedOnGET, dcdIOStruct.errExpectedOnHEAD }[i];
var errExpected = new bool[] { dcdIOStruct.ErrExpectedOnGET, dcdIOStruct.ErrExpectedOnHEAD }[i];
if (d.Length == 0)
{
// To avoid an otherwise impossible scenario in the tested code
// path, we set d so that verifyContentDigest does not break.
d = dcdIOStruct.serverCalculatedDigest;
d = dcdIOStruct.ServerCalculatedDigest;
}

var err = false;
Expand Down Expand Up @@ -2238,25 +2238,25 @@ public async Task ManifestStore_generateDescriptorWithVariousDockerContentDigest
var s = new ManifestStore(repo);
foreach ((int i, HttpMethod method) in methods.Select((value, i) => (i, value)))
{
reference.ContentReference = dcdIOStruct.clientSuppliedReference;
reference.ContentReference = dcdIOStruct.ClientSuppliedReference;
var resp = new HttpResponseMessage();
if (method == HttpMethod.Get)
{
resp.Content = new ByteArrayContent(_theAmazingBanClan);
resp.Content.Headers.Add("Content-Type", new string[] { "application/vnd.docker.distribution.manifest.v2+json" });
resp.Headers.Add(_dockerContentDigestHeader, new string[] { dcdIOStruct.serverCalculatedDigest });
resp.Headers.Add(_dockerContentDigestHeader, new string[] { dcdIOStruct.ServerCalculatedDigest });
}
else
{
resp.Content.Headers.Add("Content-Type", new string[] { "application/vnd.docker.distribution.manifest.v2+json" });
resp.Headers.Add(_dockerContentDigestHeader, new string[] { dcdIOStruct.serverCalculatedDigest });
resp.Headers.Add(_dockerContentDigestHeader, new string[] { dcdIOStruct.ServerCalculatedDigest });
}
resp.RequestMessage = new HttpRequestMessage()
{
Method = method
};

var errExpected = new bool[] { dcdIOStruct.errExpectedOnGET, dcdIOStruct.errExpectedOnHEAD }[i];
var errExpected = new bool[] { dcdIOStruct.ErrExpectedOnGET, dcdIOStruct.ErrExpectedOnHEAD }[i];

var err = false;
try
Expand Down

0 comments on commit 4bf2a21

Please sign in to comment.