Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonar issues #294

Merged
merged 1 commit into from
Jun 22, 2024
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
2 changes: 2 additions & 0 deletions DAL/PluginManager.DAL.TextFiles/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@

[assembly: SuppressMessage("Major Code Smell", "S6561:Avoid using \"DateTime.Now\" for benchmarking or timing operations", Justification = "Required for this context", Scope = "member", Target = "~M:PluginManager.DAL.TextFiles.Providers.BlogProvider.AddComment(Middleware.Blog.BlogItem@,Middleware.Blog.BlogComment@,System.Int64@,System.String@,System.String@)")]
[assembly: SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields", Justification = "<Pending>", Scope = "member", Target = "~M:PluginManager.DAL.TextFiles.Providers.DynamicContentProvider.Templates~System.Collections.Generic.List{SharedPluginFeatures.DynamicContent.DynamicContentTemplate}")]
[assembly: SuppressMessage("Major Bug", "S1244:Floating point numbers should not be tested for equality", Justification = "Fine as is", Scope = "member", Target = "~P:PluginManager.DAL.TextFiles.Tables.PageViewsDataRow.TotalTime")]
[assembly: SuppressMessage("Major Code Smell", "S1854:Unused assignments should be removed", Justification = "Without it there will be no depth", Scope = "member", Target = "~M:PluginManager.DAL.TextFiles.Providers.HelpdeskProvider.InternalGetKnowledgebaseGroup(System.Int64,System.Int32)~Middleware.Helpdesk.KnowledgeBaseGroup")]
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void UpdateSetting<T>(string name, T value)
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException(nameof(name));

if (value == null)
if (object.Equals(value, default(T)))
throw new ArgumentNullException(nameof(value));

SettingsDataRow settingsDataRow = _settingsData.Select().FirstOrDefault(sd => sd.Name.Equals(name)) ?? new SettingsDataRow()
Expand Down
4 changes: 4 additions & 0 deletions Database/PluginManager.SimpleDB/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
[assembly: SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "Not required here", Scope = "type", Target = "~T:SimpleDB.InvalidDataRowException")]
[assembly: SuppressMessage("Major Code Smell", "S3925:\"ISerializable\" should be implemented correctly", Justification = "Not required", Scope = "type", Target = "~T:SimpleDB.ObservableDictionary`2")]
[assembly: SuppressMessage("Critical Bug", "S4275:Getters and setters should access the expected fields", Justification = "This is by design to obtain just the table name without path data", Scope = "member", Target = "~P:SimpleDB.Internal.SimpleDBOperations`1.TableName")]
[assembly: SuppressMessage("Minor Code Smell", "S6602:\"Find\" method should be used instead of the \"FirstOrDefault\" extension", Justification = "OK in this context", Scope = "member", Target = "~M:SimpleDB.Internal.SimpleDBOperations`1.GetForeignKeysForTable~System.Collections.Generic.Dictionary{System.String,SimpleDB.Internal.SimpleDBOperations`1.ForeignKeyRelation`0}")]
[assembly: SuppressMessage("Minor Code Smell", "S6602:\"Find\" method should be used instead of the \"FirstOrDefault\" extension", Justification = "OK in this context", Scope = "member", Target = "~M:SimpleDB.Internal.SimpleDBOperations`1.BuildIndexListForTable~SimpleDB.Internal.BatchUpdateDictionary{System.String,SimpleDB.IIndexManager}")]
[assembly: SuppressMessage("Minor Code Smell", "S6602:\"Find\" method should be used instead of the \"FirstOrDefault\" extension", Justification = "OK in this context", Scope = "member", Target = "~M:SimpleDB.Internal.SimpleDBOperations`1.GetTableAttributes~SimpleDB.TableAttribute")]
[assembly: SuppressMessage("Major Code Smell", "S2589:Boolean expressions should not be gratuitous", Justification = "Implementations can return null at this point", Scope = "member", Target = "~M:SimpleDB.Internal.SimpleDBOperations`1.Initialize(PluginManager.Abstractions.IPluginClassesService)")]
2 changes: 2 additions & 0 deletions Demo/DemoApiPlugin/Controllers/DemoApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void Delete(int id)
[HttpGet]
[Route("/api/ex")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "Used as a route to raise an exception")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Major Bug", "S2259:Null pointers should not be dereferenced", Justification = "See above justification")]
public void RaiseError()
{
List<string> list = null;
Expand All @@ -141,6 +142,7 @@ public IActionResult RequiresAuthorization(string s)
return new JsonResult(new { response = $"If you can see this you passed the security without a policy: {s}" });
}

[HttpGet]
[Route("/api/invaliduserPolicy")]
[ApiAuthorization("Policy")]
public IActionResult RequiresAuthorizationPolicy()
Expand Down
1 change: 1 addition & 0 deletions Demo/DemoApiPlugin/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "<Pending>", Scope = "member", Target = "~M:DemoApiPlugin.Controllers.DemoApiController.TestApi(System.String,System.String,System.String)~Microsoft.AspNetCore.Mvc.IActionResult")]
[assembly: SuppressMessage("Major Code Smell", "S6962:You should pool HTTP connections with HttpClientFactory", Justification = "Used as part of a demo app in this context", Scope = "member", Target = "~M:DemoApiPlugin.Controllers.DemoApiController.TestApi(System.String,System.String,System.String)~Microsoft.AspNetCore.Mvc.IActionResult")]
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public BlogItem GetBlog(in int id)
{
int blogId = id;

return _blogEntries.FirstOrDefault(b => b.Id == blogId);
return _blogEntries.Find(b => b.Id == blogId);
}

public List<BlogItem> GetMyBlogs(in long userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ public MockHelpdeskProvider()
_tickets = new List<HelpdeskTicket>()
{
new(1,
GetTicketPriorities().FirstOrDefault(p => p.Id == 1),
GetTicketDepartments().FirstOrDefault(d => d.Id == 2),
GetTicketStatus().FirstOrDefault(s => s.Id == 3),
GetTicketPriorities().Find(p => p.Id == 1),
GetTicketDepartments().Find(d => d.Id == 2),
GetTicketStatus().Find(s => s.Id == 3),
"ABC-123456", "Test 1", DateTime.Now, DateTime.Now, "Joe Bloggs",
"joe@bloggs.com", "Joe Bloggs", new List<HelpdeskTicketMessage>()
{
new(DateTime.Now, "Joe Bloggs", "Hello\r\nLine 2"),
}),
new(2,
GetTicketPriorities().FirstOrDefault(p => p.Id == 1),
GetTicketDepartments().FirstOrDefault(d => d.Id == 2),
GetTicketStatus().FirstOrDefault(s => s.Id == 3),
GetTicketPriorities().Find(p => p.Id == 1),
GetTicketDepartments().Find(d => d.Id == 2),
GetTicketStatus().Find(s => s.Id == 3),
"DEF-987654", "Test 2", DateTime.Now, DateTime.Now, "Jane Doe",
"jane@doe.com", "Service Representative 1", new List<HelpdeskTicketMessage>()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class MockProductProvider : IProductProvider
public ProductGroup ProductGroupGet(in int id)
{
int groupId = id;
return ProductGroupsGet().FirstOrDefault(pg => pg.Id == groupId);
return ProductGroupsGet().Find(pg => pg.Id == groupId);
}

public List<ProductGroup> ProductGroupsGet()
Expand Down Expand Up @@ -139,7 +139,7 @@ public List<Product> GetProducts(in ProductGroup productGroup, in int page, in i
public Product GetProduct(in int id)
{
int prodId = id;
return GetProducts(1, 10000).FirstOrDefault(p => p.Id == prodId);
return GetProducts(1, 10000).Find(p => p.Id == prodId);
}

public bool ProductGroupSave(in int id, in string description, in bool showOnWebsite, in int sortOrder, in string tagLine, in string url, out string errorMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public ShoppingCartDetail GetDetail(in long shoppingCartId)
{
List<ShoppingCartItem> items = new();

Product product = _productProvider.GetProducts(1, 10000).FirstOrDefault(p => p.RetailPrice > 0);
Product product = _productProvider.GetProducts(1, 10000).Find(p => p.RetailPrice > 0);

if (product == null)
return null;
Expand Down Expand Up @@ -250,7 +250,7 @@ private void cartCacheManager_ItemNotFound(object sender, Shared.CacheItemNotFou
0, 0, 20, 0, 0, System.Threading.Thread.CurrentThread.CurrentCulture,
String.Empty, new List<ShoppingCartItem>(), false, "GBP");

Product product = _productProvider.GetProducts(1, 10000).FirstOrDefault(p => p.RetailPrice > 0 && !p.IsDownload);
Product product = _productProvider.GetProducts(1, 10000).First(p => p.RetailPrice > 0 && !p.IsDownload);

if (product != null)
cartDetail.Add(product, 1);
Expand Down
6 changes: 6 additions & 0 deletions Demo/NetCorePluginDemoWebsite/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@
[assembly: SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields", Justification = "<Pending>", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Classes.MockHelpdeskProvider.GetFeedback(System.Boolean@)~System.Collections.Generic.List{Middleware.Helpdesk.Feedback}")]
[assembly: SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "static uri that is unlikely to change", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Classes.MockClaimsProvider.GetUserClaims(System.Int64@)~System.Collections.Generic.List{System.Security.Claims.ClaimsIdentity}")]
[assembly: SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "static uri that is unlikely to change", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Classes.PluginInitialisation.ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection)")]
[assembly: SuppressMessage("Major Code Smell", "S3010:Static fields should not be updated in constructors", Justification = "Mock class so ok", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Classes.MockHelpdeskProvider.#ctor")]
[assembly: SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields", Justification = "Mock class", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Classes.MockShoppingCartPluginProvider.AddToCart(Shared.Classes.UserSession@,SharedPluginFeatures.ShoppingCartSummary@,Middleware.Products.Product@,System.Int32@)~System.Int64")]
[assembly: SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields", Justification = "Mock class", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Classes.Mocks.MockDynamicContentProvider.Templates~System.Collections.Generic.List{SharedPluginFeatures.DynamicContent.DynamicContentTemplate}")]
[assembly: SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields", Justification = "By design", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Classes.MockShoppingCartPluginProvider.cartCacheManager_ItemNotFound(System.Object,Shared.CacheItemNotFoundArgs)")]
[assembly: SuppressMessage("Major Code Smell", "S3010:Static fields should not be updated in constructors", Justification = "Mock class", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Classes.MockShoppingCartPluginProvider.#ctor(Middleware.IProductProvider,Middleware.Accounts.IAccountProvider)")]
[assembly: SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields", Justification = "Mock class", Scope = "member", Target = "~M:AspNetCore.PluginManager.DemoWebsite.Classes.MockShoppingCartPluginProvider.Dispose")]
61 changes: 61 additions & 0 deletions Docs/XmlFiles/SharedPluginFeatures.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions Docs/XmlFiles/UserSessionMiddleware.Plugin.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Plugins/BadEgg.Plugin/Classes/BadEggMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private void LoadRouteData(IActionDescriptorCollectionProvider routeProvider,
foreach (Type type in badeggAttributes)
{
// is it a class attribute
BadEggAttribute attribute = type.GetCustomAttributes(true).FirstOrDefault(a => a.GetType() == typeof(BadEggAttribute)) as BadEggAttribute;
BadEggAttribute attribute = type.GetCustomAttributes(true).FirstOrDefault(a => a is BadEggAttribute) as BadEggAttribute;

if (attribute != null)
{
Expand All @@ -202,7 +202,7 @@ private void LoadRouteData(IActionDescriptorCollectionProvider routeProvider,
foreach (MethodInfo method in type.GetMethods())
{
attribute = method.GetCustomAttributes(true)
.FirstOrDefault(a => a.GetType() == typeof(BadEggAttribute)) as BadEggAttribute;
.FirstOrDefault(a => a is BadEggAttribute) as BadEggAttribute;

if (attribute != null)
{
Expand Down
8 changes: 8 additions & 0 deletions Plugins/Blog.Plugin/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Major Bug", "S2259:Null pointers should not be dereferenced", Justification = "ModelState will be invalid if it's null", Scope = "member", Target = "~M:Blog.Plugin.Controllers.BlogController.Edit(Blog.Plugin.Models.BlogPostViewModel)~Microsoft.AspNetCore.Mvc.IActionResult")]
12 changes: 6 additions & 6 deletions Plugins/Documentation.Plugin/Classes/DocumentPostProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,6 @@ private string FindReplaceableTags(in Document document, BaseDocument linkDocume
continue;
}

if (!inTag)
{
builder.Append(c);
continue;
}

if (inTag && c == '>')
{
inTag = false;
Expand All @@ -398,6 +392,12 @@ private string FindReplaceableTags(in Document document, BaseDocument linkDocume
{
currentTag.Append(c);
}

if (!inTag)
{
builder.Append(c);
continue;
}
}

if (currentTag != null)
Expand Down
1 change: 1 addition & 0 deletions Plugins/Documentation.Plugin/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Major Code Smell", "S125:Sections of code should not be commented out", Justification = "<Pending>")]
[assembly: SuppressMessage("Major Code Smell", "S2589:Boolean expressions should not be gratuitous", Justification = "seems ok in switch statement", Scope = "member", Target = "~M:DocumentationPlugin.Classes.DocumentPostProcess.SplitAndFindReplaceableTags(Shared.Docs.Document@,Shared.Docs.BaseDocument@,System.String@,System.Boolean@,System.Boolean@)~System.String")]
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ private string GenerateContent(bool isEditing)
if (first)
{
Result.AppendFormat("<option value=\"{0}\" selected>{1}</option>",
routeOption, optionText, ctlStyle, disabled);
routeOption, optionText);
first = false;
}
else
{
Result.AppendFormat("<option value=\"{0}\">{1}</option>",
routeOption, optionText, ctlStyle, disabled);
routeOption, optionText);
}
}

Expand Down
8 changes: 8 additions & 0 deletions Plugins/ImageManager.Plugin/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields", Justification = "Required for unique id in app lifetime", Scope = "member", Target = "~M:ImageManager.Plugin.Controllers.ImageManagerController.GetCacheId~System.String")]
1 change: 1 addition & 0 deletions Plugins/MemoryCachePlugin/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Major Code Smell", "S3010:Static fields should not be updated in constructors", Justification = "Required as part of flyweight pattern where multiple instances share same underlying cache. First one created creates the cache items with correct timeout values", Scope = "member", Target = "~M:MemoryCache.Plugin.DefaultMemoryCache.#ctor(PluginManager.Abstractions.ISettingsProvider)")]
[assembly: SuppressMessage("Major Code Smell", "S3010:Static fields should not be updated in constructors", Justification = "As above", Scope = "member", Target = "~M:MemoryCache.Plugin.DefaultMemoryCache.#ctor(PluginManager.Abstractions.ISettingsProvider,System.Boolean,System.DateTime)")]
Loading
Loading