Skip to content

Commit 1e74a04

Browse files
authored
chore: Change file scoped namespaces and cleanup job (#453)
<!-- Please use this template for your pull request. --> <!-- Please use the sections that you need and delete other sections --> ## This PR <!-- add the description of the PR here --> This pull request introduces a significant refactor to the codebase by converting all namespace declarations to file-scoped namespaces and updating the `.editorconfig` to enforce this style. Additionally, it simplifies the structure of multiple files by removing unnecessary closing braces for namespace blocks. ### Namespace Refactoring: * Converted all namespace declarations in the `src/OpenFeature` directory to file-scoped namespaces for consistency and improved readability. This change affects multiple files, including `Api.cs`, `Constants.cs`, `Error/*.cs`, `EventExecutor.cs`, and `Extension/*.cs`. [[1]](diffhunk://#diff-dc150fbd3b7be797470374ee7e38c7ab8a31eb9b6b7a52345e05114c2d32a15eL12-R13) [[2]](diffhunk://#diff-b0112a803c4d4783b4b829626b4970801bda0de261d9887d3d5f5de30eb49d4fL1-L9) [[3]](diffhunk://#diff-08c95bef1c40daf926c6da5657e9333d4481a1e76b03c8749b87e58d9c711af3L3-R4) [[4]](diffhunk://#diff-95f94f0d86864094b6a4ed191b7a08bc306c6b2f21eb061b7de319aa9fa19e3fL1-R2) [[5]](diffhunk://#diff-591e2f16844f704f064cbe31b7427e66c6f816f421a970fc7ad6fe1ad3c4c220L1-R2)R1, [[6]](diffhunk://#diff-04e7c0ae5d31a3d10742b06dd413c512ee002ce27ce7b3b39cca79598c381a68L3-R4) [[7]](diffhunk://#diff-0c85dcfcfa3c97d37ee0ba4394ca6958a14c013ee0940aaea09cefd2686bf41fL1-R2) [[8]](diffhunk://#diff-a7a382f3d0da52015d1b9e03802692a86c61e7b57580747f31fae37d8dcc5cd6L4-R5) [[9]](diffhunk://#diff-b9fdde9b61e62d7c474069ea5fc2a43d123ab86d93cb9a6d0673254a64536722L5-R6) [[10]](diffhunk://#diff-bb4aadb03ea44e3b6b74b83f12b2b1a258e13836bcf815f996addcd5537a478fL5-R6) [[11]](diffhunk://#diff-89efe60a8b640cc303a38e5b01bc27ad40599e364ff2654a57b7e42138056cdaL5-R6) [[12]](diffhunk://#diff-7a8cbfba7673f1b69d3d927f60eb4ab0aa548403a118fad9eb43b9a22875dc02L5-R6) [[13]](diffhunk://#diff-48ae8447bc31a75ecf4bba768a7b68244fbbc9dd5480db9114d9c74fb10fe2efL5-R6) [[14]](diffhunk://#diff-9a3b5bf7bf3351a6161fc6dd75830bfbaab7aca730cf3f0ae6cd120a76b2f1b1L5-R6) [[15]](diffhunk://#diff-c4388b2e7252e2e3ac0967dbfdd4647a924cdfc54da229667a0db3613b243a7eL5-R6) [[16]](diffhunk://#diff-44c88ae43caf99ee733ec911fa85454a96c57d07fc57d2fadd44e12cd7d31cd4L5-R6) [[17]](diffhunk://#diff-f563baadcf750bb66efaea76d7ec4783320e6efdc45c468effb531c948a2292cL10-R11) [[18]](diffhunk://#diff-f94bf65f426e13a14f798a8db21a5c9dd3306f5941bde1aba79af3e41421bfc0L5-R6) [[19]](diffhunk://#diff-484832cfacaa02b6872a26cf5202843e96e0125281deca5798974879d9d609a0L3-R4) ### Code Style Enforcement: * Updated `.editorconfig` to include a new rule (`csharp_style_namespace_declarations = file_scoped:warning`) to enforce the use of file-scoped namespaces. ### Simplification of Code Structure: * Removed unnecessary closing braces for namespace blocks in all affected files, as they are no longer required with file-scoped namespaces. This change simplifies the code and reduces visual clutter. [[1]](diffhunk://#diff-dc150fbd3b7be797470374ee7e38c7ab8a31eb9b6b7a52345e05114c2d32a15eL369) [[2]](diffhunk://#diff-b0112a803c4d4783b4b829626b4970801bda0de261d9887d3d5f5de30eb49d4fL1-L9) [[3]](diffhunk://#diff-08c95bef1c40daf926c6da5657e9333d4481a1e76b03c8749b87e58d9c711af3L56) [[4]](diffhunk://#diff-95f94f0d86864094b6a4ed191b7a08bc306c6b2f21eb061b7de319aa9fa19e3fL25) [[5]](diffhunk://#diff-591e2f16844f704f064cbe31b7427e66c6f816f421a970fc7ad6fe1ad3c4c220L28) [[6]](diffhunk://#diff-04e7c0ae5d31a3d10742b06dd413c512ee002ce27ce7b3b39cca79598c381a68L36) [[7]](diffhunk://#diff-0c85dcfcfa3c97d37ee0ba4394ca6958a14c013ee0940aaea09cefd2686bf41fL50) [[8]](diffhunk://#diff-a7a382f3d0da52015d1b9e03802692a86c61e7b57580747f31fae37d8dcc5cd6L29) [[9]](diffhunk://#diff-b9fdde9b61e62d7c474069ea5fc2a43d123ab86d93cb9a6d0673254a64536722L23) [[10]](diffhunk://#diff-bb4aadb03ea44e3b6b74b83f12b2b1a258e13836bcf815f996addcd5537a478fL23) [[11]](diffhunk://#diff-89efe60a8b640cc303a38e5b01bc27ad40599e364ff2654a57b7e42138056cdaL23) [[12]](diffhunk://#diff-7a8cbfba7673f1b69d3d927f60eb4ab0aa548403a118fad9eb43b9a22875dc02L23) [[13]](diffhunk://#diff-48ae8447bc31a75ecf4bba768a7b68244fbbc9dd5480db9114d9c74fb10fe2efL23) [[14]](diffhunk://#diff-9a3b5bf7bf3351a6161fc6dd75830bfbaab7aca730cf3f0ae6cd120a76b2f1b1L23) [[15]](diffhunk://#diff-c4388b2e7252e2e3ac0967dbfdd4647a924cdfc54da229667a0db3613b243a7eL23) [[16]](diffhunk://#diff-44c88ae43caf99ee733ec911fa85454a96c57d07fc57d2fadd44e12cd7d31cd4L23) [[17]](diffhunk://#diff-f563baadcf750bb66efaea76d7ec4783320e6efdc45c468effb531c948a2292cL356) [[18]](diffhunk://#diff-f94bf65f426e13a14f798a8db21a5c9dd3306f5941bde1aba79af3e41421bfc0L16) [[19]](diffhunk://#diff-484832cfacaa02b6872a26cf5202843e96e0125281deca5798974879d9d609a0L13) ### Related Issues <!-- add here the GitHub issue that this PR resolves if applicable --> Fixes #447 ### Notes <!-- any additional notes for this PR --> I ran the `dotnet format OpenFeature.sln` to clean up the code. As you can imagine, this generates a big diff. I would advise enabling `Hide Whitespace` to review this PR, since it will show the conversion from nested to file namespaces. --------- Signed-off-by: André Silva <[email protected]>
1 parent 4795685 commit 1e74a04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+7378
-7437
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ dotnet_diagnostic.RS0041.severity = suggestion
148148
# CA2007: Do not directly await a Task
149149
dotnet_diagnostic.CA2007.severity = error
150150

151+
# IDE0161: Convert to file-scoped namespace
152+
csharp_style_namespace_declarations = file_scoped:warning
153+
151154
[obj/**.cs]
152155
generated_code = true
153156

src/OpenFeature/Api.cs

Lines changed: 306 additions & 307 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
namespace OpenFeature.Constant
1+
namespace OpenFeature.Constant;
2+
3+
internal static class NoOpProvider
24
{
3-
internal static class NoOpProvider
4-
{
5-
public const string NoOpProviderName = "No-op Provider";
6-
public const string ReasonNoOp = "No-op";
7-
public const string Variant = "No-op";
8-
}
5+
public const string NoOpProviderName = "No-op Provider";
6+
public const string ReasonNoOp = "No-op";
7+
public const string Variant = "No-op";
98
}
Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,55 @@
11
using System.ComponentModel;
22

3-
namespace OpenFeature.Constant
3+
namespace OpenFeature.Constant;
4+
5+
/// <summary>
6+
/// These errors are used to indicate abnormal execution when evaluation a flag
7+
/// </summary>
8+
/// <seealso href="https://github.com/open-feature/spec/blob/v0.5.2/specification/sections/02-providers.md#requirement-227"/>
9+
public enum ErrorType
410
{
511
/// <summary>
6-
/// These errors are used to indicate abnormal execution when evaluation a flag
7-
/// </summary>
8-
/// <seealso href="https://github.com/open-feature/spec/blob/v0.5.2/specification/sections/02-providers.md#requirement-227"/>
9-
public enum ErrorType
10-
{
11-
/// <summary>
12-
/// Default value, no error occured
13-
/// </summary>
14-
None,
15-
16-
/// <summary>
17-
/// Provider has yet been initialized
18-
/// </summary>
19-
[Description("PROVIDER_NOT_READY")] ProviderNotReady,
20-
21-
/// <summary>
22-
/// Provider was unable to find the flag
23-
/// </summary>
24-
[Description("FLAG_NOT_FOUND")] FlagNotFound,
25-
26-
/// <summary>
27-
/// Provider failed to parse the flag response
28-
/// </summary>
29-
[Description("PARSE_ERROR")] ParseError,
30-
31-
/// <summary>
32-
/// Request type does not match the expected type
33-
/// </summary>
34-
[Description("TYPE_MISMATCH")] TypeMismatch,
35-
36-
/// <summary>
37-
/// Abnormal execution of the provider
38-
/// </summary>
39-
[Description("GENERAL")] General,
40-
41-
/// <summary>
42-
/// Context does not satisfy provider requirements.
43-
/// </summary>
44-
[Description("INVALID_CONTEXT")] InvalidContext,
45-
46-
/// <summary>
47-
/// Context does not contain a targeting key and the provider requires one.
48-
/// </summary>
49-
[Description("TARGETING_KEY_MISSING")] TargetingKeyMissing,
50-
51-
/// <summary>
52-
/// The provider has entered an irrecoverable error state.
53-
/// </summary>
54-
[Description("PROVIDER_FATAL")] ProviderFatal,
55-
}
12+
/// Default value, no error occured
13+
/// </summary>
14+
None,
15+
16+
/// <summary>
17+
/// Provider has yet been initialized
18+
/// </summary>
19+
[Description("PROVIDER_NOT_READY")] ProviderNotReady,
20+
21+
/// <summary>
22+
/// Provider was unable to find the flag
23+
/// </summary>
24+
[Description("FLAG_NOT_FOUND")] FlagNotFound,
25+
26+
/// <summary>
27+
/// Provider failed to parse the flag response
28+
/// </summary>
29+
[Description("PARSE_ERROR")] ParseError,
30+
31+
/// <summary>
32+
/// Request type does not match the expected type
33+
/// </summary>
34+
[Description("TYPE_MISMATCH")] TypeMismatch,
35+
36+
/// <summary>
37+
/// Abnormal execution of the provider
38+
/// </summary>
39+
[Description("GENERAL")] General,
40+
41+
/// <summary>
42+
/// Context does not satisfy provider requirements.
43+
/// </summary>
44+
[Description("INVALID_CONTEXT")] InvalidContext,
45+
46+
/// <summary>
47+
/// Context does not contain a targeting key and the provider requires one.
48+
/// </summary>
49+
[Description("TARGETING_KEY_MISSING")] TargetingKeyMissing,
50+
51+
/// <summary>
52+
/// The provider has entered an irrecoverable error state.
53+
/// </summary>
54+
[Description("PROVIDER_FATAL")] ProviderFatal,
5655
}
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
namespace OpenFeature.Constant
1+
namespace OpenFeature.Constant;
2+
3+
/// <summary>
4+
/// The ProviderEventTypes enum represents the available event types of a provider.
5+
/// </summary>
6+
public enum ProviderEventTypes
27
{
38
/// <summary>
4-
/// The ProviderEventTypes enum represents the available event types of a provider.
9+
/// ProviderReady should be emitted by a provider upon completing its initialisation.
510
/// </summary>
6-
public enum ProviderEventTypes
7-
{
8-
/// <summary>
9-
/// ProviderReady should be emitted by a provider upon completing its initialisation.
10-
/// </summary>
11-
ProviderReady,
12-
/// <summary>
13-
/// ProviderError should be emitted by a provider upon encountering an error.
14-
/// </summary>
15-
ProviderError,
16-
/// <summary>
17-
/// ProviderConfigurationChanged should be emitted by a provider when a flag configuration has been changed.
18-
/// </summary>
19-
ProviderConfigurationChanged,
20-
/// <summary>
21-
/// ProviderStale should be emitted by a provider when it goes into the stale state.
22-
/// </summary>
23-
ProviderStale
24-
}
11+
ProviderReady,
12+
/// <summary>
13+
/// ProviderError should be emitted by a provider upon encountering an error.
14+
/// </summary>
15+
ProviderError,
16+
/// <summary>
17+
/// ProviderConfigurationChanged should be emitted by a provider when a flag configuration has been changed.
18+
/// </summary>
19+
ProviderConfigurationChanged,
20+
/// <summary>
21+
/// ProviderStale should be emitted by a provider when it goes into the stale state.
22+
/// </summary>
23+
ProviderStale
2524
}
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
namespace OpenFeature.Constant
1+
namespace OpenFeature.Constant;
2+
3+
/// <summary>
4+
/// Used to identity what object type of flag being evaluated
5+
/// </summary>
6+
public enum FlagValueType
27
{
38
/// <summary>
4-
/// Used to identity what object type of flag being evaluated
9+
/// Flag is a boolean value
510
/// </summary>
6-
public enum FlagValueType
7-
{
8-
/// <summary>
9-
/// Flag is a boolean value
10-
/// </summary>
11-
Boolean,
11+
Boolean,
1212

13-
/// <summary>
14-
/// Flag is a string value
15-
/// </summary>
16-
String,
13+
/// <summary>
14+
/// Flag is a string value
15+
/// </summary>
16+
String,
1717

18-
/// <summary>
19-
/// Flag is a numeric value
20-
/// </summary>
21-
Number,
18+
/// <summary>
19+
/// Flag is a numeric value
20+
/// </summary>
21+
Number,
2222

23-
/// <summary>
24-
/// Flag is a structured value
25-
/// </summary>
26-
Object
27-
}
23+
/// <summary>
24+
/// Flag is a structured value
25+
/// </summary>
26+
Object
2827
}
Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
using System.ComponentModel;
22

3-
namespace OpenFeature.Constant
3+
namespace OpenFeature.Constant;
4+
5+
/// <summary>
6+
/// The state of the provider.
7+
/// </summary>
8+
/// <seealso href="https://github.com/open-feature/spec/blob/main/specification/sections/02-providers.md#requirement-242" />
9+
public enum ProviderStatus
410
{
511
/// <summary>
6-
/// The state of the provider.
12+
/// The provider has not been initialized and cannot yet evaluate flags.
713
/// </summary>
8-
/// <seealso href="https://github.com/open-feature/spec/blob/main/specification/sections/02-providers.md#requirement-242" />
9-
public enum ProviderStatus
10-
{
11-
/// <summary>
12-
/// The provider has not been initialized and cannot yet evaluate flags.
13-
/// </summary>
14-
[Description("NOT_READY")] NotReady,
14+
[Description("NOT_READY")] NotReady,
1515

16-
/// <summary>
17-
/// The provider is ready to resolve flags.
18-
/// </summary>
19-
[Description("READY")] Ready,
16+
/// <summary>
17+
/// The provider is ready to resolve flags.
18+
/// </summary>
19+
[Description("READY")] Ready,
2020

21-
/// <summary>
22-
/// The provider's cached state is no longer valid and may not be up-to-date with the source of truth.
23-
/// </summary>
24-
[Description("STALE")] Stale,
21+
/// <summary>
22+
/// The provider's cached state is no longer valid and may not be up-to-date with the source of truth.
23+
/// </summary>
24+
[Description("STALE")] Stale,
2525

26-
/// <summary>
27-
/// The provider is in an error state and unable to evaluate flags.
28-
/// </summary>
29-
[Description("ERROR")] Error,
26+
/// <summary>
27+
/// The provider is in an error state and unable to evaluate flags.
28+
/// </summary>
29+
[Description("ERROR")] Error,
3030

31-
/// <summary>
32-
/// The provider has entered an irrecoverable error state.
33-
/// </summary>
34-
[Description("FATAL")] Fatal,
35-
}
31+
/// <summary>
32+
/// The provider has entered an irrecoverable error state.
33+
/// </summary>
34+
[Description("FATAL")] Fatal,
3635
}

src/OpenFeature/Constant/Reason.cs

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,49 @@
1-
namespace OpenFeature.Constant
1+
namespace OpenFeature.Constant;
2+
3+
/// <summary>
4+
/// Common reasons used during flag resolution
5+
/// </summary>
6+
/// <seealso href="https://github.com/open-feature/spec/blob/v0.5.2/specification/sections/02-providers.md#requirement-225">Reason Specification</seealso>
7+
public static class Reason
28
{
39
/// <summary>
4-
/// Common reasons used during flag resolution
5-
/// </summary>
6-
/// <seealso href="https://github.com/open-feature/spec/blob/v0.5.2/specification/sections/02-providers.md#requirement-225">Reason Specification</seealso>
7-
public static class Reason
8-
{
9-
/// <summary>
10-
/// Use when the flag is matched based on the evaluation context user data
11-
/// </summary>
12-
public const string TargetingMatch = "TARGETING_MATCH";
13-
14-
/// <summary>
15-
/// Use when the flag is matched based on a split rule in the feature flag provider
16-
/// </summary>
17-
public const string Split = "SPLIT";
18-
19-
/// <summary>
20-
/// Use when the flag is disabled in the feature flag provider
21-
/// </summary>
22-
public const string Disabled = "DISABLED";
23-
24-
/// <summary>
25-
/// Default reason when evaluating flag
26-
/// </summary>
27-
public const string Default = "DEFAULT";
28-
29-
/// <summary>
30-
/// The resolved value is static (no dynamic evaluation)
31-
/// </summary>
32-
public const string Static = "STATIC";
33-
34-
/// <summary>
35-
/// The resolved value was retrieved from cache
36-
/// </summary>
37-
public const string Cached = "CACHED";
38-
39-
/// <summary>
40-
/// Use when an unknown reason is encountered when evaluating flag.
41-
/// An example of this is if the feature provider returns a reason that is not defined in the spec
42-
/// </summary>
43-
public const string Unknown = "UNKNOWN";
44-
45-
/// <summary>
46-
/// Use this flag when abnormal execution is encountered.
47-
/// </summary>
48-
public const string Error = "ERROR";
49-
}
10+
/// Use when the flag is matched based on the evaluation context user data
11+
/// </summary>
12+
public const string TargetingMatch = "TARGETING_MATCH";
13+
14+
/// <summary>
15+
/// Use when the flag is matched based on a split rule in the feature flag provider
16+
/// </summary>
17+
public const string Split = "SPLIT";
18+
19+
/// <summary>
20+
/// Use when the flag is disabled in the feature flag provider
21+
/// </summary>
22+
public const string Disabled = "DISABLED";
23+
24+
/// <summary>
25+
/// Default reason when evaluating flag
26+
/// </summary>
27+
public const string Default = "DEFAULT";
28+
29+
/// <summary>
30+
/// The resolved value is static (no dynamic evaluation)
31+
/// </summary>
32+
public const string Static = "STATIC";
33+
34+
/// <summary>
35+
/// The resolved value was retrieved from cache
36+
/// </summary>
37+
public const string Cached = "CACHED";
38+
39+
/// <summary>
40+
/// Use when an unknown reason is encountered when evaluating flag.
41+
/// An example of this is if the feature provider returns a reason that is not defined in the spec
42+
/// </summary>
43+
public const string Unknown = "UNKNOWN";
44+
45+
/// <summary>
46+
/// Use this flag when abnormal execution is encountered.
47+
/// </summary>
48+
public const string Error = "ERROR";
5049
}

0 commit comments

Comments
 (0)