From e8d82004cc7ed63709f752a02c7a9d6c8f0a0ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Thu, 24 Oct 2024 12:11:13 -0400 Subject: [PATCH 1/2] show statusCheck documentation on CI --- .github/workflows/ci.yml | 37 +++++++++++------- .github/workflows/close-issues.yml | 2 +- Directory.Build.props | 4 +- README.md | 1 + .../DocumentationGenerator.csproj | 3 +- src/DocumentationGenerator/Program.cs | 38 +++++++++++++++---- .../Properties/launchSettings.json | 8 ---- 7 files changed, 59 insertions(+), 34 deletions(-) delete mode 100644 src/DocumentationGenerator/Properties/launchSettings.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ea49571e..c59d963e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,15 @@ defaults: shell: pwsh jobs: + check_documentation: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-dotnet@v4 + - run: dotnet run --project src/DocumentationGenerator/DocumentationGenerator.csproj + - run: git status + if: failure() + compute_package_version: runs-on: ubuntu-latest outputs: @@ -47,9 +56,9 @@ jobs: env: RepositoryBranch: ${{github.ref}} steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 + - uses: actions/checkout@v4 - name: Setup .NET Core - uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4 + uses: actions/setup-dotnet@v4 - run: dotnet run --project src/ListDotNetTypes/ListDotNetTypes.csproj -- src/Meziantou.Analyzer/Resources/ @@ -69,7 +78,7 @@ jobs: - run: dotnet pack src/Meziantou.Analyzer.pack.csproj --configuration Release --no-build /p:Version=${{ needs.compute_package_version.outputs.package_version }} - run: dotnet pack src/Meziantou.Analyzer.Annotations/Meziantou.Analyzer.Annotations.csproj --configuration Release - - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4 + - uses: actions/upload-artifact@v4 with: name: nuget if-no-files-found: error @@ -80,10 +89,10 @@ jobs: runs-on: ubuntu-latest needs: [ create_nuget ] steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 + - uses: actions/checkout@v4 - name: Setup .NET Core (global.json) - uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4 - - uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4 + uses: actions/setup-dotnet@v4 + - uses: actions/download-artifact@v4 with: name: nuget path: ${{ env.NuGetDirectory }} @@ -113,12 +122,12 @@ jobs: roslyn-version: [ 'roslyn3.8', 'roslyn4.2', 'roslyn4.4', 'roslyn4.6', 'roslyn4.8', 'default' ] fail-fast: false steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 + - uses: actions/checkout@v4 - name: Setup .NET Core (global.json) - uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4 + uses: actions/setup-dotnet@v4 - run: dotnet test --configuration ${{ matrix.configuration }} --logger trx --logger "GitHubActions;report-warnings=false" --collect:"XPlat Code Coverage" --blame-hang --blame-hang-timeout 2min --results-directory "${{ env.TestResultsDirectory }}" /p:WarningsAsErrors=true /p:RoslynVersion=${{ matrix.roslyn-version}} name: Run tests - - uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4 + - uses: actions/upload-artifact@v4 if: always() with: name: test-results-${{ matrix.runs-on }}-${{ matrix.roslyn-version }}-${{ matrix.configuration }} @@ -128,17 +137,17 @@ jobs: deploy: runs-on: 'ubuntu-latest' - needs: [ validate_nuget, build_and_test ] + needs: [ check_documentation, validate_nuget, build_and_test ] steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 + - uses: actions/checkout@v4 with: fetch-depth: 2 - - uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4 + - uses: actions/download-artifact@v4 with: name: nuget path: ${{ env.NuGetDirectory }} - name: Setup .NET Core - uses: actions/setup-dotnet@4d6c8fcf3c8f7a60068d26b594648e99df24cee3 # v4 + uses: actions/setup-dotnet@v4 - run: | Write-Host "Current ref: $env:GITHUB_REF" Write-Host "Searching nupkg in folder: ${{ env.NuGetDirectory }}" @@ -167,7 +176,7 @@ jobs: permissions: contents: write steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4 + - uses: actions/checkout@v4 - run: 'gh release create "${{ needs.compute_package_version.outputs.package_version }}" --generate-notes --notes "NuGet package: "' env: GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/close-issues.yml b/.github/workflows/close-issues.yml index 9919634a3..febfae15c 100644 --- a/.github/workflows/close-issues.yml +++ b/.github/workflows/close-issues.yml @@ -11,7 +11,7 @@ jobs: issues: write pull-requests: write steps: - - uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e # v9 + - uses: actions/stale@v9 with: days-before-issue-stale: 60 days-before-issue-close: 14 diff --git a/Directory.Build.props b/Directory.Build.props index 136129b36..61fb4f160 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -34,11 +34,11 @@ - + all runtime; build; native; contentfiles; analyzers - + all runtime; build; native; contentfiles; analyzers diff --git a/README.md b/README.md index a88f5f466..06ece215f 100755 --- a/README.md +++ b/README.md @@ -180,6 +180,7 @@ If you are already using other analyzers, you can check [which rules are duplica |[MA0162](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0162.md)|Usage|Use Process.Start overload with ProcessStartInfo|ℹ️|❌|❌| |[MA0163](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0163.md)|Usage|UseShellExecute must be false when redirecting standard input or output|⚠️|✔️|❌| |[MA0164](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0164.md)|Style|Use parentheses to make not pattern clearer|⚠️|✔️|✔️| +|[MA0165](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0165.md)|Usage|Make interpolated string|👻|✔️|✔️| diff --git a/src/DocumentationGenerator/DocumentationGenerator.csproj b/src/DocumentationGenerator/DocumentationGenerator.csproj index d5024c813..f97c9d00a 100644 --- a/src/DocumentationGenerator/DocumentationGenerator.csproj +++ b/src/DocumentationGenerator/DocumentationGenerator.csproj @@ -9,7 +9,8 @@ - + + diff --git a/src/DocumentationGenerator/Program.cs b/src/DocumentationGenerator/Program.cs index 6f619121b..7df26cf70 100644 --- a/src/DocumentationGenerator/Program.cs +++ b/src/DocumentationGenerator/Program.cs @@ -6,17 +6,18 @@ using System.Text; using System.Text.Encodings.Web; using System.Text.RegularExpressions; +using Meziantou.Framework; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Diagnostics; -if (args.Length == 0) +if (!FullPath.CurrentDirectory().TryFindFirstAncestorOrSelf(p => Directory.Exists(p / ".git"), out var outputFolder)) { - Console.Error.WriteLine("You must specify the output folder"); - return; + Console.WriteLine("Cannot find the current git folder"); + return 1; } -var outputFolder = Path.GetFullPath(args[0]); +var fileWritten = 0; var assemblies = new[] { typeof(Meziantou.Analyzer.Rules.CommaAnalyzer).Assembly, typeof(Meziantou.Analyzer.Rules.CommaFixer).Assembly }; var diagnosticAnalyzers = assemblies.SelectMany(assembly => assembly.GetExportedTypes()) @@ -59,14 +60,14 @@ var readmeContent = await File.ReadAllTextAsync(readmePath); var newContent = Regex.Replace(readmeContent, "(?<=\\r?\\n).*(?=)", "\n" + GenerateRulesTable(diagnosticAnalyzers, codeFixProviders, addTitle: false) + "\n", RegexOptions.Singleline); newContent = Regex.Replace(newContent, "(?<=\\r?\\n).*(?=)", "\n" + GenerateSuppressorsTable(diagnosticSuppressors) + "\n", RegexOptions.Singleline); - await File.WriteAllTextAsync(readmePath, newContent); + WriteFileIfChanged(readmePath, newContent); } // Update doc readme { var path = Path.GetFullPath(Path.Combine(outputFolder, "docs", "README.md")); Console.WriteLine(path); - await File.WriteAllTextAsync(path, sb.ToString()); + WriteFileIfChanged(path, sb.ToString()); } // Update title in rule pages @@ -79,15 +80,36 @@ { var lines = await File.ReadAllLinesAsync(detailPath); lines[0] = title; - File.WriteAllLines(detailPath, lines); + WriteFileIfChanged(detailPath, string.Join('\n', lines) + "\n"); } else { - await File.WriteAllTextAsync(detailPath, title); + WriteFileIfChanged(detailPath, title); } } } +return fileWritten; + +void WriteFileIfChanged(string path, string content) +{ + content = content.ReplaceLineEndings("\n"); + + if (!File.Exists(path)) + { + File.WriteAllText(path, content); + fileWritten++; + return; + } + + var existingContent = File.ReadAllText(path).ReplaceLineEndings(); + if (existingContent != content) + { + File.WriteAllText(path, content); + fileWritten++; + } +} + static string GenerateRulesTable(List diagnosticAnalyzers, List codeFixProviders, bool addTitle = true) { var sb = new StringBuilder(); diff --git a/src/DocumentationGenerator/Properties/launchSettings.json b/src/DocumentationGenerator/Properties/launchSettings.json deleted file mode 100644 index a770c3d55..000000000 --- a/src/DocumentationGenerator/Properties/launchSettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "profiles": { - "DocumentationGenerator": { - "commandName": "Project", - "commandLineArgs": "..\\..\\..\\..\\.." - } - } -} \ No newline at end of file From 9f63343c3ef1989a746ba26c5b44daa48d8c7a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rald=20Barr=C3=A9?= Date: Thu, 24 Oct 2024 12:40:59 -0400 Subject: [PATCH 2/2] Add doc for MA0165 --- docs/README.md | 7 +++++++ docs/Rules/MA0165.md | 5 +++++ 2 files changed, 12 insertions(+) create mode 100644 docs/Rules/MA0165.md diff --git a/docs/README.md b/docs/README.md index b408b8075..e84882da3 100755 --- a/docs/README.md +++ b/docs/README.md @@ -164,6 +164,7 @@ |[MA0162](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0162.md)|Usage|Use Process.Start overload with ProcessStartInfo|ℹ️|❌|❌| |[MA0163](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0163.md)|Usage|UseShellExecute must be false when redirecting standard input or output|⚠️|✔️|❌| |[MA0164](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0164.md)|Style|Use parentheses to make not pattern clearer|⚠️|✔️|✔️| +|[MA0165](https://github.com/meziantou/Meziantou.Analyzer/blob/main/docs/Rules/MA0165.md)|Usage|Make interpolated string|👻|✔️|✔️| |Id|Suppressed rule|Justification| |--|---------------|-------------| @@ -663,6 +664,9 @@ dotnet_diagnostic.MA0163.severity = warning # MA0164: Use parentheses to make not pattern clearer dotnet_diagnostic.MA0164.severity = warning + +# MA0165: Make interpolated string +dotnet_diagnostic.MA0165.severity = silent ``` # .editorconfig - all rules disabled @@ -1156,4 +1160,7 @@ dotnet_diagnostic.MA0163.severity = none # MA0164: Use parentheses to make not pattern clearer dotnet_diagnostic.MA0164.severity = none + +# MA0165: Make interpolated string +dotnet_diagnostic.MA0165.severity = none ``` diff --git a/docs/Rules/MA0165.md b/docs/Rules/MA0165.md new file mode 100644 index 000000000..77c0e4c26 --- /dev/null +++ b/docs/Rules/MA0165.md @@ -0,0 +1,5 @@ +# MA0165 - Make interpolated string + +This rule is intended to provide a codefix for adding `$` in front of a string or a verbatim string. + +The default verbosity is `Hidden`, so it should not be visible in the IDE, only a codefix should be offered by the IDE.