Resolved more warnings, and marked more warning types as errors (#16991)
* Fix warnings SA1111, SA1028, SA1500, IDE1270 in Umbraco.Web.Website, and updated rules. * Remove warnings: IDE0270: Null check can be simplified * More SqlServer project warnings resolved * CS0105 namespace appeared already * Suppress warning until implementation: #pragma warning disable CS0162 // Unreachable code detected #pragma warning disable CS0618 // Type or member is obsolete CS0162 remove unreachable code SA1028 remove trailing whitespace SA1106 no empty statements CS1570 malformed XML CS1572 corrected xml parameter CS1573 param tag added IDE0007 var not explicit IDE0008 explicit not var IDE0057 simplify substring IDE0074 compound assignment CA1825 array.empty Down to 3479 warnings * - SA1116, SA117 params on same line - IDE0057 substring simplified Specific warnings for Umbraco.Tests.Benchmarks * Fixed IDE0074 compound assignment and added specific warnings for Umbraco.Tests.Common * Specific warnings for Umbraco.Tests.Integration and Umbraco.Tests.Common Fixed: - SA1111, SA1116, SA117 params and line formatting (not all as there are many) - SA1122 string.Empty - IDE0057 simplify substring - IDE0044,IDE0044 make field readonly - IDE1006 naming rule violation (add _) - SA1111 closing parenthesis on line of last parameter - SA1649 filename match type name - SA1312,SA1306 lowercase variable and field names * Fixed various warnings where they are more straight-forward, including: - SA1649 file name match type name - SA111 parenthesis on line of last parameter - IDE0028 simplify collection initializer - SA1306 lower-case letter field - IDE044 readonly field - SA1122 string.Empty - SA1116 params same line - IDE1006 upper casing - IDE0041 simplify null check Updated the following projects to only list their remaining specific warning codes: - Umbraco.Tests.UnitTests Typo in `Umbraco.Web.Website` project * Reverted test change * Now 1556 warnings. Fixed various warnings where they are more straight-forward, including: - SA1111/SA1116/SA1119 parenthesis - SA1117 params - SA1312 lowercase variable - SA1121 built-in type - SA1500/SA1513/SA1503 formatting braces - SA1400 declare access modifier - SA1122 string.Empty - SA1310 no underscore - IDE0049 name simplified - IDE0057 simplify substring - IDE0074 compound assignment - IDE0032 use auto-property - IDE0037 simplify member name - IDE0008 explicit type not var - IDE0016/IDE0270/IDE0041 simplify null checks - IDE0048/SA1407 clarity in arithmetic - IDE1006 correct param names - IDE0042 deconstruct variable - IDE0044 readonly - IDE0018 inline variable declarations - IDE0074/IDE0054 compound assignment - IDE1006 naming - CS1573 param XML - CS0168 unused variable Comment formatting in project files for consistency. Updated all projects to only list remaining specific warning codes as warnings instead of errors (errors is now default). * Type not var, and more warning exceptions * Tweaked merge issue, readded comment about rollback * Readded comment re rollback. * Readded comments * Comment tweak * Comment tweak
This commit is contained in:
@@ -34,7 +34,7 @@ public class SuppressNotificationsTests : UmbracoIntegrationTest
|
||||
public void GivenScope_WhenNotificationsSuppressed_ThenNotificationsDoNotExecute()
|
||||
{
|
||||
using var scope = ScopeProvider.CreateScope(autoComplete: true);
|
||||
using var _ = scope.Notifications.Suppress();
|
||||
using var suppressed = scope.Notifications.Suppress();
|
||||
|
||||
var contentType = ContentTypeBuilder.CreateBasicContentType();
|
||||
ContentTypeService.Save(contentType);
|
||||
@@ -47,7 +47,7 @@ public class SuppressNotificationsTests : UmbracoIntegrationTest
|
||||
{
|
||||
using (var parentScope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
using var _ = parentScope.Notifications.Suppress();
|
||||
using var suppressed = parentScope.Notifications.Suppress();
|
||||
|
||||
using (var childScope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
@@ -38,7 +38,7 @@ public class BackOfficeUserStoreTests : UmbracoIntegrationTest
|
||||
|
||||
private IEventMessagesFactory EventMessagesFactory => GetRequiredService<IEventMessagesFactory>();
|
||||
|
||||
private ILogger<BackOfficeUserStore> Logger = NullLogger<BackOfficeUserStore>.Instance;
|
||||
private readonly ILogger<BackOfficeUserStore> _logger = NullLogger<BackOfficeUserStore>.Instance;
|
||||
|
||||
|
||||
private BackOfficeUserStore GetUserStore()
|
||||
@@ -55,7 +55,7 @@ public class BackOfficeUserStoreTests : UmbracoIntegrationTest
|
||||
UserRepository,
|
||||
RuntimeState,
|
||||
EventMessagesFactory,
|
||||
Logger
|
||||
_logger
|
||||
);
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -221,8 +221,7 @@ public class CacheInstructionServiceTests : UmbracoIntegrationTest
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(3, result.LastId); // 3 records found.
|
||||
Assert.AreEqual(2,
|
||||
result.NumberOfInstructionsProcessed); // 2 records processed (as one is for the same identity).
|
||||
Assert.AreEqual(2, result.NumberOfInstructionsProcessed); // 2 records processed (as one is for the same identity).
|
||||
Assert.IsFalse(result.InstructionsWerePruned);
|
||||
});
|
||||
|
||||
@@ -231,11 +230,17 @@ public class CacheInstructionServiceTests : UmbracoIntegrationTest
|
||||
|
||||
// The instructions has now been processed and shouldn't be processed on the next call...
|
||||
// Run again.
|
||||
var secondResult = sut.ProcessInstructions(CacheRefreshers, ServerRoleAccessor.CurrentServerRole,
|
||||
CancellationToken, LocalIdentity, DateTime.UtcNow.AddSeconds(-1), lastId);
|
||||
var secondResult = sut.ProcessInstructions(
|
||||
CacheRefreshers,
|
||||
ServerRoleAccessor.CurrentServerRole,
|
||||
CancellationToken,
|
||||
LocalIdentity,
|
||||
DateTime.UtcNow.AddSeconds(-1),
|
||||
lastId);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(0,
|
||||
Assert.AreEqual(
|
||||
0,
|
||||
secondResult
|
||||
.LastId); // No instructions was processed so LastId is 0, this is consistent with behavior from V8
|
||||
Assert.AreEqual(0, secondResult.NumberOfInstructionsProcessed); // Nothing was processed.
|
||||
|
||||
@@ -328,8 +328,7 @@ public class ContentServicePublishBranchTests : UmbracoIntegrationTest
|
||||
Assert.IsTrue(vRoot.IsCulturePublished("es"));
|
||||
Assert.IsTrue(vRoot.IsCultureEdited("es")); // has draft
|
||||
|
||||
Assert.AreEqual("changed",
|
||||
vRoot.GetValue("ip", published: true)); // publishing de implies publishing invariants
|
||||
Assert.AreEqual("changed", vRoot.GetValue("ip", published: true)); // publishing de implies publishing invariants
|
||||
Assert.AreEqual("changed.de", vRoot.GetValue("vp", "de", published: true));
|
||||
|
||||
// validate - de and ru are published, es has not been published
|
||||
|
||||
@@ -934,7 +934,8 @@ public class ContentServiceTagsTests : UmbracoIntegrationTest
|
||||
Assert.AreEqual(2, savedTags.Length);
|
||||
}
|
||||
|
||||
private PropertyType CreateAndAddTagsPropertyType(ContentType contentType,
|
||||
private PropertyType CreateAndAddTagsPropertyType(
|
||||
ContentType contentType,
|
||||
ContentVariation variations = ContentVariation.Nothing)
|
||||
{
|
||||
var propertyType = new PropertyTypeBuilder()
|
||||
|
||||
@@ -641,9 +641,11 @@ public class ContentTypeServiceTests : UmbracoIntegrationTest
|
||||
Assert.AreNotEqual(contentType.Key, category.Key);
|
||||
Assert.AreNotEqual(contentType.Path, category.Path);
|
||||
Assert.AreNotEqual(contentType.SortOrder, category.SortOrder);
|
||||
Assert.AreNotEqual(contentType.PropertyTypes.First(x => x.Alias.Equals("title")).Id,
|
||||
Assert.AreNotEqual(
|
||||
contentType.PropertyTypes.First(x => x.Alias.Equals("title")).Id,
|
||||
category.PropertyTypes.First(x => x.Alias.Equals("title")).Id);
|
||||
Assert.AreNotEqual(contentType.PropertyGroups.First(x => x.Name.Equals("Content")).Id,
|
||||
Assert.AreNotEqual(
|
||||
contentType.PropertyGroups.First(x => x.Name.Equals("Content")).Id,
|
||||
category.PropertyGroups.First(x => x.Name.Equals("Content")).Id);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ContentTypeServiceVariantsTests : UmbracoIntegrationTest
|
||||
{
|
||||
var json = GetJson(id).Replace('"', '\'');
|
||||
var pos = json.IndexOf("'cd':", StringComparison.InvariantCultureIgnoreCase);
|
||||
json = json.Substring(0, pos + "'cd':".Length);
|
||||
json = json[..(pos + "'cd':".Length)];
|
||||
Assert.AreEqual(expected, json);
|
||||
}
|
||||
|
||||
@@ -82,8 +82,10 @@ public class ContentTypeServiceVariantsTests : UmbracoIntegrationTest
|
||||
[TestCase(ContentVariation.CultureAndSegment, ContentVariation.Segment, true)]
|
||||
[TestCase(ContentVariation.CultureAndSegment, ContentVariation.CultureAndSegment, false)]
|
||||
[LongRunning]
|
||||
public void Change_Content_Type_Variation_Clears_Redirects(ContentVariation startingContentTypeVariation,
|
||||
ContentVariation changedContentTypeVariation, bool shouldUrlRedirectsBeCleared)
|
||||
public void Change_Content_Type_Variation_Clears_Redirects(
|
||||
ContentVariation startingContentTypeVariation,
|
||||
ContentVariation changedContentTypeVariation,
|
||||
bool shouldUrlRedirectsBeCleared)
|
||||
{
|
||||
var contentType = ContentTypeBuilder.CreateBasicContentType();
|
||||
contentType.Variations = startingContentTypeVariation;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
@@ -238,7 +238,8 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest
|
||||
Assert.AreEqual("Testing12345", item.ItemKey);
|
||||
foreach (var language in allLangs)
|
||||
{
|
||||
Assert.AreEqual($"Translation for: {language.IsoCode}",
|
||||
Assert.AreEqual(
|
||||
$"Translation for: {language.IsoCode}",
|
||||
item.Translations.Single(x => x.LanguageIsoCode == language.IsoCode).Value);
|
||||
}
|
||||
}
|
||||
@@ -627,8 +628,7 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest
|
||||
dictionaryResult = await DictionaryItemService.CreateAsync(
|
||||
new DictionaryItem(
|
||||
parentItem.Key,
|
||||
"Child"
|
||||
)
|
||||
"Child")
|
||||
{
|
||||
Translations = new List<IDictionaryTranslation>
|
||||
{
|
||||
|
||||
@@ -836,9 +836,11 @@ public class EntityServiceTests : UmbracoIntegrationTest
|
||||
[Test]
|
||||
public void EntityService_Cannot_Get_Id_For_Key_With_Incorrect_Object_Type()
|
||||
{
|
||||
var result1 = EntityService.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"),
|
||||
var result1 = EntityService.GetId(
|
||||
Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"),
|
||||
UmbracoObjectTypes.DocumentType);
|
||||
var result2 = EntityService.GetId(Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"),
|
||||
var result2 = EntityService.GetId(
|
||||
Guid.Parse("1D3A8E6E-2EA9-4CC1-B229-1AEE19821522"),
|
||||
UmbracoObjectTypes.MediaType);
|
||||
|
||||
Assert.IsTrue(result1.Success);
|
||||
@@ -868,7 +870,7 @@ public class EntityServiceTests : UmbracoIntegrationTest
|
||||
Assert.IsFalse(EntityService.GetId(Guid.NewGuid(), UmbracoObjectTypes.DocumentType).Success);
|
||||
}
|
||||
|
||||
private static bool s_isSetup;
|
||||
private static bool _isSetup;
|
||||
|
||||
private int _folderId;
|
||||
private ContentType _contentType;
|
||||
@@ -885,9 +887,9 @@ public class EntityServiceTests : UmbracoIntegrationTest
|
||||
|
||||
public void CreateTestData()
|
||||
{
|
||||
if (s_isSetup == false)
|
||||
if (_isSetup == false)
|
||||
{
|
||||
s_isSetup = true;
|
||||
_isSetup = true;
|
||||
|
||||
var template = TemplateBuilder.CreateTextPageTemplate("defaultTemplate");
|
||||
FileService.SaveTemplate(template); // else, FK violation on contentType!
|
||||
|
||||
@@ -120,7 +120,7 @@ public class EntityXmlSerializerTests : UmbracoIntegrationTest
|
||||
Assert.AreEqual(content.Name, (string)element.Attribute("nodeName"));
|
||||
Assert.AreEqual(urlName, (string)element.Attribute("urlName"));
|
||||
Assert.AreEqual(content.Path, (string)element.Attribute("path"));
|
||||
Assert.AreEqual("", (string)element.Attribute("isDoc"));
|
||||
Assert.AreEqual(string.Empty, (string)element.Attribute("isDoc"));
|
||||
Assert.AreEqual(content.ContentType.Id.ToString(), (string)element.Attribute("nodeType"));
|
||||
Assert.AreEqual(content.GetCreatorProfile(UserService).Name, (string)element.Attribute("creatorName"));
|
||||
Assert.AreEqual(content.GetWriterProfile(UserService).Name, (string)element.Attribute("writerName"));
|
||||
@@ -128,11 +128,14 @@ public class EntityXmlSerializerTests : UmbracoIntegrationTest
|
||||
Assert.AreEqual(content.TemplateId.ToString(), (string)element.Attribute("template"));
|
||||
|
||||
Assert.AreEqual(content.Properties["title"].GetValue().ToString(), element.Elements("title").Single().Value);
|
||||
Assert.AreEqual(content.Properties["bodyText"].GetValue().ToString(),
|
||||
Assert.AreEqual(
|
||||
content.Properties["bodyText"].GetValue().ToString(),
|
||||
element.Elements("bodyText").Single().Value);
|
||||
Assert.AreEqual(content.Properties["keywords"].GetValue().ToString(),
|
||||
Assert.AreEqual(
|
||||
content.Properties["keywords"].GetValue().ToString(),
|
||||
element.Elements("keywords").Single().Value);
|
||||
Assert.AreEqual(content.Properties["description"].GetValue().ToString(),
|
||||
Assert.AreEqual(
|
||||
content.Properties["description"].GetValue().ToString(),
|
||||
element.Elements("description").Single().Value);
|
||||
}
|
||||
|
||||
@@ -193,7 +196,7 @@ public class EntityXmlSerializerTests : UmbracoIntegrationTest
|
||||
Assert.AreEqual(media.Name, (string)element.Attribute("nodeName"));
|
||||
Assert.AreEqual(urlName, (string)element.Attribute("urlName"));
|
||||
Assert.AreEqual(media.Path, (string)element.Attribute("path"));
|
||||
Assert.AreEqual("", (string)element.Attribute("isDoc"));
|
||||
Assert.AreEqual(string.Empty, (string)element.Attribute("isDoc"));
|
||||
Assert.AreEqual(media.ContentType.Id.ToString(), (string)element.Attribute("nodeType"));
|
||||
Assert.AreEqual(media.GetCreatorProfile(UserService).Name, (string)element.Attribute("writerName"));
|
||||
Assert.AreEqual(media.CreatorId.ToString(), (string)element.Attribute("writerID"));
|
||||
|
||||
@@ -275,7 +275,8 @@ public class LocalizationServiceTests : UmbracoIntegrationTest
|
||||
Assert.Greater(allLangs.Count(), 0);
|
||||
foreach (var language in allLangs)
|
||||
{
|
||||
Assert.AreEqual("Hellooooo",
|
||||
Assert.AreEqual(
|
||||
"Hellooooo",
|
||||
item.Translations.Single(x => x.LanguageIsoCode == language.IsoCode).Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using NUnit.Framework;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Services;
|
||||
@@ -177,11 +177,11 @@ public class MediaTypeContainerServiceTests : UmbracoIntegrationTest
|
||||
{
|
||||
EntityContainer container = (await MediaTypeContainerService.CreateAsync(null,"Root Container", null, Constants.Security.SuperUserKey)).Result;
|
||||
|
||||
IMediaType MediaType = new MediaType(ShortStringHelper, container.Id)
|
||||
IMediaType mediaType = new MediaType(ShortStringHelper, container.Id)
|
||||
{
|
||||
Alias = "test", Name = "Test"
|
||||
};
|
||||
MediaTypeService.Save(MediaType);
|
||||
MediaTypeService.Save(mediaType);
|
||||
|
||||
var result = await MediaTypeContainerService.DeleteAsync(container.Key, Constants.Security.SuperUserKey);
|
||||
Assert.IsFalse(result.Success);
|
||||
@@ -190,7 +190,7 @@ public class MediaTypeContainerServiceTests : UmbracoIntegrationTest
|
||||
var currentContainer = await MediaTypeContainerService.GetAsync(container.Key);
|
||||
Assert.IsNotNull(currentContainer);
|
||||
|
||||
var currentMediaType = MediaTypeService.Get(MediaType.Key);
|
||||
var currentMediaType = MediaTypeService.Get(mediaType.Key);
|
||||
Assert.IsNotNull(currentMediaType);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,9 +170,11 @@ public class MediaTypeServiceTests : UmbracoIntegrationTest
|
||||
Assert.AreNotEqual(mediaType.Key, sut.Key);
|
||||
Assert.AreNotEqual(mediaType.Path, sut.Path);
|
||||
Assert.AreNotEqual(mediaType.SortOrder, sut.SortOrder);
|
||||
Assert.AreNotEqual(mediaType.PropertyTypes.First(x => x.Alias.Equals("umbracoFile")).Id,
|
||||
Assert.AreNotEqual(
|
||||
mediaType.PropertyTypes.First(x => x.Alias.Equals("umbracoFile")).Id,
|
||||
sut.PropertyTypes.First(x => x.Alias.Equals("umbracoFile")).Id);
|
||||
Assert.AreNotEqual(mediaType.PropertyGroups.First(x => x.Name.Equals("Media")).Id,
|
||||
Assert.AreNotEqual(
|
||||
mediaType.PropertyGroups.First(x => x.Name.Equals("Media")).Id,
|
||||
sut.PropertyGroups.First(x => x.Name.Equals("Media")).Id);
|
||||
}
|
||||
|
||||
@@ -214,9 +216,11 @@ public class MediaTypeServiceTests : UmbracoIntegrationTest
|
||||
Assert.AreNotEqual(clonedMediaType.Key, originalMediaType.Key);
|
||||
Assert.AreNotEqual(clonedMediaType.Path, originalMediaType.Path);
|
||||
|
||||
Assert.AreNotEqual(clonedMediaType.PropertyTypes.First(x => x.Alias.StartsWith("umbracoFile")).Id,
|
||||
Assert.AreNotEqual(
|
||||
clonedMediaType.PropertyTypes.First(x => x.Alias.StartsWith("umbracoFile")).Id,
|
||||
originalMediaType.PropertyTypes.First(x => x.Alias.StartsWith("umbracoFile")).Id);
|
||||
Assert.AreNotEqual(clonedMediaType.PropertyGroups.First(x => x.Name.StartsWith("Media")).Id,
|
||||
Assert.AreNotEqual(
|
||||
clonedMediaType.PropertyGroups.First(x => x.Name.StartsWith("Media")).Id,
|
||||
originalMediaType.PropertyGroups.First(x => x.Name.StartsWith("Media")).Id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user