Skip to content

Commit

Permalink
chore: put an autoformatter in (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
sighphyre authored Jul 9, 2024
1 parent 246fb54 commit aa4b83a
Show file tree
Hide file tree
Showing 38 changed files with 137 additions and 114 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

name: Pull request

# Controls when the action will run.
# Controls when the action will run.
on:
push:
pull_request:
Expand All @@ -22,20 +22,28 @@ jobs:
# Set up MSBuild in PATH for command
- name: Setup MSBuild in PATH
uses: microsoft/setup-msbuild@v1

- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'

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

- name: Verify formatting
run: dotnet format --verify-no-changes
env:
PATH: ${{ github.env.PATH }}:/home/runner/.dotnet/tools

# Get NuGet setup for restoring, packaging and pushing
- name: Setup NuGet
uses: NuGet/[email protected]

- name: Restore packages with NuGet
run: nuget restore Unleash.sln

- name: Build the solution
run: msbuild Unleash.sln /p:Configuration=Release

- name: Run tests
run: dotnet test tests/Unleash.Tests/Unleash.Tests.csproj --no-restore --verbosity normal
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ var settings = new UnleashSettings()
### HttpMessageHandlers/Custom HttpClient initialization
If you need to specify HttpMessageHandlers or to control the instantiation of the HttpClient, you can create a custom
HttpClientFactory that inherits from DefaultHttpClientFactory, and override the method CreateHttpClientInstance.
Then configure UnleashSettings to use your custom HttpClientFactory.
Then configure UnleashSettings to use your custom HttpClientFactory.

```csharp
internal class CustomHttpClientFactory : DefaultHttpClientFactory
Expand All @@ -332,7 +332,7 @@ var settings = new UnleashSettings
```

### Dynamic custom HTTP headers
If you need custom http headers that change during the lifetime of the client, a provider can be defined via the `UnleashSettings`.
If you need custom http headers that change during the lifetime of the client, a provider can be defined via the `UnleashSettings`.

```vb
Public Class CustomHttpHeaderProvider
Expand All @@ -354,7 +354,7 @@ unleashSettings.UnleashCustomHttpHeaderProvider = New CustomHttpHeaderProvider()
unleashSettings.UnleashApi = new Uri("http://unleash.herokuapp.com/api/")
unleashSettings.UnleashContextProvider = New AspNetContextProvider()
Dim unleash = New DefaultUnleash(unleashSettings)

```

## Logging
Expand Down Expand Up @@ -519,7 +519,7 @@ public class NewtonsoftJson7Serializer : IJsonSerializer
using (var jsonWriter = new JsonTextWriter(writer))
{
Serializer.Serialize(jsonWriter, instance);

jsonWriter.Flush();
stream.Position = 0;
}
Expand Down Expand Up @@ -560,6 +560,12 @@ Tests live in `./tests/Unleash.Tests`
- Build: `dotnet build`
- Test: `dotnet test` - This also executes spec tests

## Formatting

We enforce formatting with `dotnet format`. This can be installed using the following command:

`dotnet tool install -g dotnet-format`.

### Release process
- Draft a new release in releases, target `main`
- Choose a new version (ie `4.1.9` without `v`)
Expand Down
4 changes: 2 additions & 2 deletions src/Unleash/ClientFactory/UnleashClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Unleash.ClientFactory
/// <inheritdoc />
public class UnleashClientFactory : IUnleashClientFactory
{
private static readonly TaskFactory TaskFactory =
private static readonly TaskFactory TaskFactory =
new TaskFactory(CancellationToken.None,
TaskCreationOptions.None,
TaskContinuationOptions.None,
Expand All @@ -30,7 +30,7 @@ public IUnleash CreateClient(UnleashSettings settings, bool synchronousInitializ
.Unwrap()
.GetAwaiter()
.GetResult();

return unleash;
}
return new DefaultUnleash(settings, strategies);
Expand Down
6 changes: 3 additions & 3 deletions src/Unleash/Communication/UnleashApiClientRequestHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace Unleash.Communication
{
internal class UnleashApiClientRequestHeaders
{
public string AppName { get; set; }
public string InstanceId { get; set; }
public Dictionary<string,string> CustomHttpHeaders { get; set; }
public string AppName { get; set; }
public string InstanceId { get; set; }
public Dictionary<string, string> CustomHttpHeaders { get; set; }
public IUnleashCustomHttpHeaderProvider CustomHttpHeaderProvider { get; set; }
public string SupportedSpecVersion { get; internal set; }
}
Expand Down
13 changes: 8 additions & 5 deletions src/Unleash/DefaultUnleash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public DefaultUnleash(UnleashSettings settings, bool overrideDefaultStrategies,

services = new UnleashServices(settings, EventConfig, strategyMap);

Logger.Info(() => $"UNLEASH: Unleash instance number { currentInstanceNo } is initialized and configured with: {settings}");
Logger.Info(() => $"UNLEASH: Unleash instance number {currentInstanceNo} is initialized and configured with: {settings}");

if (currentInstanceNo >= ErrorOnInstanceCount)
{
Expand Down Expand Up @@ -121,7 +121,8 @@ private FeatureEvaluationResult CheckIsEnabled(
var enhancedContext = context.ApplyStaticFields(settings);
var enabled = DetermineIsEnabledAndStrategy(toggleName, featureToggle, enhancedContext, defaultSetting, out var strategy);
var variant = DetermineVariant(enabled, featureToggle, strategy, enhancedContext, defaultVariant);
if (variant != null) {
if (variant != null)
{
variant.FeatureEnabled = enabled;
}

Expand Down Expand Up @@ -190,15 +191,17 @@ private bool DependenciesSatisfied(FeatureToggle featureToggle, Dependency depen
return false;
}

if (parentToggle.Dependencies.Any()) {
if (parentToggle.Dependencies.Any())
{
return false;
}

if (dependency.Enabled) {
if (dependency.Enabled)
{
if (dependency.Variants != null && dependency.Variants.Any())
{
var checkResult = CheckIsEnabled(dependency.Feature, context, false, Variant.DISABLED_VARIANT);
return checkResult.Enabled && dependency.Variants.Contains(checkResult.Variant.Name);
return checkResult.Enabled && dependency.Variants.Contains(checkResult.Variant.Name);
}
return CheckIsEnabled(dependency.Feature, context, false).Enabled;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Unleash/IUnleashCustomHttpHeaderProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Unleash
{
public interface IUnleashCustomHttpHeaderProvider
{
Dictionary<string, string> CustomHeaders { get; }
Dictionary<string, string> CustomHeaders { get; }
}
}
6 changes: 4 additions & 2 deletions src/Unleash/Internal/Dependency.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Unleash.Internal {
public class Dependency {
namespace Unleash.Internal
{
public class Dependency
{
/// <summary>
/// Feature is the name of the feature toggle we depend upon
/// </summary>
Expand Down
7 changes: 4 additions & 3 deletions src/Unleash/Internal/ToggleCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public ToggleCollection(ICollection<FeatureToggle> features = null, ICollection<
togglesCache = new Dictionary<string, FeatureToggle>(Features.Count);
segmentsCache = new Dictionary<int, Segment>(Segments.Count);

foreach (var featureToggle in Features) {
foreach (var featureToggle in Features)
{
togglesCache.Add(featureToggle.Name, featureToggle);
}

Expand All @@ -42,8 +43,8 @@ public ToggleCollection(ICollection<FeatureToggle> features = null, ICollection<

public FeatureToggle GetToggleByName(string name)
{
return togglesCache.TryGetValue(name, out var value)
? value
return togglesCache.TryGetValue(name, out var value)
? value
: null;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Unleash/Internal/UnleashServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public UnleashServices(UnleashSettings settings, EventCallbackConfig eventConfig
IsMetricsDisabled = settings.SendMetricsInterval == null;

var fetchFeatureTogglesTask = new FetchFeatureTogglesTask(
apiClient,
apiClient,
ToggleCollection,
settings.JsonSerializer,
settings.JsonSerializer,
settings.FileSystem,
eventConfig,
backupFile,
backupFile,
etagBackupFile,
settings.ThrowOnInitialFetchFail)
{
Expand All @@ -101,7 +101,7 @@ public UnleashServices(UnleashSettings settings, EventCallbackConfig eventConfig
if (settings.SendMetricsInterval != null)
{
var clientRegistrationBackgroundTask = new ClientRegistrationBackgroundTask(
apiClient,
apiClient,
settings,
strategyMap.Select(pair => pair.Key).ToList())
{
Expand All @@ -112,8 +112,8 @@ public UnleashServices(UnleashSettings settings, EventCallbackConfig eventConfig
scheduledTasks.Add(clientRegistrationBackgroundTask);

var clientMetricsBackgroundTask = new ClientMetricsBackgroundTask(
apiClient,
settings,
apiClient,
settings,
MetricsBucket)
{
Interval = settings.SendMetricsInterval.Value
Expand Down
4 changes: 2 additions & 2 deletions src/Unleash/Metrics/MetricsBucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class ThreadSafeMetricsBucket : IDisposable

private readonly MetricsBucket metricsBucket;

private readonly ReaderWriterLockSlim @lock =
private readonly ReaderWriterLockSlim @lock =
new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);

public ThreadSafeMetricsBucket(MetricsBucket metricsBucket = null)
Expand Down Expand Up @@ -71,7 +71,7 @@ private void WithToggleCount(string toggleName, Action<ToggleCount> action)
public IDisposable StopCollectingMetrics(out MetricsBucket bucket)
{
@lock.EnterWriteLock();

bucket = metricsBucket;
bucket.Stop = DateTimeOffset.UtcNow;

Expand Down
2 changes: 1 addition & 1 deletion src/Unleash/Scheduling/ClientMetricsBackgroundTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class ClientMetricsBackgroundTask : IUnleashScheduledTask
private readonly ThreadSafeMetricsBucket metricsBucket;

public ClientMetricsBackgroundTask(
IUnleashApiClient apiClient,
IUnleashApiClient apiClient,
UnleashSettings settings,
ThreadSafeMetricsBucket metricsBucket)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Unleash/Scheduling/ClientRegistrationBackgroundTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ internal class ClientRegistrationBackgroundTask : IUnleashScheduledTask
private readonly List<string> strategies;

public ClientRegistrationBackgroundTask(
IUnleashApiClient apiClient,
UnleashSettings settings,
IUnleashApiClient apiClient,
UnleashSettings settings,
List<string> strategies)
{
this.apiClient = apiClient;
Expand Down
2 changes: 1 addition & 1 deletion src/Unleash/Serialization/JsonSerializerTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,5 @@ public static void Assert(IJsonSerializer serializer)
throw new UnleashException($"Wrong expected strategy parameters value (127.0.0.1): {errorMessage}");
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/Unleash/Strategies/StrategyUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static int GetNormalizedNumber(string identifier, string groupId, uint ra
/// <param name="percentage">A numeric string value</param>
public static int GetPercentage(string percentage)
{
var p = int.TryParse(percentage, out var result)
? result
var p = int.TryParse(percentage, out var result)
? result
: 0;

// Ensure between 0 and 100.
Expand Down
18 changes: 9 additions & 9 deletions src/Unleash/UnleashSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class UnleashSettings

/// <summary>
/// Gets or set the uri for the backend unleash server.
///
///
/// Default: http://unleash.herokuapp.com/api/
/// </summary>
public Uri UnleashApi { get; set; } = new Uri("http://unleash.herokuapp.com/api/");
Expand All @@ -57,21 +57,21 @@ public class UnleashSettings

/// <summary>
/// Gets or sets the interval in which feature toggle changes are re-fetched.
///
///
/// Default: 30 seconds
/// </summary>
public TimeSpan FetchTogglesInterval { get; set; } = TimeSpan.FromSeconds(30);

/// <summary>
/// Gets or sets the interval in which metrics are sent to the server. When null, no metrics are sent.
///
///
/// Default: 60s
/// </summary>
public TimeSpan? SendMetricsInterval { get; set; } = TimeSpan.FromSeconds(60);

/// <summary>
/// Gets or set a directory for storing temporary files (toggles and current etag values).
///
/// Gets or set a directory for storing temporary files (toggles and current etag values).
///
/// Default: Path.GetTempPath()
/// </summary>
public Func<string> LocalStorageFolder { get; set; } = Path.GetTempPath;
Expand All @@ -89,16 +89,16 @@ public class UnleashSettings
public IUnleashCustomHttpHeaderProvider UnleashCustomHttpHeaderProvider { get; set; } = new DefaultCustomHttpHeaderProvider();

/// <summary>
/// Gets or sets the unleash context provider. This is needed when using any of the activation strategies
/// Gets or sets the unleash context provider. This is needed when using any of the activation strategies
/// that needs application specific context like userid etc.
///
///
/// Default: A provider with no context.
/// </summary>
public IUnleashContextProvider UnleashContextProvider { get; set; } = new DefaultUnleashContextProvider();

/// <summary>
/// Gets or sets a json serializer.
///
/// Gets or sets a json serializer.
///
/// Default: A serializer based on Newtonsoft will be used, given that these assemblies are loaded into the appdomain already.
/// </summary>
public IJsonSerializer JsonSerializer { get; set; } = new DynamicNewtonsoftJsonSerializer();
Expand Down
10 changes: 5 additions & 5 deletions tests/Unleash.Tests/Communication/BaseBackoffTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal UnleashApiClient GetClient(HttpMessageHandler messageHandler)
/// <summary>
/// 200 OK
/// </summary>
protected static HttpResponseMessage Ok =>
protected static HttpResponseMessage Ok =>
new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Expand All @@ -50,13 +50,13 @@ internal UnleashApiClient GetClient(HttpMessageHandler messageHandler)
/// <summary>
/// 304 Not Modified
/// </summary>
protected static HttpResponseMessage NotModified =>
protected static HttpResponseMessage NotModified =>
new HttpResponseMessage
{
StatusCode = HttpStatusCode.NotModified,
Content = new StringContent("{}")
};

/// <summary>
/// 401 Unauthorized
/// </summary>
Expand Down Expand Up @@ -90,13 +90,13 @@ internal UnleashApiClient GetClient(HttpMessageHandler messageHandler)
/// <summary>
/// 429 Too Many Requests
/// </summary>
protected static HttpResponseMessage TooManyRequests =>
protected static HttpResponseMessage TooManyRequests =>
new HttpResponseMessage
{
StatusCode = HttpStatusCode.TooManyRequests,
Content = new StringContent("")
};

/// <summary>
/// 500 Internal Server Error
/// </summary>
Expand Down
Loading

0 comments on commit aa4b83a

Please sign in to comment.