diff --git a/Directory.Build.props b/Directory.Build.props index b04bbeb..8b34486 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -6,5 +6,6 @@ $(BaseOutputPath)/$(MSBuildProjectName)/bin $(BaseIntermediateOutputPath)/$(MSBuildProjectName)/obj $(BaseIntermediateOutputPath)/$(MSBuildProjectName)/obj + true \ No newline at end of file diff --git a/SonarqubleAnalyzer.props b/SonarqubleAnalyzer.props new file mode 100644 index 0000000..43a4aff --- /dev/null +++ b/SonarqubleAnalyzer.props @@ -0,0 +1,8 @@ + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + \ No newline at end of file diff --git a/dot.sln b/dot.sln index 7375515..a06fe81 100644 --- a/dot.sln +++ b/dot.sln @@ -27,6 +27,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "meta", "meta", "{AD79881E-7 README.md = README.md README.zh-CN.md = README.zh-CN.md SafetyDelUnusedResx.ahk = SafetyDelUnusedResx.ahk + SonarqubleAnalyzer.props = SonarqubleAnalyzer.props switch-nuget.cmd = switch-nuget.cmd switch-project.cmd = switch-project.cmd switcher.json = switcher.json diff --git a/src/Color/MouseHook.cs b/src/Color/MouseHook.cs index 7101ecc..4bd7084 100644 --- a/src/Color/MouseHook.cs +++ b/src/Color/MouseHook.cs @@ -6,15 +6,11 @@ using System.Runtime.InteropServices; namespace Dot.Color; -internal class MouseHook : IDisposable +internal sealed class MouseHook : IDisposable { [StructLayout(LayoutKind.Explicit)] private struct Msllhookstruct { - // [FieldOffset(20)] private readonly nint dwExtraInfo; - // [FieldOffset(12)] private readonly uint flags; - // [FieldOffset(8)] private readonly uint mouseData; - // [FieldOffset(16)] private readonly uint time; [FieldOffset(0)] public readonly int X; [FieldOffset(4)] public readonly int Y; } @@ -42,7 +38,9 @@ internal class MouseHook : IDisposable private void Dispose(bool disposing) { if (_disposed) return; + #pragma warning disable S108 if (disposing) { } + #pragma warning restore S108 if (_hookId != default) Win32.UnhookWindowsHookEx(_hookId); _disposed = true; diff --git a/src/CsxEditor.cs b/src/CsxEditor.cs index 9e0d99a..b87f5d7 100644 --- a/src/CsxEditor.cs +++ b/src/CsxEditor.cs @@ -1,8 +1,4 @@ -using System; using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Threading.Tasks; namespace Dot; diff --git a/src/FilesTool.cs b/src/FilesTool.cs index 415894f..e8b20bc 100644 --- a/src/FilesTool.cs +++ b/src/FilesTool.cs @@ -1,5 +1,6 @@ using System.Collections.Concurrent; using System.Text.RegularExpressions; +// ReSharper disable once RedundantUsingDirective using Panel = Spectre.Console.Panel; namespace Dot; @@ -11,43 +12,15 @@ internal abstract class FilesTool : ToolBase where TOption : D private int _excludeCnt; //排除文件数 // ReSharper disable once StaticMemberInGenericType + #pragma warning disable S2743 private static readonly object _lock = new(); //线程锁 private int _readCnt; //读取文件数 private int _totalCnt; //总文件数 private int _writeCnt; //写入文件数 private readonly ConcurrentDictionary _writeStats = new(); //写入统计:后缀,数量 - - // ReSharper disable once ReturnTypeCanBeEnumerable.Local - private string[] EnumerateFiles(string path, string searchPattern, out int excludeCnt) + private async Task CoreInternal() { - var exCnt = 0; - if (Opt.ExcludeRegexes?.FirstOrDefault() is null) //默认排除.git 、 node_modules 目录 - Opt.ExcludeRegexes = new[] { @"\.git", "node_modules" }; - var excludeRegexes = Opt.ExcludeRegexes.Select(x => new Regex(x)); - var fileList = Directory.EnumerateFiles(path, searchPattern - , new EnumerationOptions { - RecurseSubdirectories = true - , AttributesToSkip - = FileAttributes.ReparsePoint - , IgnoreInaccessible = true - , MaxRecursionDepth = Opt.MaxRecursionDepth - }) - .Where(x => { - if (!excludeRegexes.Any(y => y.IsMatch(x))) return true; - ++exCnt; - return false; - }) - .ToArray(); - excludeCnt = exCnt; - return fileList; - } - - protected override async Task Core() - { - if (!Directory.Exists(Opt.Path)) - throw new ArgumentException(nameof(Opt.Path), string.Format(Str.PathNotFound, Opt.Path)); - if (!Opt.WriteMode) AnsiConsole.MarkupLine("[gray]{0}[/]", Str.ExerciseMode); IEnumerable fileList; await AnsiConsole.Progress() @@ -79,6 +52,39 @@ internal abstract class FilesTool : ToolBase where TOption : D } + // ReSharper disable once ReturnTypeCanBeEnumerable.Local + private string[] EnumerateFiles(string path, string searchPattern, out int excludeCnt) + { + var exCnt = 0; + if (Opt.ExcludeRegexes?.FirstOrDefault() is null) //默认排除.git 、 node_modules 目录 + Opt.ExcludeRegexes = new[] { @"\.git", "node_modules" }; + var excludeRegexes = Opt.ExcludeRegexes.Select(x => new Regex(x)); + var fileList = Directory.EnumerateFiles(path, searchPattern + , new EnumerationOptions { + RecurseSubdirectories = true + , AttributesToSkip + = FileAttributes.ReparsePoint + , IgnoreInaccessible = true + , MaxRecursionDepth = Opt.MaxRecursionDepth + }) + .Where(x => { + if (!excludeRegexes.Any(y => y.IsMatch(x))) return true; + ++exCnt; + return false; + }) + .ToArray(); + excludeCnt = exCnt; + return fileList; + } + + protected override Task Core() + { + if (!Directory.Exists(Opt.Path)) + throw new ArgumentException(nameof(Opt.Path), string.Format(Str.PathNotFound, Opt.Path)); + return CoreInternal(); + } + + protected static FileStream CreateTempFile(out string file) { file = Path.Combine(Path.GetTempPath(), $"{System.Guid.NewGuid()}.tmp"); @@ -105,7 +111,9 @@ internal abstract class FilesTool : ToolBase where TOption : D // ignored } } - catch (IOException) { } + catch (IOException) { + // ignored + } return fsr; } diff --git a/src/Git/Main.cs b/src/Git/Main.cs index f42e5ba..503f5df 100644 --- a/src/Git/Main.cs +++ b/src/Git/Main.cs @@ -16,61 +16,9 @@ internal class Main : ToolBase