Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add editorconfig to enforce private and public member naming convention #137

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright The ORAS Authors.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# 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
shizhMSFT marked this conversation as resolved.
Show resolved Hide resolved
insert_final_newline = false
shizhMSFT marked this conversation as resolved.
Show resolved Hide resolved

#### .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
Loading