Skip to content

Commit

Permalink
Add an EditorConfig file (loic-sharma#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
loic-sharma authored Dec 10, 2018
1 parent 8a4b53a commit ee50340
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 69 deletions.
96 changes: 96 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
; This is the default for the codeline.
root = true

[*]
indent_style = space
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{htm,html,js,ts,tsx,css,sass,scss,less,svg,vue}]
indent_size = 2

[*.{xml,config,*proj,nuspec,props,resx,targets,yml,tasks}]
indent_size = 2

[*.json]
indent_size = 2

[*.{ps1,psm1}]
indent_size = 4

[*.sh]
indent_size = 4
end_of_line = lf

[*.cs]
indent_size = 4

# .NET Coding Conventions

# Organize usings
dotnet_sort_system_directives_first = true:warning

# this. preferences
dotnet_style_qualification_for_field = false:warning
dotnet_style_qualification_for_property = false:warning
dotnet_style_qualification_for_method = false:warning
dotnet_style_qualification_for_event = false:warning

# Language keywords vs BCL type preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:warning
dotnet_style_predefined_type_for_member_access = true:warning

# Modifier preferences
dotnet_style_require_accessibility_modifiers = always:warning
dotnet_style_readonly_field = true:warning

# Naming Conventions

# Style Definitions
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# Use PascalCase for constant fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const

# C# Code Style Rules

# var preferences
csharp_style_var_for_built_in_types = true:warning
csharp_style_var_when_type_is_apparent = true:warning
csharp_style_var_elsewhere = true:warning

# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async

# New line preferences
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true

# Indentation preferences
csharp_indent_case_contents = true
csharp_indent_switch_labels = true

# Space preferences
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false

# Wrapping preferences
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true
9 changes: 7 additions & 2 deletions BaGet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{26A0B557-53F
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{C237857D-AD8E-4C52-974F-6A8155BB0C18}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BaGet.Protocol", "src\BaGet.Protocol\BaGet.Protocol.csproj", "{A2D23427-9278-4D52-B31F-759212252832}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Protocol", "src\BaGet.Protocol\BaGet.Protocol.csproj", "{A2D23427-9278-4D52-B31F-759212252832}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BaGet.Protocol.Tests", "tests\BaGet.Protocol.Tests\BaGet.Protocol.Tests.csproj", "{AC764A9A-9EAF-422B-9223-D3290C3CFD79}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Protocol.Tests", "tests\BaGet.Protocol.Tests\BaGet.Protocol.Tests.csproj", "{AC764A9A-9EAF-422B-9223-D3290C3CFD79}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0B44364D-952B-497A-82E0-C9AAE94E0369}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
3 changes: 1 addition & 2 deletions src/BaGet.Azure/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BaGet.Azure.Configuration;
using BaGet.Azure.Configuration;
using BaGet.Azure.Search;
using BaGet.Core.Services;
using Microsoft.Azure.Search;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down
2 changes: 1 addition & 1 deletion src/BaGet.Core/Extensions/StreamExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
Expand Down
7 changes: 2 additions & 5 deletions src/BaGet.Core/Services/ApiKeyAuthenticationService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using BaGet.Core.Configuration;
using Microsoft.Extensions.Options;
Expand All @@ -23,10 +21,9 @@ public ApiKeyAuthenticationService(IOptionsSnapshot<BaGetOptions> options)
private bool Authenticate(string apiKey)
{
// No authentication is necessary if there is no required API key.
if (_apiKey == null)
return true;
if (_apiKey == null) return true;

return _apiKey == apiKey;
}
}
}
}
5 changes: 4 additions & 1 deletion src/BaGet.Core/Services/DatabaseSearchService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -28,6 +28,9 @@ public async Task<IReadOnlyList<SearchResult>> SearchAsync(string query, int ski
search = search.Where(p => p.Id.ToLower().Contains(query));
}

// This query MUST fetch all versions for each returned package, otherwise this could return
// incorrect results for a package's latest version. This query first finds package ids,
// then it returns all versions for those package ids.
var packages = await _context.Packages
.Where(p =>
search.Select(p2 => p2.Id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

namespace BaGet.Tools.AzureSearchImporter.Entities
{
class IndexerContextFactory : IDesignTimeDbContextFactory<IndexerContext>
public class IndexerContextFactory : IDesignTimeDbContextFactory<IndexerContext>
{
public const string ConnectionString = "Data Source=indexer.db";

Expand Down
2 changes: 1 addition & 1 deletion src/BaGet.Tools.AzureSearchImporter/Initializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Threading.Tasks;
using BaGet.Azure.Search;
Expand Down
6 changes: 3 additions & 3 deletions src/BaGet.Tools.AzureSearchImporter/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks;
using BaGet.Azure.Extensions;
using BaGet.Core.Configuration;
Expand All @@ -12,7 +12,7 @@

namespace BaGet.Tools.AzureSearchImporter
{
class Program
public class Program
{
public static void Main(string[] args)
=> MainAsync(args)
Expand All @@ -22,7 +22,7 @@ public static void Main(string[] args)
private async static Task MainAsync(string[] args)
{
// Parse the skip from arguments.
int skip = 0;
var skip = 0;

if (args.Length > 0)
{
Expand Down
3 changes: 1 addition & 2 deletions src/BaGet/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Reflection;
Expand Down
3 changes: 1 addition & 2 deletions src/BaGet/Routes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BaGet
namespace BaGet
{
public class Routes
{
Expand All @@ -16,6 +16,5 @@ public class Routes
public const string PackageDownloadManifestRouteName = "package-download-manifest";
public const string PackageDownloadReadmeRouteName = "package-download-readme";
public const string SymbolDownloadRouteName = "symbol-download";

}
}
3 changes: 1 addition & 2 deletions tests/BaGet.Core.Tests/Services/FileStorageServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BaGet.Core.Configuration;
using BaGet.Core.Services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Threading;
using System.Threading;
using System.Threading.Tasks;
using BaGet.Core.Configuration;
using BaGet.Core.Services;
Expand Down
2 changes: 1 addition & 1 deletion tests/BaGet.Protocol.Tests/PackageContentClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;
Expand Down
43 changes: 20 additions & 23 deletions tests/BaGet.Tests/NuGetClientIntegrationTest.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System;
using System.Linq;
using Xunit.Abstractions;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.TestHost;
using Xunit;
using System.Threading.Tasks;
using System.Collections.Generic;
using NuGet.Protocol.Core.Types;
using NuGet.Protocol;
using NuGet.Configuration;
using BaGet.Tests.Support;
using System.Net.Http;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using BaGet.Tests.Support;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Logging;
using NuGet.Configuration;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using Xunit;
using Xunit.Abstractions;

namespace BaGet.Tests
{
Expand All @@ -22,34 +21,33 @@ public class NuGetClientIntegrationTest : IDisposable
{
protected readonly ITestOutputHelper Helper;
private readonly TestServer server;
readonly string IndexUrlString = "v3/index.json";
SourceRepository _sourceRepository;
private SourceCacheContext _cacheContext;
HttpSourceResource _httpSource;
private readonly string IndexUrlString = "v3/index.json";
private SourceRepository _sourceRepository;
private readonly SourceCacheContext _cacheContext;
private HttpSourceResource _httpSource;
private HttpClient _httpClient;
string indexUrl;
private readonly string indexUrl;

public NuGetClientIntegrationTest(ITestOutputHelper helper)
{
Helper = helper ?? throw new ArgumentNullException(nameof(helper));
server = TestServerBuilder.Create().TraceToTestOutputHelper(Helper,LogLevel.Error).Build();
server = TestServerBuilder.Create().TraceToTestOutputHelper(Helper, LogLevel.Error).Build();
var providers = new List<Lazy<INuGetResourceProvider>>();
providers.AddRange(Repository.Provider.GetCoreV3());
providers.Add(new Lazy<INuGetResourceProvider>(() => new PackageMetadataResourceV3Provider()));
_httpClient = server.CreateClient();
providers.Insert(0, new Lazy<INuGetResourceProvider>(() => new HttpSourceResourceProviderTestHost(_httpClient)));

indexUrl = new Uri(server.BaseAddress, IndexUrlString).AbsoluteUri;
PackageSource packageSource = new PackageSource(indexUrl);
var packageSource = new PackageSource(indexUrl);
_sourceRepository = new SourceRepository(packageSource, providers);
_cacheContext = new SourceCacheContext() { NoCache = true, MaxAge=new DateTimeOffset(), DirectDownload=true };
_cacheContext = new SourceCacheContext() { NoCache = true, MaxAge = new DateTimeOffset(), DirectDownload = true };
_httpSource = _sourceRepository.GetResource<HttpSourceResource>();
Assert.IsType<HttpSourceTestHost>(_httpSource.HttpSource);
}
public void Dispose()
{
if(server != null)
server.Dispose();
server?.Dispose();
}

[Fact]
Expand Down Expand Up @@ -94,6 +92,5 @@ public async Task IndexIncludesAtLeastOneSearchAutocompleteServiceEntry()
var indexResource = await _sourceRepository.GetResourceAsync<ServiceIndexResourceV3>();
Assert.NotEmpty(indexResource.GetServiceEntries("SearchAutocompleteService"));
}

}
}
}
10 changes: 4 additions & 6 deletions tests/BaGet.Tests/PackageControllerTest.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Logging;
using Xunit;
using Xunit.Abstractions;
namespace BaGet.Tests
{

public class PackageControllerTest
public class PackageControllerTest
{
protected readonly ITestOutputHelper Helper;

readonly string IndexUrlFormatString = "v3/package/{0}/index.json";
private readonly string IndexUrlFormatString = "v3/package/{0}/index.json";

public PackageControllerTest(ITestOutputHelper helper)
{
Expand All @@ -23,10 +21,10 @@ public PackageControllerTest(ITestOutputHelper helper)
[InlineData("id02")]
public async Task AskEmptyServerForNotExistingPackageID(string packageID)
{
using (TestServer server = TestServerBuilder.Create().TraceToTestOutputHelper(Helper,LogLevel.Error).Build())
using (var server = TestServerBuilder.Create().TraceToTestOutputHelper(Helper, LogLevel.Error).Build())
{
//Ask Empty Storage for a not existings ID
var response = await server.CreateClient().GetAsync(string.Format(IndexUrlFormatString, packageID));
var response = await server.CreateClient().GetAsync(string.Format(IndexUrlFormatString, packageID));
Assert.Equal(System.Net.HttpStatusCode.NotFound, response.StatusCode);
}
}
Expand Down
Loading

0 comments on commit ee50340

Please sign in to comment.