Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Jul 20, 2024
1 parent d53a900 commit b6014ce
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 37 deletions.
6 changes: 3 additions & 3 deletions OneMore/Commands/Edit/AlterSizeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public int AlterQuickStyles(Page page)
? Math.Max(size + delta, MinFontSize)
: Math.Min(size + delta, MaxFontSize);

if (!result.Equalsish(size))
if (!result.EstEquals(size))
{
attr.Value = $"{result:#0}.05";
count++;
Expand Down Expand Up @@ -139,7 +139,7 @@ private int AlterByName(XElement outline)
? Math.Max(size + delta, MinFontSize)
: Math.Min(size + delta, MaxFontSize);

if (!result.Equalsish(size))
if (!result.EstEquals(size))
{
attr.Value = $"{result:#0}.05";
count++;
Expand Down Expand Up @@ -251,7 +251,7 @@ private bool UpdateSpanStyle(XElement span)
? Math.Max(size + delta, MinFontSize)
: Math.Min(size + delta, MaxFontSize);

if (!result.Equalsish(size))
if (!result.EstEquals(size))
{
properties["font-size"] = $"{result:#0}.05pt";

Expand Down
15 changes: 9 additions & 6 deletions OneMore/Commands/File/Markdown/MarkdownWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task Copy(XElement content)
using var stream = new MemoryStream();
using (writer = new StreamWriter(stream))
{
writer.WriteLine($"# {page.Title}");
await writer.WriteLineAsync($"# {page.Title}");

if (content.Name.LocalName == "Page")
{
Expand All @@ -87,14 +87,14 @@ public async Task Copy(XElement content)
.ForEach(e => Write(e));
}

writer.WriteLine();
writer.Flush();
await writer.WriteLineAsync();
await writer.FlushAsync();

stream.Position = 0;
using var reader = new StreamReader(stream);

var clippy = new ClipboardProvider();
var success = await clippy.SetText(reader.ReadToEnd(), true);
var success = await clippy.SetText(await reader.ReadToEndAsync(), true);
if (!success)
{
MoreMessageBox.ShowError(null, Resx.Clipboard_locked);
Expand Down Expand Up @@ -256,8 +256,11 @@ private void Stylize(string prefix)
var quick = quickStyles.First(q => q.Index == context.QuickStyleIndex);
switch (quick.Name)
{
case "PageTitle": writer.Write("# "); break;
case "h1": writer.Write("# "); break;
case "PageTitle":
case "h1":
writer.Write("# ");
break;

case "h2": writer.Write("## "); break;
case "h3": writer.Write("### "); break;
case "h4": writer.Write("#### "); break;
Expand Down
4 changes: 3 additions & 1 deletion OneMore/Commands/File/PluginDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ internal partial class PluginDialog : MoreForm
{
private string[] predefinedNames;
private Plugin plugin;
private bool initializing = true;
private bool initializing;
private readonly bool single = false;


public PluginDialog()
{
initializing = true;

InitializeComponent();

// sectionGroup is not visible by default but sits in same location as pageGroup
Expand Down
8 changes: 4 additions & 4 deletions OneMore/Commands/Images/ImageEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public ImageEditor()


public bool IsReady =>
Brightness != float.MinValue ||
Contrast != float.MinValue ||
Opacity != float.MinValue ||
!Brightness.EstEquals(float.MinValue) ||
!Contrast.EstEquals(float.MinValue) ||
!Opacity.EstEquals(float.MinValue) ||
Quality != long.MinValue ||
Saturation != float.MinValue ||
!Saturation.EstEquals(float.MinValue) ||
Size != Size.Empty ||
Style != Stylization.None;

Expand Down
2 changes: 1 addition & 1 deletion OneMore/Commands/References/HyperlinkProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private async Task BuildHyperlinkMap(
// $"element:{element.Name.LocalName}={ea?.Value} " +
// $"path:{path}");

var p = string.IsNullOrEmpty(path) ? ea?.Value : $"{path}/{ea?.Value}";
var p = string.IsNullOrEmpty(path) ? ea.Value : $"{path}/{ea.Value}";

await BuildHyperlinkMap(
hyperlinks, element,
Expand Down
2 changes: 1 addition & 1 deletion OneMore/Commands/Tables/Formulas/MathFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private static double StandardDeviation(double[] values)
{
var variance = Variance(values);

if (variance == 0.0)
if (variance.EstEquals(0.0, double.Epsilon))
return 0.0;

return Math.Sqrt(variance);
Expand Down
3 changes: 2 additions & 1 deletion OneMore/Commands/Tools/UpdateDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ private string FormatDate(string value)
}
else
{
if (DateTime.TryParse(value, out var date))
if (DateTime.TryParse(value,
DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None, out var date))
{
return date.ToShortDateString();
}
Expand Down
8 changes: 4 additions & 4 deletions OneMore/Commands/Tools/Updater/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public async Task<bool> Update()
using var response = await client.GetAsync(asset.browser_download_url);
using var stream = await response.Content.ReadAsStreamAsync();
using var file = File.OpenWrite(msi);
stream.CopyTo(file);
await stream.CopyToAsync(file);
}
catch (Exception exc)
{
Expand All @@ -193,12 +193,12 @@ public async Task<bool> Update()
var shutdown = $"start /b \"\" \"{action}\" --uninstall-shutdown";

using var writer = new StreamWriter(path, false);
writer.WriteLine(shutdown);
writer.WriteLine(msi);
await writer.WriteLineAsync(shutdown);
await writer.WriteLineAsync(msi);
#if DebugUpdater
writer.WriteLine("set /p \"continue: \""); // for debugging
#endif
writer.Flush();
await writer.FlushAsync();
writer.Close();

// run installer script
Expand Down
18 changes: 17 additions & 1 deletion OneMore/Helpers/Extensions/DoubleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,23 @@ internal static class DoubleExtensions
/// font size comparisons, our most common use case in OneMore
/// </param>
/// <returns>True if the two values are within the specified epsilon difference</returns>
public static bool Equalsish(this double a, double b, double epsilon = 0.5)
public static bool EstEquals(this double a, double b, double epsilon = 0.5)
{
return Math.Abs(a - b) < epsilon;
}


/// <summary>
/// OneMore Extension >> Compares two Floats with a specified epsilon window.
/// </summary>
/// <param name="a">This Float</param>
/// <param name="b">That Float</param>
/// <param name="epsilon">
/// The fudge factor for comparison. This defaults to Float.Epsilon, the smallest
/// viable vaiance window for comparison.
/// </param>
/// <returns>True if the two values are within the specified epsilon difference</returns>
public static bool EstEquals(this float a, float b, float epsilon = float.Epsilon)
{
return Math.Abs(a - b) < epsilon;
}
Expand Down
2 changes: 1 addition & 1 deletion OneMore/UI/MoreButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void Rescale()
{
// special-case handling for 96 DPI monitors
(float dpiX, _) = UI.Scaling.GetDpiValues();
if (Math.Floor(dpiX) == 96)
if (Math.Floor(dpiX).EstEquals(96.0))
{
if (BackgroundImage != null)
{
Expand Down
9 changes: 4 additions & 5 deletions OneMore/UI/ProgressDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ public DialogResult ShowDialogWithCancel(

source ??= new CancellationTokenSource();

DialogResult result = DialogResult.Cancel;

try
{
// process should run in an STA thread otherwise it will conflict with
Expand Down Expand Up @@ -160,22 +158,23 @@ public DialogResult ShowDialogWithCancel(
thread.IsBackground = true;
thread.Start();

result = ShowDialog();
var result = ShowDialog();

if (result == DialogResult.Cancel)
{
logger.WriteLine("clicked cancel");
source.Cancel();
thread.Abort();
return result;
}

return result;
}
catch (Exception exc)
{
logger.WriteLine("error importing", exc);
}

return result;
return DialogResult.Cancel;
}


Expand Down
2 changes: 1 addition & 1 deletion OneMore/UI/Scaling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static (float, float) GetDpiValues()
/// <returns>A Tuple with xScalingFactor and yScalingFactor</returns>
public static (float, float) GetScalingFactors()
{
if (xScalingFactor == 0 && yScalingFactor == 0)
if (xScalingFactor.EstEquals(0) && yScalingFactor.EstEquals(0))
{
using var g = Graphics.FromHwnd(IntPtr.Zero);
IntPtr desktop = g.GetHdc();
Expand Down
8 changes: 4 additions & 4 deletions OneMore/UI/TagPickerDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ public void Select(int symbol)

private void pictureBox_MouseMove(object sender, MouseEventArgs e)
{
var mouseX = xScalingFactor == 0.0 ? e.X : (int)Math.Round(e.X / xScalingFactor);
var mouseY = yScalingFactor == 0.0 ? e.Y : (int)Math.Round(e.Y / yScalingFactor);
var mouseX = xScalingFactor.EstEquals(0f) ? e.X : (int)Math.Round(e.X / xScalingFactor);
var mouseY = yScalingFactor.EstEquals(0f) ? e.Y : (int)Math.Round(e.Y / yScalingFactor);

var zone = zones.Find(z =>
mouseX >= z.Bounds.Left && mouseX <= z.Bounds.Right &&
Expand Down Expand Up @@ -311,8 +311,8 @@ private void pictureBox_MouseMove(object sender, MouseEventArgs e)

private void pictureBox_MouseUp(object sender, MouseEventArgs e)
{
var mouseX = xScalingFactor == 0.0 ? e.X : (int)Math.Round(e.X / xScalingFactor);
var mouseY = yScalingFactor == 0.0 ? e.Y : (int)Math.Round(e.Y / yScalingFactor);
var mouseX = xScalingFactor.EstEquals(0f) ? e.X : (int)Math.Round(e.X / xScalingFactor);
var mouseY = yScalingFactor.EstEquals(0f) ? e.Y : (int)Math.Round(e.Y / yScalingFactor);

var zone = zones.Find(z =>
mouseX >= z.Bounds.Left && mouseX <= z.Bounds.Right &&
Expand Down
11 changes: 7 additions & 4 deletions OneMoreCalendar/OneNoteProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace OneMoreCalendar
using River.OneMoreAddIn.Models;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -69,8 +70,8 @@ public async Task<CalendarPages> GetPages(
.Select(e => new
{
Page = e,
Created = DateTime.Parse(e.Attribute("dateTime").Value),
Modified = DateTime.Parse(e.Attribute("lastModifiedTime").Value),
Created = DateTime.Parse(e.Attribute("dateTime").Value, DateTimeFormatInfo.CurrentInfo),
Modified = DateTime.Parse(e.Attribute("lastModifiedTime").Value, DateTimeFormatInfo.CurrentInfo),
IsDeleted = e.Attribute("isInRecycleBin") != null
})
// filter by one or both filters
Expand Down Expand Up @@ -208,8 +209,10 @@ public async Task<IEnumerable<int>> GetYears(IEnumerable<string> notebookIDs)
var pages = notebooks.Descendants(ns + "Page");

var years = pages
.Select(p => DateTime.Parse(p.Attribute("dateTime").Value).Year)
.Union(pages.Select(p => DateTime.Parse(p.Attribute("lastModifiedTime").Value).Year))
.Select(p => DateTime.Parse(
p.Attribute("dateTime").Value, DateTimeFormatInfo.CurrentInfo).Year)
.Union(pages.Select(p => DateTime.Parse(
p.Attribute("lastModifiedTime").Value, DateTimeFormatInfo.CurrentInfo).Year))
.Distinct()
.OrderByDescending(y => y);

Expand Down

0 comments on commit b6014ce

Please sign in to comment.