From a6a84d9d1c26e58b4d475eb7252653eacef7dd94 Mon Sep 17 00:00:00 2001 From: nsnail Date: Thu, 19 Jan 2023 15:58:49 +0800 Subject: [PATCH] 1.0.0 --- .editorconfig | 70 ++++++ .gitattributes | 63 +++++ .gitignore | 404 +++++++++++++++++++++++++++++++++ .tgitconfig | 4 + AddMetaFilesToSln.csx | 14 ++ CodeCleanupOnSave.csx | 27 +++ CodeQuality.props | 17 ++ Directory.Build.props | 40 ++++ GenerateResx.targets | 9 + LICENSE | 2 +- NSCodeAnalysis.sln | 46 ++++ NSCodeAnalysis.sln.DotSettings | 62 +++++ StyleCopAnalyzers.ruleset | 221 ++++++++++++++++++ build.cake | 117 ++++++++++ code-format.cmd | 3 + dotnet-tools.json | 12 + git-clean.cmd | 2 + global.json | 10 + key.snk | Bin 0 -> 596 bytes logo.png | Bin 0 -> 9347 bytes src/CodeLinesAnalyzer.cs | 61 +++++ src/Languages/Ln.resx | 33 +++ src/Languages/Ln.tt | 90 ++++++++ src/NSCodeAnalysis.csproj | 11 + stylecop.json | 9 + 25 files changed, 1326 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .tgitconfig create mode 100644 AddMetaFilesToSln.csx create mode 100644 CodeCleanupOnSave.csx create mode 100644 CodeQuality.props create mode 100644 Directory.Build.props create mode 100644 GenerateResx.targets create mode 100644 NSCodeAnalysis.sln create mode 100644 NSCodeAnalysis.sln.DotSettings create mode 100644 StyleCopAnalyzers.ruleset create mode 100644 build.cake create mode 100644 code-format.cmd create mode 100644 dotnet-tools.json create mode 100644 git-clean.cmd create mode 100644 global.json create mode 100644 key.snk create mode 100644 logo.png create mode 100644 src/CodeLinesAnalyzer.cs create mode 100644 src/Languages/Ln.resx create mode 100644 src/Languages/Ln.tt create mode 100644 src/NSCodeAnalysis.csproj create mode 100644 stylecop.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d54638d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,70 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +ij_xml_attribute_wrap = off +ij_xml_text_wrap = off +indent_size = 4 +indent_style = space +insert_final_newline = false +trim_trailing_whitespace = true + +[*.cs] +dotnet_analyzer_diagnostic.severity = warning +dotnet_diagnostic.CA1707.severity = none +dotnet_diagnostic.CA1716.severity = none +dotnet_diagnostic.CA1848.severity = none +dotnet_diagnostic.CA2254.severity = none +dotnet_diagnostic.CA5350.severity = none +dotnet_diagnostic.CA5351.severity = none +dotnet_diagnostic.IDE0005.severity = none +dotnet_diagnostic.IDE0008.severity = none +dotnet_diagnostic.IDE0010.severity = none +dotnet_diagnostic.IDE0017.severity = none +dotnet_diagnostic.IDE0048.severity = none +dotnet_diagnostic.IDE0055.severity = none +dotnet_diagnostic.IDE0058.severity = none +dotnet_diagnostic.IDE0160.severity = none +dotnet_diagnostic.SYSLIB1045.severity = none + + +# ReSharper properties +resharper_align_linq_query = true +resharper_align_multiline_argument = true +resharper_align_multiline_array_and_object_initializer = true +resharper_align_multiline_binary_patterns = true +resharper_align_multiline_calls_chain = true +resharper_align_multiline_extends_list = true +resharper_align_multiline_parameter = true +resharper_align_multiline_property_pattern = true +resharper_align_multiline_switch_expression = true +resharper_align_multiple_declaration = true +resharper_align_multline_type_parameter_constrains = true +resharper_align_multline_type_parameter_list = true +resharper_align_tuple_components = true +resharper_allow_comment_after_lbrace = true +resharper_blank_lines_before_single_line_comment = 1 +resharper_csharp_empty_block_style = together_same_line +resharper_csharp_outdent_commas = true +resharper_csharp_place_type_constraints_on_same_line = false +resharper_csharp_stick_comment = false +resharper_csharp_wrap_before_comma = true +resharper_indent_nested_for_stmt = true +resharper_indent_nested_foreach_stmt = true +resharper_indent_nested_while_stmt = true +resharper_indent_preprocessor_if = usual_indent +resharper_indent_preprocessor_other = usual_indent +resharper_int_align = true +resharper_keep_existing_arrangement = false +resharper_place_linq_into_on_new_line = false +resharper_place_simple_embedded_statement_on_same_line = false +resharper_place_simple_switch_expression_on_single_line = true +resharper_wrap_before_eq = true +resharper_wrap_chained_method_calls = chop_if_long +resharper_wrap_switch_expression = chop_if_long + + +# Microsoft .NET properties +csharp_indent_braces = false +csharp_new_line_before_open_brace = local_functions, methods, types \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a1e1e97 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9865879 --- /dev/null +++ b/.gitignore @@ -0,0 +1,404 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +# [Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml +.idea/ + +# User Define +dist/ +nuget.config +*.[Dd]esigner.cs \ No newline at end of file diff --git a/.tgitconfig b/.tgitconfig new file mode 100644 index 0000000..380a28a --- /dev/null +++ b/.tgitconfig @@ -0,0 +1,4 @@ +[hook "startcommit"] + cmdline = code-format.cmd + wait = true + show = true \ No newline at end of file diff --git a/AddMetaFilesToSln.csx b/AddMetaFilesToSln.csx new file mode 100644 index 0000000..b378f00 --- /dev/null +++ b/AddMetaFilesToSln.csx @@ -0,0 +1,14 @@ +using System.Text.RegularExpressions; + +var slnFile = Directory.GetFiles(@".", "*.sln").First(); + var content = File.ReadAllText(slnFile); + content = Regex.Replace(content,@"ProjectSection\(SolutionItems\) = preProject(?:.|\n)*?EndProjectSection", + $""" +ProjectSection(SolutionItems) = preProject +{string.Join('\n', + Directory.GetFiles(@".", "*").Where(x => !x.EndsWith(".sln")) + .Select(x=>$"\t\t{Path.GetFileName(x)} = {Path.GetFileName(x)}"))} +{'\t'}EndProjectSection +"""); + Console.WriteLine(content); + File.WriteAllText(slnFile, content); \ No newline at end of file diff --git a/CodeCleanupOnSave.csx b/CodeCleanupOnSave.csx new file mode 100644 index 0000000..7dcefb9 --- /dev/null +++ b/CodeCleanupOnSave.csx @@ -0,0 +1,27 @@ +#r "nuget: Newtonsoft.Json, 13.0.0" + +using System.Xml; +using System.IO; +using Newtonsoft.Json.Linq; + +var path = Directory.GetFiles(@".idea", "workspace.xml", SearchOption.AllDirectories).First(); +XmlDocument xdoc = new XmlDocument(); +using(var fs = File.Open(path, FileMode.Open)){ + xdoc.Load(fs); + fs.Seek(0, SeekOrigin.Begin); + var propertiesComponent = xdoc.SelectSingleNode("""//component[@name="PropertiesComponent"]"""); + var jsonStr = propertiesComponent.InnerText; + var jsonObj = JObject.Parse(jsonStr); + var keyToStringObj = jsonObj["keyToString"] as JObject; + if (keyToStringObj.ContainsKey("rider.code.cleanup.on.save")) return; + + keyToStringObj.Add(new JProperty("rider.code.cleanup.on.save", "true")); + var newNode = xdoc.CreateCDataSection(jsonObj.ToString()); + propertiesComponent.InnerText=string.Empty; + propertiesComponent.AppendChild(newNode); + var settings = new XmlWriterSettings { Indent = true }; + using(var writer = XmlWriter.Create(fs, settings)){ + xdoc.WriteTo(writer); + } + +} \ No newline at end of file diff --git a/CodeQuality.props b/CodeQuality.props new file mode 100644 index 0000000..df0775d --- /dev/null +++ b/CodeQuality.props @@ -0,0 +1,17 @@ + + + ../StyleCopAnalyzers.ruleset + true + true + true + true + true + true + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..9fc25d5 --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,40 @@ + + + ../key.snk + nsnail + ../dist + ../dist + © 2006-2023 nsnail + false + A better dotnet code analyzer + true + true + false + true + true + enable + true + $(BaseIntermediateOutputPath)/$(MSBuildProjectName)/obj + true + $(BaseIntermediateOutputPath)/$(MSBuildProjectName)/obj + $(BaseOutputPath)/$(MSBuildProjectName)/bin + logo.png + MIT + https://github.com/nsnail/NSCodeAnalysis.git + analyzer;analysis + NSCodeAnalysis + true + git + https://github.com/nsnail/NSCodeAnalysis.git + true + snupkg + net7.0 + $(AssemblyName) + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + \ No newline at end of file diff --git a/GenerateResx.targets b/GenerateResx.targets new file mode 100644 index 0000000..ca7d33c --- /dev/null +++ b/GenerateResx.targets @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE index d289d82..25c689d 100644 --- a/LICENSE +++ b/LICENSE @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +SOFTWARE. \ No newline at end of file diff --git a/NSCodeAnalysis.sln b/NSCodeAnalysis.sln new file mode 100644 index 0000000..3e4cfaa --- /dev/null +++ b/NSCodeAnalysis.sln @@ -0,0 +1,46 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSCodeAnalysis", "src\NSCodeAnalysis.csproj", "{AF3310AE-A287-4C3A-AC59-A718C18107A3}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "meta", "meta", "{3799A282-8F5B-431D-A83F-A674A3138530}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + .gitattributes = .gitattributes + .gitignore = .gitignore + .tgitconfig = .tgitconfig + AddMetaFilesToSln.csx = AddMetaFilesToSln.csx + build.cake = build.cake + code-format.cmd = code-format.cmd + CodeCleanupOnSave.csx = CodeCleanupOnSave.csx + CodeQuality.props = CodeQuality.props + Directory.Build.props = Directory.Build.props + dotnet-tools.json = dotnet-tools.json + GenerateResx.targets = GenerateResx.targets + git-clean.cmd = git-clean.cmd + global.json = global.json + LICENSE = LICENSE + NSCodeAnalysis.sln.DotSettings = NSCodeAnalysis.sln.DotSettings + NSCodeAnalysis.sln.DotSettings.user = NSCodeAnalysis.sln.DotSettings.user + README.md = README.md + stylecop.json = stylecop.json + StyleCopAnalyzers.ruleset = StyleCopAnalyzers.ruleset + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AF3310AE-A287-4C3A-AC59-A718C18107A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AF3310AE-A287-4C3A-AC59-A718C18107A3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AF3310AE-A287-4C3A-AC59-A718C18107A3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AF3310AE-A287-4C3A-AC59-A718C18107A3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal \ No newline at end of file diff --git a/NSCodeAnalysis.sln.DotSettings b/NSCodeAnalysis.sln.DotSettings new file mode 100644 index 0000000..5f4f66e --- /dev/null +++ b/NSCodeAnalysis.sln.DotSettings @@ -0,0 +1,62 @@ + + DO_NOT_SHOW + DO_NOT_SHOW + NEVER + True + True + True + True + False + 1 + 1 + OFF + HINT + Required + Required + Required + Required + <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /> + <Policy Inspect="True" Prefix="_" Suffix="" Style="AA_BB" /> + <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + <?xml version="1.0" encoding="utf-16"?> +<Patterns xmlns="urn:schemas-jetbrains-com:member-reordering-patterns"> + <TypePattern> + <Entry> + <Entry.SortBy> + <Kind> + <Kind.Order> + <DeclarationKind>Constant</DeclarationKind> + <DeclarationKind>Field</DeclarationKind> + <DeclarationKind>Constructor</DeclarationKind> + <DeclarationKind>Destructor</DeclarationKind> + <DeclarationKind>Delegate</DeclarationKind> + <DeclarationKind>Event</DeclarationKind> + <DeclarationKind>Enum</DeclarationKind> + <DeclarationKind>Interface</DeclarationKind> + <DeclarationKind>Property</DeclarationKind> + <DeclarationKind>Indexer</DeclarationKind> + <DeclarationKind>Method</DeclarationKind> + <DeclarationKind>Struct</DeclarationKind> + <DeclarationKind>Record</DeclarationKind> + <DeclarationKind>Class</DeclarationKind> + </Kind.Order> + </Kind> + <Access> + <Access.Order> + <AccessModifier>Public</AccessModifier> + <AccessModifier>Internal</AccessModifier> + <AccessModifier>ProtectedInternal</AccessModifier> + <AccessModifier>Protected</AccessModifier> + <AccessModifier>PrivateProtected</AccessModifier> + <AccessModifier>Private</AccessModifier> + </Access.Order> + </Access> + <Static /> + <Readonly /> + <Name /> + </Entry.SortBy> + </Entry> + </TypePattern> +</Patterns> + \ No newline at end of file diff --git a/StyleCopAnalyzers.ruleset b/StyleCopAnalyzers.ruleset new file mode 100644 index 0000000..d318627 --- /dev/null +++ b/StyleCopAnalyzers.ruleset @@ -0,0 +1,221 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..78465e5 --- /dev/null +++ b/build.cake @@ -0,0 +1,117 @@ +var target = Argument("target", "Default"); +var configuration = Argument("configuration", "Release"); +var framework = Argument("framework", "net7.0"); + +//////////////////////////////////////////////////////////////// +// Tasks + +Task("Clean") + .Does(context => +{ + context.CleanDirectory("./dist"); +}); + +Task("Build") + .IsDependentOn("Clean") + .Does(context => +{ + DotNetPublish("./src/dot.csproj", new DotNetPublishSettings { + Configuration = configuration, + Framework = framework, + }); +}); + + +// Task("Test") +// .IsDependentOn("Build") +// .Does(context => +// { +// DotNetTest("./test/Spectre.Console.Tests/Spectre.Console.Tests.csproj", new DotNetTestSettings { +// Configuration = configuration, +// NoRestore = true, +// NoBuild = true, +// }); +// +// DotNetTest("./test/Spectre.Console.Cli.Tests/Spectre.Console.Cli.Tests.csproj", new DotNetTestSettings { +// Configuration = configuration, +// NoRestore = true, +// NoBuild = true, +// }); +// +// DotNetTest("./test/Spectre.Console.Analyzer.Tests/Spectre.Console.Analyzer.Tests.csproj", new DotNetTestSettings { +// Configuration = configuration, +// NoRestore = true, +// NoBuild = true, +// }); +// }); + + +// Task("Publish-GitHub") +// .WithCriteria(ctx => BuildSystem.IsRunningOnGitHubActions, "Not running on GitHub Actions") +// //.IsDependentOn("Package") +// .Does(context => +// { +// var apiKey = Argument("github-key", null); +// if(string.IsNullOrWhiteSpace(apiKey)) { +// throw new CakeException("No GitHub API key was provided."); +// } +// +// // Publish to GitHub Packages +// var exitCode = 0; +// foreach(var file in context.GetFiles("./.artifacts/*.nupkg")) +// { +// context.Information("Publishing {0}...", file.GetFilename().FullPath); +// exitCode += StartProcess("dotnet", +// new ProcessSettings { +// Arguments = new ProcessArgumentBuilder() +// .Append("gpr") +// .Append("push") +// .AppendQuoted(file.FullPath) +// .AppendSwitchSecret("-k", " ", apiKey) +// } +// ); +// } +// +// if(exitCode != 0) +// { +// throw new CakeException("Could not push GitHub packages."); +// } +// }); + +Task("Publish-NuGet") + //.WithCriteria(ctx => BuildSystem.IsRunningOnGitHubActions, "Not running on GitHub Actions") + //.IsDependentOn("Package") + .Does(context => +{ + var apiKey = Argument("nuget-key", null); + if(string.IsNullOrWhiteSpace(apiKey)) { + throw new CakeException("No NuGet API key was provided."); + } + + // Publish to GitHub Packages + foreach(var file in context.GetFiles("./.artifacts/*.nupkg")) + { + context.Information("Publishing {0}...", file.GetFilename().FullPath); + DotNetNuGetPush(file.FullPath, new DotNetNuGetPushSettings + { + Source = "https://api.nuget.org/v3/index.json", + ApiKey = apiKey, + SkipDuplicate = true + }); + } +}); + +//////////////////////////////////////////////////////////////// +// Targets + +Task("Publish") +// .IsDependentOn("Publish-GitHub") + .IsDependentOn("Publish-NuGet"); + +Task("Default") + .IsDependentOn("Build"); + +//////////////////////////////////////////////////////////////// +// Execution + +RunTarget(target) \ No newline at end of file diff --git a/code-format.cmd b/code-format.cmd new file mode 100644 index 0000000..dd2fd79 --- /dev/null +++ b/code-format.cmd @@ -0,0 +1,3 @@ +dot rbom -w +dot trim -w +dot tolf -w \ No newline at end of file diff --git a/dotnet-tools.json b/dotnet-tools.json new file mode 100644 index 0000000..4f358a6 --- /dev/null +++ b/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-t4": { + "version": "2.3.1", + "commands": [ + "t4" + ] + } + } +} \ No newline at end of file diff --git a/git-clean.cmd b/git-clean.cmd new file mode 100644 index 0000000..07b006c --- /dev/null +++ b/git-clean.cmd @@ -0,0 +1,2 @@ +git reset --hard +git clean -d -fx . \ No newline at end of file diff --git a/global.json b/global.json new file mode 100644 index 0000000..0e46db0 --- /dev/null +++ b/global.json @@ -0,0 +1,10 @@ +{ + "sdk": { + "version": "7.0.100", + "allowPrerelease": true, + "rollForward": "major" + }, + "tools": { + "dotnet": "7.0.100" + } +} \ No newline at end of file diff --git a/key.snk b/key.snk new file mode 100644 index 0000000000000000000000000000000000000000..0d56adacee4f8f0decb189650fccb4b0d7d3917a GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa500979zDO&X7eud0-7cb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>}sX6mG gpKX +/// 代码行数分析器 +/// +[DiagnosticAnalyzer(LanguageNames.CSharp)] +public class CodeLinesAnalyzer : DiagnosticAnalyzer +{ + private const int _CLASS_LINES_LIMIT = 500; + private const int _METHOD_LINES_LIMIT = 50; + + private static readonly DiagnosticDescriptor _rule = new(nameof(CodeLinesAnalyzer), nameof(CodeLinesAnalyzer) + , (LocalizableString)Ln.Rows_of_code_cannot_be_exceeded + , "Readability", DiagnosticSeverity.Error, true + , (LocalizableString)Ln.Code_line_number_analyzer); + + /// + public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(_rule); + + /// + public override void Initialize(AnalysisContext context) + { + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); + context.EnableConcurrentExecution(); + context.RegisterSyntaxTreeAction(VerifyLines); + } + + private static void Report(SyntaxTreeAnalysisContext context, SyntaxNode node, string typeName, int linesLimit) + { + var location = Location.Create(context.Tree, node.Span); + var diagnostic = Diagnostic.Create(_rule, location, typeName, linesLimit); + context.ReportDiagnostic(diagnostic); + } + + private static void VerifyLines(SyntaxTreeAnalysisContext context) + { + var members = context.Tree.GetRoot().DescendantNodes().OfType(); + foreach (var member in members) { + switch (member) { + case MethodDeclarationSyntax method: + if (method.GetText().Lines.Count > _METHOD_LINES_LIMIT) { + Report(context, method, nameof(MethodDeclarationSyntax), _METHOD_LINES_LIMIT); + } + + break; + case ClassDeclarationSyntax @class: + if (@class.GetText().Lines.Count > _CLASS_LINES_LIMIT) { + Report(context, @class, nameof(ClassDeclarationSyntax), _CLASS_LINES_LIMIT); + } + + break; + } + } + } +} \ No newline at end of file diff --git a/src/Languages/Ln.resx b/src/Languages/Ln.resx new file mode 100644 index 0000000..ded3d8d --- /dev/null +++ b/src/Languages/Ln.resx @@ -0,0 +1,33 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + + {0} 代码行数不能超过 {1} + + + 代码行数分析器 + + \ No newline at end of file diff --git a/src/Languages/Ln.tt b/src/Languages/Ln.tt new file mode 100644 index 0000000..59da8de --- /dev/null +++ b/src/Languages/Ln.tt @@ -0,0 +1,90 @@ +<#@ template language="C#" #> +<#@ assembly name="System.Xml" #> +<#@ output encoding="utf-8" extension="Designer.cs" #> +<#@ import namespace="System.Xml" #> + +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace NSCodeAnalysis.Languages { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public sealed class Ln { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + /// + /// Initializes a new instance of the class. + /// + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + public Ln() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NSCodeAnalysis.Languages.Ln", typeof(Ln).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + <# + var xml = new XmlDocument(); + xml.Load("Ln.resx"); + foreach (XmlNode data in xml.SelectNodes("//root/data")!) + { +#> + /// + /// <#= data.SelectSingleNode("value")?.InnerText #> + /// + public static string <#= + data.Attributes!["name"].Value.Replace(" ", "_") #> { + get { + return ResourceManager.GetString("<#= data.Attributes!["name"].Value #>", resourceCulture); + } + } +<# + } +#> + + } +} \ No newline at end of file diff --git a/src/NSCodeAnalysis.csproj b/src/NSCodeAnalysis.csproj new file mode 100644 index 0000000..b95166a --- /dev/null +++ b/src/NSCodeAnalysis.csproj @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/stylecop.json b/stylecop.json new file mode 100644 index 0000000..ae79eec --- /dev/null +++ b/stylecop.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "indentation": { + "useTabs": false, + "indentationSize": 4 + } + } +} \ No newline at end of file