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

Remove useless variable assignments #1400

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- [SIL.Windows.Forms] Changed build date in SILAboutBox to be computed using the last write time instead of creation time.
- [SIL.Windows.Forms] Made FadingMessageWindow implement all UI logic on the main UI thread in a thread-safe way. Fixes crashes like SP-2340.
- [SIL.Core.ClearShare] BREAKING CHANGE: Public method LoadWorkFromXml could possibly return a contribution with null role; in those cases, now falls back to the first role in the list of roles in the doc.

## [15.0.0] - 2025-01-06

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class RobustNetworkOperationTests
[Test, Ignore("Run by hand")]
public void DoHttpGetAndGetProxyInfo()
{
string host, userName, password;
bool gotProxy = RobustNetworkOperation.DoHttpGetAndGetProxyInfo("http://hg.palaso.org/", out host, out userName, out password, s=>Debug.WriteLine(s));
_ = RobustNetworkOperation.DoHttpGetAndGetProxyInfo(
"http://hg.palaso.org/", out _, out _, out _, s => Debug.WriteLine(s));
}

}
Expand Down
2 changes: 1 addition & 1 deletion SIL.Core.Desktop.Tests/UsbDrive/UsbDeviceInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void RootDirectory_FirstDriveIsNotMounted_Throws()
Assert.Throws<ArgumentOutOfRangeException>(
() =>
{
string s = usbDrives[0].RootDirectory.FullName;
_ = usbDrives[0].RootDirectory.FullName;
}
);
}
Expand Down
14 changes: 7 additions & 7 deletions SIL.Core.Desktop.Tests/i18n/StringCatalogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
[Test]
public void GetFormatted_FoundCorrectString_Formats()
{
StringCatalog catalog = new StringCatalog(_poFile, null, 9);
_ = new StringCatalog(_poFile, null, 9);
Assert.AreEqual("first=one", StringCatalog.GetFormatted("oneParam", "blah blah", "one"));
}

Expand All @@ -112,7 +112,7 @@
[Test]
public void GetFormatted_TooManyParamsInCatalog_ShowsMessageAndReturnRightMessage()
{
StringCatalog catalog = new StringCatalog(_poFile, null, 9);
_ = new StringCatalog(_poFile, null, 9);
using(new ErrorReport.NonFatalErrorReportExpected())
{
var answer = StringCatalog.GetFormatted("oneParam", "blah blah");
Expand Down Expand Up @@ -166,31 +166,31 @@
[Test]
public void FontsDoNotScaleUp()
{
StringCatalog catalog = new StringCatalog(_poFile, "Onyx", 30);
Font normal = new Font(System.Drawing.FontFamily.GenericSerif, 20);
_ = new StringCatalog(_poFile, "Onyx", 30);
Font normal = new Font(FontFamily.GenericSerif, 20);
Font localized = StringCatalog.ModifyFontForLocalization(normal);
Assert.AreEqual(20,Math.Floor(localized.SizeInPoints));
}
[Test]
public void FontsDoNotChange()
{
StringCatalog catalog = new StringCatalog(_poFile, FontFamily.GenericSansSerif.Name, 30);
_ = new StringCatalog(_poFile, FontFamily.GenericSansSerif.Name, 30);
Font normal = new Font(FontFamily.GenericSerif, 20);

Check warning

Code scanning / CodeQL

Missing Dispose call on local IDisposable Warning test

Disposable 'Font' is created but not disposed.
Font localized = StringCatalog.ModifyFontForLocalization(normal);
Assert.AreEqual(FontFamily.GenericSerif.Name, localized.FontFamily.Name);
}
[Test]
public void ModifyFontForLocation_SmallFont_ValidFont()
{
StringCatalog catalog = new StringCatalog(_poFile, FontFamily.GenericSerif.Name, Single.Epsilon);
_ = new StringCatalog(_poFile, FontFamily.GenericSerif.Name, Single.Epsilon);
Font normal = new Font(FontFamily.GenericSerif, Single.Epsilon);
Font localized = StringCatalog.ModifyFontForLocalization(normal);
Assert.IsNotNull(localized);
}
[Test]
public void ModifyFontForLocation_HugeFont_ValidFont()
{
StringCatalog catalog = new StringCatalog(_poFile, FontFamily.GenericSerif.Name, Single.MaxValue);
_ = new StringCatalog(_poFile, FontFamily.GenericSerif.Name, Single.MaxValue);
Font normal = new Font(FontFamily.GenericSerif, Single.MaxValue);
Font localized = StringCatalog.ModifyFontForLocalization(normal);
Assert.IsNotNull(localized);
Expand Down
14 changes: 7 additions & 7 deletions SIL.Core.Desktop/Settings/CrossPlatformSettingsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public CrossPlatformSettingsProvider()
GetFullSettingsPath());
// When running multiple builds in parallel we have to use separate directories for
// each build, otherwise some unit tests might fail.
var buildagentSubdir = Environment.GetEnvironmentVariable("BUILDAGENT_SUBKEY");
if (!string.IsNullOrEmpty(buildagentSubdir))
var buildAgentSubdir = Environment.GetEnvironmentVariable("BUILDAGENT_SUBKEY");
if (!string.IsNullOrEmpty(buildAgentSubdir))
{
UserRoamingLocation = Path.Combine(UserRoamingLocation, buildagentSubdir);
UserLocalLocation = Path.Combine(UserLocalLocation, buildagentSubdir);
UserRoamingLocation = Path.Combine(UserRoamingLocation, buildAgentSubdir);
UserLocalLocation = Path.Combine(UserLocalLocation, buildAgentSubdir);
}
}

Expand All @@ -85,7 +85,7 @@ public Exception CheckForErrorsInSettingsFile()
throw new ApplicationException("CrossPlatformSettingsProvider: Call Initialize() before CheckForErrorsInFile()");

_reportReadingErrorsDirectlyToUser = false;
var dummy =SettingsXml;
_ = SettingsXml;
return _lastReadingError;
}

Expand Down Expand Up @@ -167,7 +167,7 @@ public override void SetPropertyValues(SettingsContext context, SettingsProperty
_settingsXml = null;

//Iterate through the settings to be stored, only dirty settings for this provider are in collection
foreach(SettingsPropertyValue propval in collection)
foreach(SettingsPropertyValue propVal in collection)
{
var groupName = context["GroupName"].ToString();
var groupNode = SettingsXml.SelectSingleNode("/configuration/userSettings/" + context["GroupName"]);
Expand All @@ -186,7 +186,7 @@ public override void SetPropertyValues(SettingsContext context, SettingsProperty
section.SetAttribute("type", String.Format("{0}, {1}", typeof(ClientSettingsSection), Assembly.GetAssembly(typeof(ClientSettingsSection))));
parentNode.AppendChild(section);
}
SetValue(groupNode, propval);
SetValue(groupNode, propVal);
}
Directory.CreateDirectory(UserConfigLocation);
RobustIO.SaveXml(SettingsXml, Path.Combine(UserConfigLocation, UserConfigFileName));
Expand Down
5 changes: 3 additions & 2 deletions SIL.Core.Tests/Migration/XmlReaderWriterMigratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ protected override void CopyNode(XmlReader reader, XmlWriter writer)
writer.WriteStartElement("configuration");
writer.WriteAttributeString("version", "2");
reader.Read();
} else
}
else
{
writer.WriteNode(reader, true);
}
Expand All @@ -36,7 +37,7 @@ protected override void CopyNode(XmlReader reader, XmlWriter writer)
public void Constructor_FromLessThanTo_Throws()
{
Assert.Throws<ArgumentException>(
() => { var migrator = new MigratorForTest(5, 4); }
() => { _ = new MigratorForTest(5, 4); }
);
}

Expand Down
2 changes: 1 addition & 1 deletion SIL.Core.Tests/Migration/XslMigratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override TextReader OpenXslStream(string xslSource)
public void Constructor_FromLessThanTo_Throws()
{
Assert.Throws<ArgumentException>(
() => { var migrator = new XslStringMigrator(5, 4, null); }
() => { _ = new XslStringMigrator(5, 4, null); }
);
}

Expand Down
10 changes: 4 additions & 6 deletions SIL.Core.Tests/Spelling/WordTokenizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ public void PassNULL_Throws()
{
Assert.Throws<ArgumentNullException>(
() =>
{
foreach (WordTokenizer.Token t in WordTokenizer.TokenizeText(null))
{

}
}
{
foreach (var _ in WordTokenizer.TokenizeText(null))
{ }
}
);
}

Expand Down
17 changes: 7 additions & 10 deletions SIL.Core.Tests/Xml/FastXmlElementSplitterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public void SplitterFailsInvalidRootTagOnASCIIAndUTF8Files()
{
const string emptyRoot =
@"notes version='0'/>";
Assert.Throws<ArgumentException>(()=>CheckGoodFile(emptyRoot, 0, null, "annotation", Encoding.ASCII), @"Failed to detect bad ASCII file");
Assert.Throws<ArgumentException>(() => CheckGoodFile(emptyRoot, 0, null, "annotation", Encoding.ASCII), @"Failed to detect bad ASCII file");
Assert.Throws<ArgumentException>(() => CheckGoodFile(emptyRoot, 0, null, "annotation", Encoding.UTF8), @"Failed to detect bad UTF8 file");
}

Expand Down Expand Up @@ -558,7 +558,7 @@ private static void ProcessMultipleEntryContent(FastXmlElementSplitter fastXmlEl
{
var curElement = elements[i];
Assert.AreEqual(curElement.Name, expectedNames[i]);
var el = XElement.Parse(curElement.BytesAsString);
XElement.Parse(curElement.BytesAsString);
if (i >= 3) // parse the sublist for Analyses and Entries
{
using (var splitter = new FastXmlElementSplitter(curElement.Bytes))
Expand Down Expand Up @@ -610,22 +610,19 @@ private static void CheckGoodFile(string hasRecordsInput, int expectedCount, str
private static void ProcessContent(FastXmlElementSplitter fastXmlElementSplitter, int expectedCount, string firstElementMarker,
string recordMarker, Encoding enc)
{
bool foundOptionalFirstElement;
var elementBytes =
fastXmlElementSplitter.GetSecondLevelElementBytes(firstElementMarker, recordMarker, out foundOptionalFirstElement)
.ToList();
var elementBytes = fastXmlElementSplitter.GetSecondLevelElementBytes(
firstElementMarker, recordMarker, out _).ToList();
Assert.AreEqual(expectedCount, elementBytes.Count);
var elementStrings =
fastXmlElementSplitter.GetSecondLevelElementStrings(firstElementMarker, recordMarker,
out foundOptionalFirstElement).ToList();
var elementStrings = fastXmlElementSplitter.GetSecondLevelElementStrings(
firstElementMarker, recordMarker, out _).ToList();
Assert.AreEqual(expectedCount, elementStrings.Count);
for (var i = 0; i < elementStrings.Count; ++i)
{
var currentStr = elementStrings[i];
Assert.AreEqual(
currentStr,
enc.GetString(elementBytes[i]));
var el = XElement.Parse(currentStr);
XElement.Parse(currentStr);
}
}

Expand Down
6 changes: 3 additions & 3 deletions SIL.Core/ClearShare/OlacSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public void LoadWorkFromXml(Work work, string xml)

foreach (var contributor in doc.Descendants((new XElement(s_nsDc + "contributor")).Name))
{
Role role = GetRoles().ElementAt(0);
var roleCode = contributor.Attributes().Single(a => a.Name == s_nsOlac + "code").Value;
TryGetRoleByCode(roleCode, out role);
if (!TryGetRoleByCode(roleCode, out var role))
role = GetRoles().ElementAt(0);
work.Contributions.Add(new Contribution(contributor.Value, role));
}
}
Expand Down Expand Up @@ -67,7 +67,7 @@ public string GetContributorElement(string roleCode, string contributorName)
[PublicAPI]
public string GetXmlForWork(Work work)
{
var bldr = new StringBuilder();
var bldr = new StringBuilder();

if (work != null)
{
Expand Down
4 changes: 2 additions & 2 deletions SIL.Core/Reporting/UsageReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ private void MakeLaunchDateSafe( )
{
try
{
DateTime dummy = _settings.PreviousLaunchDate;
_ = _settings.PreviousLaunchDate;
}
catch
{
_settings.PreviousLaunchDate = default(DateTime);
_settings.PreviousLaunchDate = default;
}
}
/*
Expand Down
1 change: 0 additions & 1 deletion SIL.Core/Xml/XmlUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,6 @@ public static string DecodeXmlAttribute(string sInput)
/// <returns></returns>
public static string GetIndentedXml(string xml)
{
string outXml = string.Empty;
using(MemoryStream ms = new MemoryStream())
// Create a XMLTextWriter that will send its output to a memory stream (file)
using (XmlTextWriter xtw = new XmlTextWriter(ms, Encoding.Unicode))
Expand Down
7 changes: 4 additions & 3 deletions SIL.DictionaryServices.Tests/LexEntryRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,8 @@ public void GetEntriesWithSemanticDomainSortedBySemanticDomain_EntryWithoutSeman
{
using (var env = new TestEnvironment())
{
LexEntry lexEntryWithoutSemanticDomain = env.Repository.CreateItem();
// Create a LexEntry with no semantic domain.
env.Repository.CreateItem();
ResultSet<LexEntry> sortedResults = env.Repository.GetEntriesWithSemanticDomainSortedBySemanticDomain(LexSense.WellKnownProperties.SemanticDomainDdp4);
Assert.AreEqual(0, sortedResults.Count);
}
Expand Down Expand Up @@ -1217,7 +1218,7 @@ public void GetHomographNumber_AssignsUniqueNumbers()
{
using (var env = new TestEnvironment())
{
LexEntry entryOther = env.MakeEntryWithLexemeForm("en", "blue");
env.MakeEntryWithLexemeForm("en", "blue");
Assert.AreNotEqual("en", env.HeadwordWritingSystem.LanguageTag);
LexEntry[] entries = new LexEntry[3];
entries[0] = env.MakeEntryWithLexemeForm(env.HeadwordWritingSystem.LanguageTag, "blue");
Expand All @@ -1239,7 +1240,7 @@ public void GetHomographNumber_ThirdEntry_Returns3()
{
using (var env = new TestEnvironment())
{
LexEntry entryOther = env.MakeEntryWithLexemeForm("en", "blue");
env.MakeEntryWithLexemeForm("en", "blue");
Assert.AreNotEqual("en", env.HeadwordWritingSystem.LanguageTag);
LexEntry entry1 = env.MakeEntryWithLexemeForm(env.HeadwordWritingSystem.LanguageTag, "blue");
LexEntry entry2 = env.MakeEntryWithLexemeForm(env.HeadwordWritingSystem.LanguageTag, "blue");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ public void NewEntry_NoGlossNoDef_GetNeitherInTheSense()
{
Extensible extensibleInfo = new Extensible();
LexEntry e = _builder.GetOrMakeEntry(extensibleInfo, 0);
LexSense s = _builder.GetOrMakeSense(e, new Extensible(), string.Empty);
_builder.GetOrMakeSense(e, new Extensible(), string.Empty);
_builder.FinishEntry(e);
Assert.AreEqual(0,e.Senses[0].Gloss.Count);
Assert.AreEqual(0, e.Senses[0].Gloss.Count);
Assert.AreEqual(0, e.Senses[0].Definition.Count);
}

Expand Down
7 changes: 3 additions & 4 deletions SIL.DictionaryServices.Tests/Model/LexEntryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace SIL.DictionaryServices.Tests.Model
{
[TestFixture]
public class LexEntryCloneableTests:CloneableTests<LexEntry>
public class LexEntryCloneableTests : CloneableTests<LexEntry>
{
public override LexEntry CreateNewCloneable()
{
Expand Down Expand Up @@ -84,7 +84,7 @@ public void Clone_NewGuidIsCreatedAndNotZeros()
public void Clone_ClonedEntryHasId_NewIdIsCreatedForNewEntry()
{
var entry = new LexEntry();
entry.LexicalForm.SetAlternative("en","form");
entry.LexicalForm.SetAlternative("en", "form");
entry.GetOrCreateId(true);
var entry2 = entry.Clone();
Assert.That(entry2.Id, Is.Not.EqualTo(entry.Id));
Expand Down Expand Up @@ -272,7 +272,7 @@ public void GetSomeMeaningToUseInAbsenceOfHeadWord_NoGloss_GivesDefinition()
sense.Definition.SetAlternative("en", "blue");
var entry = new LexEntry();
entry.Senses.Add(sense);
Assert.AreEqual("blue",entry.GetSomeMeaningToUseInAbsenceOfHeadWord("en"));
Assert.AreEqual("blue", entry.GetSomeMeaningToUseInAbsenceOfHeadWord("en"));
}

[Test]
Expand Down Expand Up @@ -339,7 +339,6 @@ public void Cleanup_HasBaseForm_PropertyIsNotRemoved()
[Test]
public void Cleanup_HasEmptyBaseForm_PropertyIsRemoved()
{
var target = new LexEntry();
_entry = new LexEntry();
_entry.LexicalForm["v"] = "hello";
_entry.AddRelationTarget(LexEntry.WellKnownProperties.BaseForm, string.Empty);
Expand Down
19 changes: 9 additions & 10 deletions SIL.Lift.Tests/Merging/LiftChangeDetectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
using (TempFile working = new TempFile(_originalLift))
{
int howManyEntries = 10000;
Debug.WriteLine("running test using "+howManyEntries.ToString()+" entries");
Debug.WriteLine("running test using " + howManyEntries.ToString() + " entries");

Check notice

Code scanning / CodeQL

Redundant ToString() call Note test

Redundant call to 'ToString' on a String object.
using (XmlWriter w = XmlWriter.Create(working.Path))
{
w.WriteStartElement("lift");
Expand All @@ -74,7 +74,7 @@
timer.Start();
detector.Reset();
timer.Stop();
Debug.WriteLine("reset took "+timer.Elapsed.TotalSeconds+" seconds");
Debug.WriteLine("reset took " + timer.Elapsed.TotalSeconds + " seconds");

timer.Reset();
timer.Start();
Expand All @@ -88,8 +88,8 @@
{
report.GetChangeType(i.ToString());
}
timer.Stop();
Debug.WriteLine("Time to inquire about each entry " + timer.Elapsed.TotalSeconds + " seconds");
timer.Stop();
Debug.WriteLine("Time to inquire about each entry " + timer.Elapsed.TotalSeconds + " seconds");

}
}
Expand All @@ -107,10 +107,10 @@
detector.Reset();


ILiftChangeReport report = detector.GetChangeReport(null);
Assert.AreEqual(LiftChangeReport.ChangeType.None, report.GetChangeType("one"));
Assert.AreEqual(LiftChangeReport.ChangeType.None, report.GetChangeType("two"));
Assert.AreEqual(0, report.IdsOfDeletedEntries.Count);
ILiftChangeReport report = detector.GetChangeReport(null);
Assert.AreEqual(LiftChangeReport.ChangeType.None, report.GetChangeType("one"));
Assert.AreEqual(LiftChangeReport.ChangeType.None, report.GetChangeType("two"));
Assert.AreEqual(0, report.IdsOfDeletedEntries.Count);
}
}
}
Expand Down Expand Up @@ -157,9 +157,8 @@
}
using (TempFile working = new TempFile("<lift version='0.12'/>"))
{
LiftChangeDetector detector = new LiftChangeDetector(working.Path, cache);
_ = new LiftChangeDetector(working.Path, cache);
Assert.IsFalse(Directory.Exists(cache));
// Directory.Delete(cache,true);
}
}

Expand Down
Loading
Loading