Skip to content

Commit

Permalink
[Backend] Resolve CA1711, CA1725, CA2215, CA2229 (#2328)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Jun 28, 2023
1 parent 494da2a commit e420fce
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 22 deletions.
2 changes: 0 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ indent_size = 4
# CA1305 requires using a FormatProvider with int.Parse and string.Format.
dotnet_diagnostic.CA1305.severity = none
dotnet_diagnostic.CA1710.severity = warning
# CA1816 is our only exception to <AnalysisMode>Minimum</AnalysisMode>.
dotnet_diagnostic.CA1816.severity = none
# CS1591 is our only exception to EnforceCodeStyleInBuild+GenerateDocumentationFile.
dotnet_diagnostic.CS1591.severity = none
# IDE0005 requires both EnforceCodeStyleInBuild and GenerateDocumentationFile set to true.
Expand Down
2 changes: 1 addition & 1 deletion Backend.Tests/Backend.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AnalysisMode>Recommended</AnalysisMode>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CA1305;CA1816;CS1591</NoWarn>
<NoWarn>$(NoWarn);CA1305;CS1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
Expand Down
4 changes: 4 additions & 0 deletions Backend/Helper/FileOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;

Expand All @@ -13,6 +14,9 @@ public class InvalidFileException : Exception
{
public InvalidFileException(string message) : base(message) { }

protected InvalidFileException(SerializationInfo info, StreamingContext context)
: base(info, context) { }

}

/// <summary>
Expand Down
17 changes: 15 additions & 2 deletions Backend/Helper/FileStorage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.Serialization;

namespace BackendFramework.Helper
{
Expand All @@ -24,11 +25,23 @@ public enum FileType

/// <summary> Indicates that an error occurred locating the current user's home directory. </summary>
[Serializable]
public class HomeFolderNotFoundException : Exception { }
public class HomeFolderNotFoundException : Exception
{
public HomeFolderNotFoundException() { }

protected HomeFolderNotFoundException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}

/// <summary> Indicates an invalid input id. </summary>
[Serializable]
public class InvalidIdException : Exception { }
public class InvalidIdException : Exception
{
public InvalidIdException() { }

protected InvalidIdException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}

/// <summary>
/// Generate a path to the file name of an audio file for the Project based on the Word ID.
Expand Down
4 changes: 4 additions & 0 deletions Backend/Helper/LiftHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using SIL.Lift.Parsing;

namespace BackendFramework.Helper
Expand All @@ -10,6 +11,9 @@ public class InvalidLiftFileException : InvalidFileException
{
public InvalidLiftFileException(string message) : base("Malformed LIFT file: " + message) { }

protected InvalidLiftFileException(SerializationInfo info, StreamingContext context)
: base(info, context) { }

}

public static class LiftHelper
Expand Down
20 changes: 10 additions & 10 deletions Backend/Interfaces/ILiftService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ namespace BackendFramework.Interfaces
public interface ILiftService
{
ILiftMerger GetLiftImporterExporter(string projectId, IWordRepository wordRepo);
Task<bool> LdmlImport(string filePath, IProjectRepository projRepo, Project project);
Task<bool> LdmlImport(string dirPath, IProjectRepository projRepo, Project project);
Task<string> LiftExport(string projectId, IWordRepository wordRepo, IProjectRepository projRepo);

// Methods to store, retrieve, and delete an export/import string in a common dictionary.
void StoreExport(string key, string filePath);
string? RetrieveExport(string key);
bool DeleteExport(string key);
void SetExportInProgress(string key, bool isInProgress);
bool IsExportInProgress(string key);
void StoreImport(string key, string filePath);
string? RetrieveImport(string key);
bool DeleteImport(string key);
// Methods to store, retrieve, and delete an export string in a common dictionary.
void StoreExport(string userId, string filePath);
string? RetrieveExport(string userId);
bool DeleteExport(string userId);
void SetExportInProgress(string userId, bool isInProgress);
bool IsExportInProgress(string userId);
void StoreImport(string userId, string filePath);
string? RetrieveImport(string userId);
bool DeleteImport(string userId);
}

public interface ILiftMerger : ILexiconMerger<LiftObject, LiftEntry, LiftSense, LiftExample>
Expand Down
3 changes: 3 additions & 0 deletions Backend/Models/UserRole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public override int GetHashCode()
}
}

#pragma warning disable CA1711
// Ignoring CA1711, which requires identifiers ending in Permission to implement System.Security.IPermission.
public enum Permission
#pragma warning restore CA1711
{
/// <summary> Project Owner by default should be given to the user who created the project </summary>
Owner = 6,
Expand Down
11 changes: 8 additions & 3 deletions Backend/Services/LiftService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Security;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -49,12 +50,13 @@ protected override void InsertPronunciationIfNeeded(
}
}

// This raises error CA1816, which is currently suppressed in .editorconfig and with <NoWarn>.
#pragma warning disable CA1816, CA2215
public override void Dispose()
{
// TODO: When updating the LiftWriter dependency, check to see if its Dispose() implementation
// has been fixed properly to avoid needing to override its Dispose method.
// https://github.com/sillsdev/libpalaso/blob/master/SIL.DictionaryServices/Lift/LiftWriter.cs
// Also, re-evaluate our CA1816 violation.
Dispose(true);
}

Expand All @@ -73,16 +75,19 @@ protected override void Dispose(bool disposing)

Disposed = true;

// Generally, the base class Dispose method would be called here, but it accesses _writer,
// Generally, the base class Dispose method would be called here (CA2215), but it accesses _writer,
// and we are disposing of that ourselves in the child class to fix a memory leak.
}
#pragma warning restore CA1816, CA2215
}

[Serializable]
public class MissingProjectException : Exception
{
public MissingProjectException(string message) : base(message) { }

protected MissingProjectException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}

public class LiftService : ILiftService
Expand All @@ -105,7 +110,7 @@ public LiftService()
}

/// <summary> Store status that a user's export is in-progress. </summary>
public void SetExportInProgress(string userId, bool isInProgress = true)
public void SetExportInProgress(string userId, bool isInProgress)
{
_liftExports.Remove(userId);
if (isInProgress)
Expand Down
4 changes: 4 additions & 0 deletions Backend/Services/MergeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using BackendFramework.Helper;
using BackendFramework.Interfaces;
using BackendFramework.Models;
Expand Down Expand Up @@ -223,6 +224,9 @@ public class InvalidBlacklistEntryException : Exception
public InvalidBlacklistEntryException() { }

public InvalidBlacklistEntryException(string message) : base(message) { }

protected InvalidBlacklistEntryException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
}
}
4 changes: 4 additions & 0 deletions Backend/Services/PermissionService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Runtime.Serialization;
using System.Security.Claims;
using System.Text;
using System.Text.Json;
Expand Down Expand Up @@ -244,6 +245,9 @@ public InvalidJwtTokenException() { }
public InvalidJwtTokenException(string msg) : base(msg) { }

public InvalidJwtTokenException(string msg, Exception innerException) : base(msg, innerException) { }

protected InvalidJwtTokenException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
}

Expand Down
8 changes: 4 additions & 4 deletions Backend/Services/UserEditService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task<Tuple<bool, int>> AddGoalToUserEdit(string projectId, string u

/// <summary> Adds a string representation of a step to a specified <see cref="Edit"/> </summary>
/// <returns> A bool: success of operation </returns>
public async Task<bool> AddStepToGoal(string projectId, string userEditId, int goalIndex, string newStep)
public async Task<bool> AddStepToGoal(string projectId, string userEditId, int goalIndex, string stepString)
{
var oldUserEdit = await _userEditRepo.GetUserEdit(projectId, userEditId);
if (oldUserEdit is null || goalIndex >= oldUserEdit.Edits.Count)
Expand All @@ -70,15 +70,15 @@ public async Task<bool> AddStepToGoal(string projectId, string userEditId, int g
}

var newUserEdit = oldUserEdit.Clone();
newUserEdit.Edits[goalIndex].StepData.Add(newStep);
newUserEdit.Edits[goalIndex].StepData.Add(stepString);
var updateResult = await _userEditRepo.Replace(projectId, userEditId, newUserEdit);
return updateResult;
}

/// <summary> Updates a specified step to in a specified <see cref="Edit"/> </summary>
/// <returns> A bool: success of operation </returns>
public async Task<bool> UpdateStepInGoal(
string projectId, string userEditId, int goalIndex, string updatedStep, int stepIndex)
string projectId, string userEditId, int goalIndex, string stepString, int stepIndex)
{
var oldUserEdit = await _userEditRepo.GetUserEdit(projectId, userEditId);
if (oldUserEdit is null || goalIndex >= oldUserEdit.Edits.Count
Expand All @@ -88,7 +88,7 @@ public async Task<bool> UpdateStepInGoal(
}

var newUserEdit = oldUserEdit.Clone();
newUserEdit.Edits[goalIndex].StepData[stepIndex] = updatedStep;
newUserEdit.Edits[goalIndex].StepData[stepIndex] = stepString;
var updateResult = await _userEditRepo.Replace(projectId, userEditId, newUserEdit);
return updateResult;
}
Expand Down

0 comments on commit e420fce

Please sign in to comment.