Skip to content

Commit

Permalink
Add Roslyn analyzers (#76)
Browse files Browse the repository at this point in the history
Added Roslyn analyzers, and fixed raised issues.
  • Loading branch information
dalyIsaac authored Apr 22, 2022
1 parent 91cc039 commit 0aeed77
Show file tree
Hide file tree
Showing 109 changed files with 651 additions and 432 deletions.
40 changes: 38 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dotnet_style_require_accessibility_modifiers = for_non_interface_members
dotnet_style_coalesce_expression = true
dotnet_style_collection_initializer = true
dotnet_style_explicit_tuple_names = true
dotnet_style_namespace_match_folder = true
dotnet_style_namespace_match_folder = false
dotnet_style_null_propagation = true
dotnet_style_object_initializer = true
dotnet_style_operator_placement_when_wrapping = beginning_of_line
Expand Down Expand Up @@ -85,7 +85,7 @@ csharp_style_expression_bodied_constructors = false
csharp_style_expression_bodied_indexers = true
csharp_style_expression_bodied_lambdas = true
csharp_style_expression_bodied_local_functions = false
csharp_style_expression_bodied_methods = false
csharp_style_expression_bodied_methods = when_on_single_line
csharp_style_expression_bodied_operators = false
csharp_style_expression_bodied_properties = true

Expand Down Expand Up @@ -220,3 +220,39 @@ dotnet_naming_style.begins_with_i.capitalization = pascal_case

# CA1416: Validate platform compatibility
dotnet_diagnostic.CA1416.severity = silent

# CA1031: Do not catch general exception types
dotnet_diagnostic.CA1031.severity = silent

# CA2201: Do not raise reserved exception types
dotnet_diagnostic.CA2201.severity = silent

# CA1062: Validate arguments of public methods
dotnet_diagnostic.CA1062.severity = silent

# CA1725: Parameter names should match base declaration
dotnet_diagnostic.CA1725.severity = silent

# CA1014: Mark assemblies with CLSCompliant attribute
dotnet_diagnostic.CA1014.severity = none

# IDE0130: Namespace does not match folder structure
dotnet_diagnostic.IDE0130.severity = none

# IDE0078: Use pattern matching
dotnet_diagnostic.IDE0078.severity = silent

# IDE0058: Expression value is never used
dotnet_diagnostic.IDE0058.severity = silent

# IDE0046: Convert to conditional expression
dotnet_diagnostic.IDE0046.severity = silent

# IDE0022: Use expression body for methods
dotnet_diagnostic.IDE0022.severity = silent

# IDE0072: Add missing cases
dotnet_diagnostic.IDE0072.severity = silent

# IDE0010: Add missing cases
dotnet_diagnostic.IDE0010.severity = silent
8 changes: 7 additions & 1 deletion Whim.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whim.TreeLayout.Tests", "sr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whim.FloatingLayout", "src\Whim.FloatingLayout\Whim.FloatingLayout.csproj", "{636EA561-2625-4D2A-9A8A-890E5AEF18B9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whim.App", "src\Whim.App\Whim.App.csproj", "{D74F1389-F4D1-4A1C-ACE3-D91D70472DBB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whim.Runner", "src\Whim.Runner\Whim.Runner.csproj", "{D74F1389-F4D1-4A1C-ACE3-D91D70472DBB}"
ProjectSection(ProjectDependencies) = postProject
{D1CD9632-7BF6-40D3-BEE5-E6FA9BCE79CB} = {D1CD9632-7BF6-40D3-BEE5-E6FA9BCE79CB}
{636EA561-2625-4D2A-9A8A-890E5AEF18B9} = {636EA561-2625-4D2A-9A8A-890E5AEF18B9}
Expand All @@ -28,6 +28,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whim.Bar", "src\Whim.Bar\Wh
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whim.FocusIndicator", "src\Whim.FocusIndicator\Whim.FocusIndicator.csproj", "{C16D9C8A-A36E-430C-AB84-700919BC7259}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{ECA4C58D-FAF9-4F32-9C35-0555959ABFE5}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
10 changes: 10 additions & 0 deletions omnisharp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"FileOptions": {
"ExcludeSearchPatterns": [
"src/Whim.Runner/Template/whim.config.template.csx"
]
},
"RoslynExtensionsOptions": {
"EnableAnalyzersSupport": true
}
}
48 changes: 0 additions & 48 deletions src/Whim.App/Package.appxmanifest

This file was deleted.

12 changes: 3 additions & 9 deletions src/Whim.Bar/ActiveLayout/ActiveLayoutWidgetViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ActiveLayoutWidgetViewModel : INotifyPropertyChanged, IDisposable
private bool disposedValue;

private readonly HashSet<IWorkspace> _workspaces = new();
public string ActiveLayoutEngine { get => _configContext.WorkspaceManager.GetWorkspaceForMonitor(Monitor)?.ActiveLayoutEngine.Name ?? ""; }
public string ActiveLayoutEngine => _configContext.WorkspaceManager.GetWorkspaceForMonitor(Monitor)?.ActiveLayoutEngine.Name ?? "";

public System.Windows.Input.ICommand NextLayoutEngineCommand { get; }

Expand All @@ -31,17 +31,11 @@ public ActiveLayoutWidgetViewModel(IConfigContext configContext, IMonitor monito
}
}

private void WorkspaceManager_ActiveWorkspaceChanged(object? sender, EventArgs e)
{
OnPropertyChanged(nameof(ActiveLayoutEngine));
}
private void WorkspaceManager_ActiveWorkspaceChanged(object? sender, EventArgs e) => OnPropertyChanged(nameof(ActiveLayoutEngine));

public event PropertyChangedEventHandler? PropertyChanged;

protected virtual void OnPropertyChanged(string? propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
protected virtual void OnPropertyChanged(string? propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

protected virtual void Dispose(bool disposing)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Whim.Bar/ActiveLayout/NextLayoutEngineCommand.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using System;
using System.Windows.Input;

namespace Whim.Bar;

public class NextLayoutEngineCommand : System.Windows.Input.ICommand
{
private readonly IConfigContext _configContext;
private readonly ActiveLayoutWidgetViewModel _viewModel;

#pragma warning disable CS0067 // The event 'NextLayoutEngineCommand.CanExecuteChanged' is never used
public event EventHandler? CanExecuteChanged;
#pragma warning restore CS0067 // The event 'NextLayoutEngineCommand.CanExecuteChanged' is never used

public NextLayoutEngineCommand(IConfigContext configContext, ActiveLayoutWidgetViewModel viewModel)
{
Expand Down
14 changes: 14 additions & 0 deletions src/Whim.Bar/BarException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Whim.Bar;

[Serializable]
public class BarException : Exception
{
public BarException() { }
public BarException(string message) : base(message) { }
public BarException(string message, Exception inner) : base(message, inner) { }
protected BarException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
2 changes: 1 addition & 1 deletion src/Whim.Bar/BarLayoutEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public override IEnumerable<IWindowLocation> DoLayout(ILocation<int> location)
width: location.Width,
height: location.Height - height
);
return _innerLayoutEngine.DoLayout(proxiedLocation);
return InnerLayoutEngine.DoLayout(proxiedLocation);
}
}
5 changes: 2 additions & 3 deletions src/Whim.Bar/BarWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Linq;

namespace Whim.Bar;

Expand All @@ -24,7 +23,7 @@ public BarWindow(IConfigContext configContext, BarConfig barConfig, IMonitor mon
IWindow? window = Window.CreateWindow(this.GetHandle(), _configContext);
if (window == null)
{
throw new Exception("Window was unexpectedly null");
throw new BarException("Window was unexpectedly null");
}

int leftMargin = (int)_barConfig.Margin.Left;
Expand Down
2 changes: 1 addition & 1 deletion src/Whim.Bar/DateTime/DateTimeWidgetViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DateTimeWidgetViewModel : INotifyPropertyChanged, IDisposable
private readonly string _format;
private bool disposedValue;

public string Value { get => DateTime.Now.ToString(_format); }
public string Value => DateTime.Now.ToString(_format);

public DateTimeWidgetViewModel(int interval, string format)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Whim.Bar/FocusedWindow/FocusedWindowWidgetViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class FocusedWindowWidgetViewModel : INotifyPropertyChanged, IDisposable
private readonly IConfigContext _configContext;
private bool disposedValue;

public string? Value { get => _configContext.WorkspaceManager.ActiveWorkspace.LastFocusedWindow?.Title; }
public string? Value => _configContext.WorkspaceManager.ActiveWorkspace.LastFocusedWindow?.Title;

public FocusedWindowWidgetViewModel(IConfigContext configContext)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Whim.Bar/Text/TextWidgetViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ public class TextWidgetViewModel : INotifyPropertyChanged
private string _value;
public string Value
{
get
{
return _value;
}
get => _value;
set
{
if (_value != value)
Expand Down
13 changes: 13 additions & 0 deletions src/Whim.Bar/Whim.Bar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
<Nullable>enable</Nullable>
<Platforms>x86;x64;arm64</Platforms>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisModeDesign>All</AnalysisModeDesign>
<AnalysisModeDocumentation>All</AnalysisModeDocumentation>
<AnalysisModeGlobalization>None</AnalysisModeGlobalization>
<AnalysisModeInteroperability>All</AnalysisModeInteroperability>
<AnalysisModeMaintainability>All</AnalysisModeMaintainability>
<AnalysisModeNaming>All</AnalysisModeNaming>
<AnalysisModePerformance>All</AnalysisModePerformance>
<AnalysisModeSingleFile>All</AnalysisModeSingleFile>
<AnalysisModeReliability>All</AnalysisModeReliability>
<AnalysisModeSecurity>All</AnalysisModeSecurity>
<AnalysisModeStyle>All</AnalysisModeStyle>
<AnalysisModeUsage>All</AnalysisModeUsage>
</PropertyGroup>
<ItemGroup>
<None Remove="BarWindow.xaml" />
Expand Down
3 changes: 2 additions & 1 deletion src/Whim.Bar/Workspace/SwitchWorkspaceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public SwitchWorkspaceCommand(IConfigContext configContext, WorkspaceWidgetViewM

private void Workspace_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(_workspace.ActiveOnMonitor)) {
if (e.PropertyName == nameof(_workspace.ActiveOnMonitor))
{
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Whim.FloatingLayout/FloatingLayoutConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ public class FloatingLayoutConfig

public void MarkWindowAsFloating(IWindow window)
{
Logger.Debug($"Marking window {window} as floating");
_floatingWindows.Add(window);
}

public void MarkWindowAsDocked(IWindow window)
{
Logger.Debug($"Marking window {window} as docked");
_floatingWindows.Remove(window);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Whim.FloatingLayout/FloatingLayoutEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override IEnumerable<IWindowLocation> DoLayout(ILocation<int> location)
}

// Iterate over all windows in the inner layout engine.
foreach (IWindowLocation windowLocation in _innerLayoutEngine.DoLayout(location))
foreach (IWindowLocation windowLocation in InnerLayoutEngine.DoLayout(location))
{
yield return windowLocation;
}
Expand All @@ -44,7 +44,7 @@ public override void AddWindowAtPoint(IWindow window, IPoint<double> point, bool
}

// Pass to the inner layout engine.
_innerLayoutEngine.AddWindowAtPoint(window, point);
InnerLayoutEngine.AddWindowAtPoint(window, point);
}

public void MarkWindowAsFloating(IWindow? window = null)
Expand All @@ -54,7 +54,7 @@ public void MarkWindowAsFloating(IWindow? window = null)

if (window != null)
{
_innerLayoutEngine.Remove(window);
InnerLayoutEngine.Remove(window);
UpdateFloatingWindow(window);
_floatingLayoutConfig.MarkWindowAsFloating(window);
}
Expand All @@ -67,7 +67,7 @@ public void MarkWindowAsDocked(IWindow? window = null)

if (window != null)
{
_innerLayoutEngine.Add(window);
InnerLayoutEngine.Add(window);
_windowToLocation.Remove(window);
_floatingLayoutConfig.MarkWindowAsDocked(window);
}
Expand Down
13 changes: 13 additions & 0 deletions src/Whim.FloatingLayout/Whim.FloatingLayout.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
<Nullable>enable</Nullable>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<Platforms>x86;x64;arm64</Platforms>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisModeDesign>All</AnalysisModeDesign>
<AnalysisModeDocumentation>All</AnalysisModeDocumentation>
<AnalysisModeGlobalization>None</AnalysisModeGlobalization>
<AnalysisModeInteroperability>All</AnalysisModeInteroperability>
<AnalysisModeMaintainability>All</AnalysisModeMaintainability>
<AnalysisModeNaming>All</AnalysisModeNaming>
<AnalysisModePerformance>All</AnalysisModePerformance>
<AnalysisModeSingleFile>All</AnalysisModeSingleFile>
<AnalysisModeReliability>All</AnalysisModeReliability>
<AnalysisModeSecurity>All</AnalysisModeSecurity>
<AnalysisModeStyle>All</AnalysisModeStyle>
<AnalysisModeUsage>All</AnalysisModeUsage>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Whim.FocusIndicator/FocusIndicatorConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public bool IsVisible
/// When <see langword="true"/>, the focus indicator will be visible for
/// <see cref="FadeTimeout"/>.
/// </summary>
public bool FadeEnabled { get; set; } = false;
public bool FadeEnabled { get; set; }

/// <summary>
/// The amount of time that the focus indicator will be visible, when
Expand Down
14 changes: 14 additions & 0 deletions src/Whim.FocusIndicator/FocusIndicatorException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Whim.FocusIndicator;

[Serializable]
public class FocusIndicatorException : Exception
{
public FocusIndicatorException() { }
public FocusIndicatorException(string message) : base(message) { }
public FocusIndicatorException(string message, Exception inner) : base(message, inner) { }
protected FocusIndicatorException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
Loading

0 comments on commit 0aeed77

Please sign in to comment.