Skip to content

Commit

Permalink
Add more syntax checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Feb 13, 2024
1 parent 3edc3d8 commit 524154e
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 1 deletion.
39 changes: 39 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ dotnet_diagnostic.CA1305.severity = warning
# CA1507: Use nameof to express symbol names
dotnet_diagnostic.CA1507.severity = warning

# CA1708: Identifiers should differ by more than case
dotnet_diagnostic.CA1708.severity = warning

# CA1510: Use ArgumentNullException throw helper
dotnet_diagnostic.CA1510.severity = warning

Expand All @@ -157,6 +160,15 @@ dotnet_diagnostic.CA1512.severity = warning
# CA1513: Use ObjectDisposedException throw helper
dotnet_diagnostic.CA1513.severity = warning

# CA1715: Identifiers should have correct prefix
dotnet_diagnostic.CA1715.severity = warning

# CA1720: Identifiers should not contain type names
dotnet_diagnostic.CA1720.severity = warning

# CA1724: Type Names Should Not Match Namespaces
dotnet_diagnostic.CA1724.severity = warning

# CA1725: Parameter names should match base declaration
dotnet_diagnostic.CA1725.severity = warning

Expand Down Expand Up @@ -402,6 +414,33 @@ dotnet_diagnostic.CA1050.severity = warning
# CA1816: Call GC.SuppressFinalize correctly
dotnet_diagnostic.CA1816.severity = warning

# CA1801: Review unused parameters
dotnet_diagnostic.CA1801.severity = warning

# CA2200: Rethrow to preserve stack details
dotnet_diagnostic.CA2200.severity = warning

# CA2211: Non-constant fields should not be visible
dotnet_diagnostic.CA2211.severity = warning

# CA2213: Disposable fields should be disposed
dotnet_diagnostic.CA2213.severity = warning

# CA2214: Do not call overridable methods in constructors
dotnet_diagnostic.CA2214.severity = warning

# CA2215: Dispose methods should call base class dispose
dotnet_diagnostic.CA2215.severity = warning

# CA2216: Disposable types should declare finalizer
dotnet_diagnostic.CA2216.severity = warning

# CA2218: Override GetHashCode on overriding Equals
dotnet_diagnostic.CA2218.severity = warning

# CA2219: Do not raise exceptions in exception clauses
dotnet_diagnostic.CA2219.severity = warning

# NUnit2046 Use Has.Length/Has.Count/Is.Empty instead of testing property directly
dotnet_diagnostic.NUnit2046.severity = warning

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,11 @@ private async Task AuthorizeAsync(CancellationToken cancellationToken)
_authToken = refreshedToken;
_logger.LogInformation("ClearML Authentication Token Refresh Successful.");
}

public override void Dispose()
{
_httpClient.Dispose();
base.Dispose();
GC.SuppressFinalize(this);
}
}
1 change: 1 addition & 0 deletions src/SIL.Machine.AspNetCore/Services/InMemoryStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public Entry(Entry other)
protected override void Dispose(bool disposing)
{
_parent._memoryStreams[Path] = new Entry(this);
base.Dispose(disposing);
}

public override void Flush()
Expand Down
7 changes: 7 additions & 0 deletions src/SIL.Machine.AspNetCore/Services/S3FileStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ namespace SIL.Machine.AspNetCore.Services;

public class S3FileStorage : DisposableBase, IFileStorage
{
#pragma warning disable CA2213 // Disposed in DisposeManagedResources
private readonly AmazonS3Client _client;
#pragma warning restore CA2213
private readonly string _bucketName;
private readonly string _basePath;
private readonly ILoggerFactory _loggerFactory;
Expand Down Expand Up @@ -119,4 +121,9 @@ public async Task DeleteAsync(string path, bool recurse = false, CancellationTok
$"Received status code {response.HttpStatusCode} when attempting to delete {path}"
);
}

protected override void DisposeManagedResources()
{
_client?.Dispose();
}
}
2 changes: 2 additions & 0 deletions src/SIL.Machine.AspNetCore/Services/S3WriteStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ protected override void Dispose(bool disposing)
}
}
}
_client.Dispose();
base.Dispose(disposing);
}

Expand Down Expand Up @@ -189,6 +190,7 @@ public override async ValueTask DisposeAsync()
{
await AbortAsync(e);
}
await base.DisposeAsync();
}

private async Task AbortAsync(Exception? e = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ await _stateService.CommitAsync(
_logger.LogError(e, "Error occurred while committing SMT transfer engines.");
}
}

public override void Dispose()
{
_stateService.Dispose();
base.Dispose();
GC.SuppressFinalize(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ string engineId
private readonly ITruecaserFactory _truecaserFactory = truecaserFactory;
private readonly AsyncLock _lock = new();

#pragma warning disable CA2213 // Disposed in UnloadAsync
private IInteractiveTranslationModel? _smtModel;
private HybridTranslationEngine? _hybridEngine;
#pragma warning restore CA2213

public string EngineId { get; } = engineId;

Expand Down Expand Up @@ -107,9 +109,11 @@ private async Task UnloadAsync(CancellationToken cancellationToken = default)
await SaveModelAsync(cancellationToken);

_hybridEngine.Dispose();
_hybridEngine = null;

_smtModel?.Dispose();
_smtModel = null;
_hybridEngine = null;

CurrentBuildRevision = -1;
}

Expand Down
2 changes: 2 additions & 0 deletions src/SIL.Machine.AspNetCore/Utils/AsyncTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

public class AsyncTimer : AsyncDisposableBase
{
#pragma warning disable CA2213 // Disposed in DisposeManagedResources
private readonly Timer _timer;
#pragma warning restore CA2213
private readonly Func<Task> _callback;
private readonly AsyncLock _lock;
private bool _running;
Expand Down
2 changes: 2 additions & 0 deletions src/SIL.Machine.Tool/ConsoleProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public void Dispose()
{
_disposed = true;
UpdateText(string.Empty);
_timer.Dispose();
_outWriter.Dispose();
}
}
}
2 changes: 2 additions & 0 deletions src/SIL.Machine.Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace SIL.Machine;

#pragma warning disable CA1724 // Type Names Should Not Match Namespaces - SIL.Program. Ignore.
public class Program
#pragma warning restore CA1724
{
public static Task<int> Main(string[] args)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ private class TestEnvironment : DisposableBase
{
private readonly Hangfire.InMemory.InMemoryStorage _memoryStorage;
private readonly BackgroundJobClient _jobClient;
#pragma warning disable CA2213 // Disposed in DisposeManagedResources
private BackgroundJobServer _jobServer;
#pragma warning restore CA2213
private readonly IDistributedReaderWriterLockFactory _lockFactory;

public TestEnvironment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ private class TestEnvironment : DisposableBase
{
private readonly Hangfire.InMemory.InMemoryStorage _memoryStorage;
private readonly BackgroundJobClient _jobClient;
#pragma warning disable CA2213 // Disposed properly in DisposeManagedResources
private BackgroundJobServer _jobServer;
#pragma warning restore CA2213
private readonly ITruecaserFactory _truecaserFactory;
private readonly IDistributedReaderWriterLockFactory _lockFactory;
private readonly IBuildJobService _buildJobService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,9 @@ private static void AddBdryDef(CharacterDefinitionTable table, string strRep)
table.AddBoundary(strRep);
}

#pragma warning disable CA1720 // Identifier contains type name - legacy
protected FeatureStruct Char(CharacterDefinitionTable table, string strRep)
#pragma warning restore CA1720
{
return table[strRep].FeatureStruct;
}
Expand Down

0 comments on commit 524154e

Please sign in to comment.