Skip to content

Commit

Permalink
Resharper Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pmachapman committed May 25, 2022
1 parent 1da499d commit 3ae4d6b
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 86 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,11 @@ dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent

[*.{cs,vb}]
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
16 changes: 12 additions & 4 deletions GoToBible.Model/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public static PassageReference AsPassageReference(this string passage, int defau

// Set the chapter reference
book = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(book);
passageReference.ChapterReference = new ChapterReference(book, chapter);
passageReference = new PassageReference { ChapterReference = new ChapterReference(book, chapter) };

// Do not highlight the first verse of a one chapter book if there is no colon and there is not a range of verses
bool highlightVerses = sanitisedPassage.Contains(':', StringComparison.OrdinalIgnoreCase) && chapter > 0;
Expand Down Expand Up @@ -339,12 +339,20 @@ public static PassageReference AsPassageReference(this string passage, int defau
}

// Set the display and highlighted verses
passageReference.Display = $"{book} {chapter}:{sb}";
passageReference.HighlightedVerses = highlightedVerses.ToArray();
passageReference = new PassageReference
{
ChapterReference = passageReference.ChapterReference,
Display = $"{book} {chapter}:{sb}",
HighlightedVerses = highlightedVerses.ToArray(),
};
}
else
{
passageReference.Display = $"{book} {chapter}";
passageReference = new PassageReference
{
ChapterReference = passageReference.ChapterReference,
Display = $"{book} {chapter}",
};
}

break;
Expand Down
14 changes: 7 additions & 7 deletions GoToBible.Model/PassageReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ namespace GoToBible.Model
/// <summary>
/// A passage reference.
/// </summary>
public record PassageReference : IEquatable<PassageReference>
public record PassageReference
{
/// <summary>
/// Gets or sets the chapter reference.
/// Gets the chapter reference.
/// </summary>
/// <value>
/// The chapter reference.
/// </value>
public ChapterReference ChapterReference { get; set; } = new ChapterReference();
public ChapterReference ChapterReference { get; init; } = new ChapterReference();

/// <summary>
/// Gets or sets the passage reference to display.
/// Gets the passage reference to display.
/// </summary>
/// <value>
/// The passage reference.
/// </value>
public string Display { get; set; } = string.Empty;
public string Display { get; init; } = string.Empty;

/// <summary>
/// Gets or sets the highlighted verses.
/// Gets the highlighted verses.
/// </summary>
/// <value>
/// The verses to highlight.
Expand All @@ -45,7 +45,7 @@ public record PassageReference : IEquatable<PassageReference>
/// i.e. <c>24g,-,25</c>
/// but not colons, commas, or any other characters.
/// </remarks>
public string[] HighlightedVerses { get; set; } = Array.Empty<string>();
public string[] HighlightedVerses { get; init; } = Array.Empty<string>();

/// <summary>
/// Gets a value indicating whether this instance is valid.
Expand Down
10 changes: 1 addition & 9 deletions GoToBible.Providers/BibliaApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,7 @@ public override async Task<Chapter> GetChapterAsync(string translation, string b
};

// If there is only one chapter, do not use a chapter number
string chapterPart;
if (Canon.GetNumberOfChapters(book) == 1)
{
chapterPart = string.Empty;
}
else
{
chapterPart = $"+{chapterNumber}";
}
string chapterPart = Canon.GetNumberOfChapters(book) == 1 ? string.Empty : $"+{chapterNumber}";

// Load the book
string url = $"content/{translation}.txt?key={this.options.ApiKey}&passage={book}{chapterPart}&eachVerse=[VerseNum]++[VerseText]\\n";
Expand Down
9 changes: 0 additions & 9 deletions GoToBible.Providers/BookHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,6 @@ public ChapterReference GetPreviousChapter(string book, int chapter)
return new ChapterReference();
}

/// <summary>
/// Determines whether this instance has the specified book.
/// </summary>
/// <param name="book">The book.</param>
/// <returns>
/// <c>true</c> if this instance has the specified book; otherwise, <c>false</c>.
/// </returns>
public bool HasBook(string book) => this.BookChapters.Contains(book.ToLowerInvariant());

/// <summary>
/// Determines whether the specified book contains the specified chapter.
/// </summary>
Expand Down
19 changes: 7 additions & 12 deletions GoToBible.Providers/DigitalBiblePlatformApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ namespace GoToBible.Providers
/// <seealso cref="GoToBible.Providers.ApiProvider" />
public class DigitalBiblePlatformApi : ApiProvider
{
/// <summary>
/// The new testament canon.
/// </summary>
private static readonly BookHelper NewTestamentCanon = new NewTestamentCanon();

/// <summary>
/// The options.
/// </summary>
Expand Down Expand Up @@ -88,7 +83,7 @@ public override async IAsyncEnumerable<Book> GetBooksAsync(string translation, b
}),
});

if (bookData?.data?.Any() ?? false)
if (bookData?.data.Any() ?? false)
{
foreach (var book in bookData.data)
{
Expand Down Expand Up @@ -269,7 +264,7 @@ public override async IAsyncEnumerable<Translation> GetTranslationsAsync()
// Clean up the JSON
json = json.Replace("\"dbp-prod\"", "\"dbp_prod\"", StringComparison.Ordinal);

var translations = DeserializeAnonymousType(json, new
var dbpTranslations = DeserializeAnonymousType(json, new
{
data = EmptyListOf(new
{
Expand All @@ -295,14 +290,14 @@ public override async IAsyncEnumerable<Translation> GetTranslationsAsync()
},
},
});
if (translations is not null)
if (dbpTranslations is not null)
{
// Set page variables
lastPage = translations.meta.pagination.last_page;
page = translations.meta.pagination.current_page;
lastPage = dbpTranslations.meta.pagination.last_page;
page = dbpTranslations.meta.pagination.current_page;

List<DigitalBiblePlatformTranslation> digitalBiblePlatformTranslations = new List<DigitalBiblePlatformTranslation>();
foreach (var translation in translations.data)
foreach (var translation in dbpTranslations.data)
{
// Get the name
string name;
Expand Down Expand Up @@ -403,7 +398,7 @@ private async Task<string> GetCopyright(string id)

if (copyrightJson?.Any() ?? false)
{
copyright = copyrightJson.FirstOrDefault(c => c.id == id)?.copyright?.copyright ?? copyrightJson.First().copyright.copyright;
copyright = copyrightJson.FirstOrDefault(c => c.id == id)?.copyright.copyright ?? copyrightJson.First().copyright.copyright;
}
}

Expand Down
10 changes: 1 addition & 9 deletions GoToBible.Providers/EsvBible.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,7 @@ public override async Task<Chapter> GetChapterAsync(string translation, string b
};

// If there is only one chapter, do not use a chapter number
string chapterPart;
if (Canon.GetNumberOfChapters(book) == 1)
{
chapterPart = string.Empty;
}
else
{
chapterPart = $"+{chapterNumber}";
}
string chapterPart = Canon.GetNumberOfChapters(book) == 1 ? string.Empty : $"+{chapterNumber}";

// Load the book
string url = $"?q={book}{chapterPart}&include-passage-references=false&include-footnotes=false&include-headings=false&include-short-copyright=false&indent-poetry=false";
Expand Down
18 changes: 11 additions & 7 deletions GoToBible.Tests.Model/ExtensionMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ public void TestAsUrl_RenderingParametersEmpty()
[TestMethod]
public void TestAsUrl_RenderingParametersOneTranslation()
{
RenderingParameters renderingParameters = new RenderingParameters();
renderingParameters.PassageReference.Display = "1 John 1:3,6-7";
renderingParameters.PrimaryTranslation = "ESV";
RenderingParameters renderingParameters = new RenderingParameters
{
PassageReference = new PassageReference { Display = "1 John 1:3,6-7" },
PrimaryTranslation = "ESV",
};
Assert.AreEqual(new Uri("https://goto.bible/1.John.1_3~6-7/ESV"), renderingParameters.AsUrl());
}

Expand All @@ -172,10 +174,12 @@ public void TestAsUrl_RenderingParametersOneTranslation()
[TestMethod]
public void TestAsUrl_RenderingParametersTwoTranslations()
{
RenderingParameters renderingParameters = new RenderingParameters();
renderingParameters.PassageReference.Display = "1 John 1:3,6-7";
renderingParameters.PrimaryTranslation = "ESV";
renderingParameters.SecondaryTranslation = "NET";
RenderingParameters renderingParameters = new RenderingParameters
{
PassageReference = new PassageReference { Display = "1 John 1:3,6-7" },
PrimaryTranslation = "ESV",
SecondaryTranslation = "NET",
};
Assert.AreEqual(new Uri("https://goto.bible/1.John.1_3~6-7/ESV/NET"), renderingParameters.AsUrl());
}

Expand Down
6 changes: 3 additions & 3 deletions GoToBible.Web/Server/Controllers/RenderPassageController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public async Task<IActionResult> Post(RenderingParameters parameters, bool rende
{
try
{
StatisticsContext context = this.context!;
StatisticsContext statisticsContext = this.context!;
Statistics statistics = new Statistics
{
AccessedAt = DateTime.UtcNow,
Expand All @@ -86,8 +86,8 @@ public async Task<IActionResult> Post(RenderingParameters parameters, bool rende
SecondaryProvider = parameters.SecondaryProvider,
SecondaryTranslation = parameters.SecondaryTranslation,
};
await context.Statistics.AddAsync(statistics);
await context.SaveChangesAsync();
await statisticsContext.Statistics.AddAsync(statistics);
await statisticsContext.SaveChangesAsync();
}
catch (Exception ex)
{
Expand Down
4 changes: 2 additions & 2 deletions GoToBible.Windows/AutoComplete/SourceCustomList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class SourceCustomList : IEnumString
/// <summary>
/// The current position.
/// </summary>
private int currentPosition = 0;
private int currentPosition;

/// <summary>
/// Gets the string list.
Expand All @@ -33,7 +33,7 @@ public class SourceCustomList : IEnumString
public int Next(int celt, string[] rgelt, IntPtr pceltFetched)
{
int fetched = 0;
while ((this.currentPosition <= this.StringList.Length - 1) && (fetched < celt))
while (this.currentPosition <= this.StringList.Length - 1 && fetched < celt)
{
rgelt[fetched] = this.StringList[this.currentPosition];
fetched++;
Expand Down
13 changes: 3 additions & 10 deletions GoToBible.Windows/FormCheckBoxList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public partial class FormCheckBoxList : Form
/// <summary>
/// A value indicating whether the check box list is updating.
/// </summary>
private bool checkBoxListIsUpdating = false;
private bool checkBoxListIsUpdating;

/// <summary>
/// A value indicating whether the select all check box is updating.
/// </summary>
private bool selectAllCheckBoxIsUpdating = false;
private bool selectAllCheckBoxIsUpdating;

/// <summary>
/// The tool tip index.
Expand Down Expand Up @@ -232,14 +232,7 @@ private void UpdateCheckBoxSelectAll(bool? checkOn = null)
{
this.CheckBoxSelectAll.Text = @"&Select All";
this.ToolTipItem.SetToolTip(this.CheckBoxSelectAll, $"{this.CheckedListBoxItems.Items.Count} items");
if (checkedCount == 0)
{
this.CheckBoxSelectAll.CheckState = CheckState.Unchecked;
}
else
{
this.CheckBoxSelectAll.CheckState = CheckState.Indeterminate;
}
this.CheckBoxSelectAll.CheckState = checkedCount == 0 ? CheckState.Unchecked : CheckState.Indeterminate;
}

this.selectAllCheckBoxIsUpdating = false;
Expand Down
32 changes: 20 additions & 12 deletions GoToBible.Windows/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ public partial class FormMain : Form
/// <summary>
/// A value indicating whether or not the translations are loaded.
/// </summary>
private bool translationsLoaded = false;
private bool translationsLoaded;

/// <summary>
/// A value indicating whether or not the web view is initialised.
/// </summary>
private bool webViewInitialised = false;
private bool webViewInitialised;

/// <summary>
/// Initialises a new instance of the <see cref="FormMain" /> class.
Expand Down Expand Up @@ -463,12 +463,20 @@ private async Task InitialiseWebBrowser(bool removeExisting)

// Setup the main web browser
webViewMain.Initialise("WebViewMain", 1);
this.SplitContainerMain.Panel1.Controls.Add(webViewMain as Control);
if (webViewMain is Control webViewMainControl)
{
this.SplitContainerMain.Panel1.Controls.Add(webViewMainControl);
}

this.WebViewMain = webViewMain;

// Setup the resource web browser
webViewResource.Initialise("WebViewResource", 2);
this.SplitContainerMain.Panel2.Controls.Add(webViewResource as Control);
if (webViewResource is Control webViewResourceControl)
{
this.SplitContainerMain.Panel2.Controls.Add(webViewResourceControl);
}

this.WebViewResource = webViewResource;

// Resume the layouts
Expand Down Expand Up @@ -696,28 +704,28 @@ private async Task LoadTranslationComboBoxes(IList<IProvider> translationProvide
List<string> blockedLanguages = Settings.Default.BlockedLanguages?.Cast<string>().ToList() ?? new List<string>();
List<string> blockedTranslations = Settings.Default.BlockedTranslations?.Cast<string>().ToList() ?? new List<string>();
List<string> blockedCommentaries = Settings.Default.BlockedCommentaries?.Cast<string>().ToList() ?? new List<string>();
List<Translation> commentaries = new List<Translation>();
List<Translation> translations = new List<Translation>();
List<Translation> unsortedCommentaries = new List<Translation>();
List<Translation> unsortedTranslations = new List<Translation>();
foreach (IProvider provider in translationProviders)
{
await foreach (Translation translation in provider.GetTranslationsAsync())
{
if (translation.Commentary)
{
commentaries.Add(translation);
unsortedCommentaries.Add(translation);
}
else
{
translations.Add(translation);
unsortedTranslations.Add(translation);
}
}
}

// Store the translations for use by other methods
this.translations.Clear();
this.translations.AddRange(translations.OrderBy(t => t.Language, new LanguageComparer()).ThenBy(t => t.Name));
this.translations.AddRange(unsortedTranslations.OrderBy(t => t.Language, new LanguageComparer()).ThenBy(t => t.Name));
this.commentaries.Clear();
this.commentaries.AddRange(commentaries.OrderBy(t => t.Name));
this.commentaries.AddRange(unsortedCommentaries.OrderBy(t => t.Name));
this.ToolStripMenuItemConfigure.Enabled = true;

// Load the commentaries and translations from the providers
Expand Down Expand Up @@ -909,8 +917,8 @@ private async void ToolStripButtonExport_Click(object sender, EventArgs e)
if (this.SaveFileDialogMain.ShowDialog() == DialogResult.OK)
{
// Render for export to Accordance
RenderedPassage renderedPassage = await this.renderer.RenderAsync(this.parameters with { Format = RenderFormat.Accordance }, false);
await File.WriteAllTextAsync(this.SaveFileDialogMain.FileName, renderedPassage.Content);
RenderedPassage renderedPassageForExport = await this.renderer.RenderAsync(this.parameters with { Format = RenderFormat.Accordance }, false);
await File.WriteAllTextAsync(this.SaveFileDialogMain.FileName, renderedPassageForExport.Content);
}
}

Expand Down
1 change: 0 additions & 1 deletion GoToBible.Windows/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace GoToBible.Windows
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.Versioning;
using System.Windows.Forms;
Expand Down
1 change: 0 additions & 1 deletion GoToBible.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
<s:Boolean x:Key="/Default/CodeEditing/TypingAssist/SurroundTypingEnabled/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Browsers/Browsers/@EntryValue">C91+,E91+,FF89+,IE11+,O75+,S14+</s:String>
<s:String x:Key="/Default/CodeInspection/JsInspections/LanguageLevel/@EntryValue">Experimental</s:String>
<s:Boolean x:Key="/Default/InstalledDictionaries/InstalledDictionaries/=GoTo_002EBible_005Cnode_005Fmodules_005Cdictionary_002Den_002Dau_005Cindex_002Edic/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/ReSpeller/ReSpellerEnabled/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Conglomo/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

0 comments on commit 3ae4d6b

Please sign in to comment.