Skip to content
Merged
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
152 changes: 152 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
###############################
# Core EditorConfig Options #
###############################
# All files
[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.{cs,cshtml,htm,html,md,py,sln,xml}]
indent_size = 4

###############################
# .NET Coding Conventions #
###############################
# Directive order based on dotnet/runtime settings
# https://github.com/dotnet/runtime/blob/main/.editorconfig
[*.cs]
# 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_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left

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

# this. preferences
dotnet_style_qualification_for_field = true:suggestion
dotnet_style_qualification_for_property = true:suggestion
dotnet_style_qualification_for_method = true:suggestion
dotnet_style_qualification_for_event = true:suggestion

# var preferences, language keywords vs BCL types preferences
csharp_style_var_for_built_in_types = true:silent
csharp_style_var_when_type_is_apparent = true:silent
csharp_style_var_elsewhere = true:silent
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent

# name all constant fields using PascalCase
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.required_modifiers = const
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# Code style defaults
dotnet_sort_system_directives_first = true
csharp_prefer_braces = true:silent
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
csharp_prefer_simple_using_statement = true:suggestion
dotnet_style_readonly_field = true:suggestion
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_object_initializer = true:suggestion

# Expression-level preferences
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:silent
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
csharp_prefer_simple_default_expression = true:suggestion

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

# Pattern matching
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

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

# Other features
csharp_style_prefer_index_operator = false:none
csharp_style_prefer_range_operator = false:none
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion

# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_around_binary_operators = before_and_after
csharp_space_before_colon_in_inheritance_clause = true
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_parameter_list_parentheses = false
csharp_space_between_parentheses = false

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

# Code analyzers
# CA1031: Do not catch general exception types
dotnet_diagnostic.CA1031.severity = none

# CA1303: Do not pass literals as localized parameters
dotnet_diagnostic.CA1303.severity = none

# IDE0001: Simplify name
dotnet_diagnostic.IDE0001.severity = warning

# IDE0002: Simplify member access
dotnet_diagnostic.IDE0002.severity = warning

# IDE0005: Remove unnecessary import
dotnet_diagnostic.IDE0005.severity = warning

# RS0041: Public members should not use oblivious types
dotnet_diagnostic.RS0041.severity = suggestion

[obj/**.cs]
generated_code = true

[*.csproj]
indent_size = 2
32 changes: 32 additions & 0 deletions .github/workflows/dotnet-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: dotnet format

on:
push:
branches: [ main ]
paths:
- '**.cs'
- '.editorconfig'
pull_request:
branches: [ main ]
paths:
- '**.cs'
- '.editorconfig'

jobs:
check-format:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Setup .NET Core 6.0
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x

- name: Install format tool
run: dotnet tool install -g dotnet-format

- name: dotnet format
run: dotnet-format --folder --check
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"rollForward": "latestFeature",
"version": "6.0.100"
}
}
4 changes: 2 additions & 2 deletions src/OpenFeature/Constant/Error.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OpenFeature.Constant
namespace OpenFeature.Constant
{
// TODO Probably should make this a enum
public static class Error
Expand All @@ -9,4 +9,4 @@ public static class Error
public static string TypeMismatch = "TYPE_MISMATCH";
public static string GeneralError = "GENERAL";
}
}
}
4 changes: 2 additions & 2 deletions src/OpenFeature/Constant/FlagValueType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OpenFeature.Constant
namespace OpenFeature.Constant
{
public enum FlagValueType
{
Expand All @@ -7,4 +7,4 @@ public enum FlagValueType
Number,
Object
}
}
}
4 changes: 2 additions & 2 deletions src/OpenFeature/Constant/NoOpProvider.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace OpenFeature.Constant
namespace OpenFeature.Constant
{
public static class NoOpProvider
{
public const string NoOpProviderName = "No-op Provider";
public const string ReasonNoOp = "No-op";
}
}
}
4 changes: 2 additions & 2 deletions src/OpenFeature/Constant/Reason.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OpenFeature.Constant
namespace OpenFeature.Constant
{
// TODO Probably should make this a enum
public static class Reason
Expand All @@ -10,4 +10,4 @@ public static class Reason
public static string Unknown = "UNKNOWN";
public static string Error = "ERROR";
}
}
}
4 changes: 2 additions & 2 deletions src/OpenFeature/Extension/ResolutionDetailsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using OpenFeature.Model;
using OpenFeature.Model;

namespace OpenFeature.Extention
{
Expand All @@ -9,4 +9,4 @@ public static FlagEvaluationDetails<T> ToFlagEvaluationDetails<T>(this Resolutio
return new FlagEvaluationDetails<T>(details.FlagKey, details.Value, details.ErrorCode, details.Reason, details.Variant);
}
}
}
}
8 changes: 4 additions & 4 deletions src/OpenFeature/Hook.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.Threading.Tasks;

Expand All @@ -11,14 +11,14 @@ internal interface IHook
Task Error<T>(HookContext<T> context, Exception error, IReadOnlyDictionary<string, object> hints = null);
Task Finally<T>(HookContext<T> context, IReadOnlyDictionary<string, object> hints = null);
}

/// <summary>
/// The Hook abstract class describes the default implementation for a hook.
///
/// More information about the lifecycle of the flag evaluation process can be found here
/// https://github.com/open-feature/spec/blob/main/specification/hooks.md
/// </summary>
public abstract class Hook : IHook
public abstract class Hook : IHook
{
public virtual Task<EvaluationContext> Before<T>(HookContext<T> context, IReadOnlyDictionary<string, object> hints = null)
{
Expand All @@ -40,4 +40,4 @@ public virtual Task Finally<T>(HookContext<T> context, IReadOnlyDictionary<strin
return Task.CompletedTask;
}
}
}
}
10 changes: 5 additions & 5 deletions src/OpenFeature/IFeatureClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using OpenFeature.Model;

Expand All @@ -15,17 +15,17 @@ public interface IFeatureClient
{
void AddHooks(IEnumerable<Hook> hooks);
ClientMetadata GetMetadata();

Task<bool> GetBooleanValue(string flagKey, bool defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null);
Task<FlagEvaluationDetails<bool>> GetBooleanDetails(string flagKey, bool defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null);

Task<string> GetStringValue(string flagKey, string defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null);
Task<FlagEvaluationDetails<string>> GetStringDetails(string flagKey, string defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null);

Task<int> GetNumberValue(string flagKey, int defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null);
Task<FlagEvaluationDetails<int>> GetNumberDetails(string flagKey, int defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null);

Task<T> GetObjectValue<T>(string flagKey, T defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null);
Task<FlagEvaluationDetails<T>> GetObjectDetails<T>(string flagKey, T defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null);
}
}
}
6 changes: 3 additions & 3 deletions src/OpenFeature/IFeatureProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Threading.Tasks;
using System.Threading.Tasks;
using OpenFeature.Model;

namespace OpenFeature
Expand All @@ -8,7 +8,7 @@ namespace OpenFeature
/// A provider acts as the translates layer between the generic feature flag structure to a target feature flag system.
///
/// More information about the provider interface can be found here:
/// https://github.com/open-feature/spec/blob/main/specification/providers.md
/// https://github.com/open-feature/spec/blob/main/specification/providers.md
/// </summary>
public interface IFeatureProvider
{
Expand All @@ -18,4 +18,4 @@ public interface IFeatureProvider
Task<ResolutionDetails<int>> ResolveNumberValue(string flagKey, int defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null);
Task<ResolutionDetails<T>> ResolveStructureValue<T>(string flagKey, T defaultValue, EvaluationContext context = null, FlagEvaluationOptions config = null);
}
}
}
6 changes: 3 additions & 3 deletions src/OpenFeature/Model/ClientMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace OpenFeature.Model
namespace OpenFeature.Model
{
public class ClientMetadata : Metadata
{
public string Version { get; }

public ClientMetadata(string name, string version) : base(name)
{
Version = version;
}
}
}
}
12 changes: 6 additions & 6 deletions src/OpenFeature/Model/EvaluationContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections;
using System.Collections;
using System.Collections.Generic;

namespace OpenFeature.Model
Expand All @@ -11,17 +11,17 @@ public void Add<T>(string key, T value)
{
_internalContext.Add(key, value);
}

public void Remove(string key)
{
_internalContext.Remove(key);
}

public T Get<T>(string key)
{
return (T)_internalContext[key];
}

public object this[string key]
{
get => _internalContext[key];
Expand All @@ -42,7 +42,7 @@ public void Merge(EvaluationContext other)
}
}
}

public int Count => _internalContext.Count;

public IEnumerator<object> GetEnumerator()
Expand All @@ -55,4 +55,4 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}
}
}
}
Loading