Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
219 changes: 219 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
# editorconfig.org

# top-most EditorConfig file
root = true

### Default settings:
[*]
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = crlf
indent_style = space

# C# files
[*.cs]
indent_size = 4

# https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules

# 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
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true

# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = false
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true

# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false

# 'Using' directive preferences
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false

# License header
dotnet_diagnostic.IDE0073.severity = warning
file_header_template = Copyright (c) Microsoft Corporation. All Rights Reserved.\nLicensed under the MIT license.

# Code style defaults
csharp_prefer_braces = true:suggestion
csharp_prefer_static_local_function = true:suggestion
csharp_style_prefer_switch_expression = true:suggestion
dotnet_style_readonly_field = true:warning
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion

# Expression-level preferences
dotnet_diagnostic.IDE0001.severity = warning # simplify name
dotnet_diagnostic.IDE0002.severity = warning # simplify member access
dotnet_diagnostic.IDE0004.severity = warning # remove unnecessary cast
dotnet_style_operator_placement_when_wrapping = end_of_line
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion

# Expression-bodied members
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_lambdas = true:suggestion
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent

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

# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion

# Avoid this. unless absolutely necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion

# New-line preferences
dotnet_style_allow_multiple_blank_lines_experimental = false:warning
csharp_style_allow_embedded_statements_on_same_line_experimental = false:warning
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = false:warning
dotnet_style_allow_statement_immediately_after_block_experimental = false:warning
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = false:warning
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false:warning
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = false:warning

# Types: use keywords instead of BCL types, and permit var only when the type is clear
csharp_style_var_for_built_in_types = false:warning
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = false:warning
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# Null checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# Pascal case naming rule
dotnet_naming_style.ipascalcase.required_prefix = I
dotnet_naming_style.ipascalcase.capitalization = pascal_case

dotnet_naming_rule.interfaces_should_be_ipascalcase.severity = warning
dotnet_naming_rule.interfaces_should_be_ipascalcase.symbols = interfaces
dotnet_naming_rule.interfaces_should_be_ipascalcase.style = ipascalcase
dotnet_naming_symbols.interfaces.applicable_kinds = interface

dotnet_naming_style.pascalcase.capitalization = pascal_case

dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.severity = warning
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.symbols = types_and_namespaces
dotnet_naming_rule.types_and_namespaces_should_be_pascalcase.style = pascalcase
dotnet_naming_symbols.types_and_namespaces.applicable_kinds = namespace, class, struct, enum

dotnet_naming_rule.non_field_members_should_be_pascalcase.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascalcase.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascalcase.style = pascalcase
dotnet_naming_symbols.non_field_members.applicable_kinds = property, method

dotnet_naming_rule.local_constants_should_be_camelcase.severity = suggestion
dotnet_naming_rule.local_constants_should_be_camelcase.symbols = local_constants
dotnet_naming_rule.local_constants_should_be_camelcase.style = pascalcase
dotnet_naming_symbols.local_constants.applicable_kinds = local
dotnet_naming_symbols.local_constants.applicable_accessibilities = local
dotnet_naming_symbols.local_constants.required_modifiers = const

# Camel case naming rule
dotnet_naming_style._camelcase.required_prefix = _
dotnet_naming_style._camelcase.capitalization = camel_case

dotnet_naming_rule.private_fields_should_be__camelcase.severity = suggestion
dotnet_naming_rule.private_fields_should_be__camelcase.symbols = private_fields
dotnet_naming_rule.private_fields_should_be__camelcase.style = _camelcase
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private, protected, protected_internal, private_protected

dotnet_naming_style.camelcase.capitalization = camel_case

dotnet_naming_rule.parameters_should_be_camelcase.severity = suggestion
dotnet_naming_rule.parameters_should_be_camelcase.symbols = parameters
dotnet_naming_rule.parameters_should_be_camelcase.style = camelcase
dotnet_naming_symbols.parameters.applicable_kinds = parameter
dotnet_naming_symbols.parameters.applicable_accessibilities = *

dotnet_naming_rule.local_variables_should_be_camelcase.severity = suggestion
dotnet_naming_rule.local_variables_should_be_camelcase.symbols = local_variables
dotnet_naming_rule.local_variables_should_be_camelcase.style = camelcase
dotnet_naming_symbols.local_variables.applicable_kinds = local
dotnet_naming_symbols.local_variables.applicable_accessibilities = local

# Xml project files
[*.csproj]
indent_size = 2
charset = utf-8

# Xml build files
[*.builds]
indent_size = 2

# Xml files
[*.xml]
indent_size = 2

# Xml config files
[*.{props,targets,config,nuspec}]
indent_size = 2

# YAML config files
[*.{yml,yaml}]
indent_size = 2

# JSON config files
[*.json]
indent_size = 2

# Shell scripts
[*.sh]
end_of_line = lf
[*.{cmd,bat}]
end_of_line = crlf
7 changes: 5 additions & 2 deletions examples/BlazorServerApp/BrowserFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.FeatureManagement;
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT license.

using Microsoft.FeatureManagement;

namespace BlazorServerApp
{
Expand Down Expand Up @@ -45,7 +48,7 @@ private static bool IsChromeBrowser(string userAgentContext)
return false;
}

return userAgentContext.Contains("chrome", StringComparison.OrdinalIgnoreCase) &&
return userAgentContext.Contains("chrome", StringComparison.OrdinalIgnoreCase) &&
!userAgentContext.Contains("edg", StringComparison.OrdinalIgnoreCase);
}

Expand Down
5 changes: 4 additions & 1 deletion examples/BlazorServerApp/BrowserFilterSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace BlazorServerApp
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT license.

namespace BlazorServerApp
{
public class BrowserFilterSettings
{
Expand Down
3 changes: 3 additions & 0 deletions examples/BlazorServerApp/Data/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT license.

namespace BlazorServerApp.Data
{
public class WeatherForecast
Expand Down
3 changes: 3 additions & 0 deletions examples/BlazorServerApp/Data/WeatherForecastService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT license.

namespace BlazorServerApp.Data
{
public class WeatherForecastService
Expand Down
5 changes: 4 additions & 1 deletion examples/BlazorServerApp/MyTargetingContextAccessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.AspNetCore.Components.Authorization;
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT license.

using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.FeatureManagement.FeatureFilters;

namespace BlazorServerApp
Expand Down
7 changes: 5 additions & 2 deletions examples/BlazorServerApp/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT license.

using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace BlazorServerApp.Pages
{
Expand Down
9 changes: 6 additions & 3 deletions examples/BlazorServerApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT license.

using BlazorServerApp.Data;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.FeatureManagement;
Expand All @@ -8,7 +11,7 @@ public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
Expand All @@ -26,7 +29,7 @@ public static void Main(string[] args)
.WithTargeting<MyTargetingContextAccessor>()
.AddFeatureFilter<BrowserFilter>();

var app = builder.Build();
WebApplication app = builder.Build();

if (!app.Environment.IsDevelopment())
{
Expand All @@ -48,4 +51,4 @@ public static void Main(string[] args)
app.Run();
}
}
}
}
5 changes: 4 additions & 1 deletion examples/BlazorServerApp/UserAgentContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace BlazorServerApp
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT license.

namespace BlazorServerApp
{
public class UserAgentContext
{
Expand Down
6 changes: 3 additions & 3 deletions examples/ConsoleApp/AccountServiceContext.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT license.
//

class AccountServiceContext : IAccountContext
{
public string AccountId { get; set; }
}
}
4 changes: 2 additions & 2 deletions examples/ConsoleApp/FeatureFilters/AccountIdFilter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT license.
//

using Microsoft.Extensions.Configuration;
using Microsoft.FeatureManagement;

Expand Down
4 changes: 2 additions & 2 deletions examples/ConsoleApp/FeatureFilters/IAccountContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT license.
//

public interface IAccountContext
{
string AccountId { get; }
Expand Down
9 changes: 6 additions & 3 deletions examples/ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.Extensions.Configuration;
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT license.

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.FeatureManagement;

Expand Down Expand Up @@ -31,7 +34,7 @@

//
// Mimic work items in a task-driven console application
foreach (var account in accounts)
foreach (string account in accounts)
{
const string FeatureName = "Beta";

Expand All @@ -49,4 +52,4 @@
// Output results
Console.WriteLine($"The {FeatureName} feature is {(enabled ? "enabled" : "disabled")} for the '{account}' account.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Licensed under the MIT license.
//

using Microsoft.AspNetCore.Authentication;

namespace FeatureFlagDemo.Authentication
Expand Down
Loading