Skip to content

Commit

Permalink
Add spellcheck to workflow, fix exit code (dotnet#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored and JochemHarmes committed Oct 30, 2023
1 parent 6a8ed2b commit 4f0858b
Show file tree
Hide file tree
Showing 40 changed files with 489 additions and 509 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ jobs:
- run: |
dotnet format Roslynator.sln --no-restore --verify-no-changes --severity info
- run: dotnet test Roslynator.sln --no-build
- uses: actions/checkout@v3
with:
repository: josefpihrt/wordb
path: wordb
- run: |
./CommandLine/bin/Release/net7.0/Roslynator spellcheck Roslynator.sln --dry-run --scope all --words \
spellcheck \
../wordb/data/en \
../wordb/data/en-us \
../wordb/data/names.txt \
../wordb/data/tech.names.txt \
../wordb/data/tech.acronyms.txt
build_core_and_testing:
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'v')
Expand Down
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix [RCS1056](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1056) ([#1154](https://github.com/JosefPihrt/Roslynator/pull/1154)).
- Fix [RCS1208](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1208) ([#1153](https://github.com/JosefPihrt/Roslynator/pull/1153)).
- Fix [RCS1043](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1043) ([#1176](https://github.com/JosefPihrt/Roslynator/pull/1176)).
- [CLI] Fix exit code of `spellcheck` command ([#1177](https://github.com/JosefPihrt/Roslynator/pull/1177)).

## [4.4.0] - 2023-08-01

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Roslynator.CSharp.Analysis;

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class UnncessaryNullForgivingOperatorAnalyzer : BaseDiagnosticAnalyzer
public sealed class UnnecessaryNullForgivingOperatorAnalyzer : BaseDiagnosticAnalyzer
{
private static readonly MetadataName System_Diagnostics_CodeAnalysis_MaybeNullWhenAttribute = MetadataName.Parse("System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute");
private static readonly MetadataName System_Diagnostics_CodeAnalysis_NotNullIfNotNullAttribute = MetadataName.Parse("System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ internal partial class CSharpSpellingService
[SuppressMessage("MicrosoftCodeAnalysisCorrectness", "RS1001:Missing diagnostic analyzer attribute.")]
private class CSharpSpellingAnalyzer : DiagnosticAnalyzer
{
private static readonly ImmutableArray<DiagnosticDescriptor> _supportedDiagnostics = ImmutableArray.Create(SpellingAnalyzer.DiagnosticDescriptor);
private static readonly ImmutableArray<DiagnosticDescriptor> _supportedDiagnostics = ImmutableArray.Create(SpellcheckAnalyzer.DiagnosticDescriptor);

private readonly SpellingData _spellingData;
private readonly SpellingFixerOptions _options;
private readonly SpellcheckOptions _options;

public CSharpSpellingAnalyzer(
SpellingData spellingData,
SpellingFixerOptions options)
SpellcheckOptions options)
{
_spellingData = spellingData;
_options = options;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ internal partial class CSharpSpellingService : SpellingService

public override DiagnosticAnalyzer CreateAnalyzer(
SpellingData spellingData,
SpellingFixerOptions options)
SpellcheckOptions options)
{
return new CSharpSpellingAnalyzer(spellingData, options);
}

public override ImmutableArray<Diagnostic> AnalyzeSpelling(
SyntaxNode node,
SpellingData spellingData,
SpellingFixerOptions options,
SpellcheckOptions options,
CancellationToken cancellationToken = default)
{
var diagnostics = new List<Diagnostic>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal sealed class CSharpSpellingWalker : CSharpSyntaxWalker
private readonly SpellingAnalysisContext _analysisContext;
private readonly Stack<SyntaxNode> _stack = new();

private SpellingFixerOptions Options => _analysisContext.Options;
private SpellcheckOptions Options => _analysisContext.Options;

private CSharpSpellingWalker(SpellingAnalysisContext analysisContext, SyntaxWalkerDepth depth)
: base(depth)
Expand Down
21 changes: 1 addition & 20 deletions src/CommandLine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ VisualStudioVersion = 17.6.33815.320
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8B17331B-D942-4A0C-82AA-23515F4B46C4}"
ProjectSection(SolutionItems) = preProject
..\.github\workflows\build.yml = ..\.github\workflows\build.yml
..\ChangeLog.md = ..\ChangeLog.md
CommandLine\CommandLine.nuspec = CommandLine\CommandLine.nuspec
Directory.Build.props = Directory.Build.props
global.ruleset = global.ruleset
..\docs\HowToFixAllDiagnostics.md = ..\docs\HowToFixAllDiagnostics.md
..\docs\HowToGenerateDocumentation.md = ..\docs\HowToGenerateDocumentation.md
..\README.md = ..\README.md
EndProjectSection
EndProject
Expand All @@ -27,21 +24,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Documentation", "Documentat
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Workspaces.Core", "Workspaces.Core\Workspaces.Core.csproj", "{F8922FB4-67DB-4EA6-932F-AAF9C7503EE7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CLI", "CLI", "{E5C47A70-19EB-4B95-9B05-DD5CEE67C060}"
ProjectSection(SolutionItems) = preProject
CommandLine\docs\analyze-assembly-command.md = CommandLine\docs\analyze-assembly-command.md
..\docs\cli\analyze-command.md = ..\docs\cli\analyze-command.md
..\docs\cli\fix-command.md = ..\docs\cli\fix-command.md
..\docs\cli\format-command.md = ..\docs\cli\format-command.md
..\docs\cli\generate-doc-command.md = ..\docs\cli\generate-doc-command.md
..\docs\cli\generate-doc-root-command.md = ..\docs\cli\generate-doc-root-command.md
..\docs\cli\list-symbols-command.md = ..\docs\cli\list-symbols-command.md
CommandLine\docs\list-vs-command.md = CommandLine\docs\list-vs-command.md
..\docs\cli\lloc-command.md = ..\docs\cli\lloc-command.md
..\docs\cli\loc-command.md = ..\docs\cli\loc-command.md
CommandLine\docs\sln-list-command.md = CommandLine\docs\sln-list-command.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualBasic", "VisualBasic\VisualBasic.csproj", "{05DF2CB8-95FB-4BD9-A9E7-D346470E979A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{D46C9C4D-33D1-467F-96A3-CC05B30BABD0}"
Expand Down Expand Up @@ -113,7 +95,6 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E5C47A70-19EB-4B95-9B05-DD5CEE67C060} = {8B17331B-D942-4A0C-82AA-23515F4B46C4}
{669F7A92-C596-4C52-A659-C9A6C66E966B} = {A098889D-10A8-4604-BA34-168E400A1FA6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
12 changes: 6 additions & 6 deletions src/CommandLine/Commands/MSBuildWorkspaceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private static MSBuildWorkspace CreateMSBuildWorkspace(string msbuildPath, IEnum
return MSBuildWorkspace.Create(properties);
}

private static bool TryGetVisualStudioInstance(out VisualStudioInstance instance)
private static bool TryGetVisualStudioInstance(out VisualStudioInstance result)
{
List<VisualStudioInstance> instances = MSBuildLocator.QueryVisualStudioInstances()
.Distinct(VisualStudioInstanceComparer.MSBuildPath)
Expand All @@ -286,14 +286,14 @@ private static bool TryGetVisualStudioInstance(out VisualStudioInstance instance
if (instances.Count == 0)
{
WriteLine($"MSBuild location not found. Use option '-{OptionShortNames.MSBuildPath}, --{OptionNames.MSBuildPath}' to specify MSBuild location", Verbosity.Quiet);
instance = null;
result = null;
return false;
}

WriteLine("Available MSBuild locations:", Verbosity.Diagnostic);

foreach (VisualStudioInstance vsi in instances.OrderBy(f => f.Version))
WriteLine($" {vsi.Name}, Version: {vsi.Version}, Path: {vsi.MSBuildPath}", Verbosity.Diagnostic);
foreach (VisualStudioInstance instance in instances.OrderBy(f => f.Version))
WriteLine($" {instance.Name}, Version: {instance.Version}, Path: {instance.MSBuildPath}", Verbosity.Diagnostic);

instances = instances
.GroupBy(f => f.Version)
Expand All @@ -304,11 +304,11 @@ private static bool TryGetVisualStudioInstance(out VisualStudioInstance instance
if (instances.Count > 1)
{
WriteLine($"Cannot choose MSBuild location automatically. Use option '-{OptionShortNames.MSBuildPath}, --{OptionNames.MSBuildPath}' to specify MSBuild location", Verbosity.Quiet);
instance = null;
result = null;
return false;
}

instance = instances[0];
result = instances[0];
return true;
}

Expand Down
52 changes: 34 additions & 18 deletions src/CommandLine/Commands/SpellcheckCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,19 @@ public override async Task<SpellcheckCommandResult> ExecuteAsync(ProjectOrSoluti
_ => throw new InvalidOperationException()
};

var options = new SpellingFixerOptions(
scopeFilter: ScopeFilter,
symbolVisibility: visibilityFilter,
minWordLength: Options.MinWordLength,
maxWordLength: Options.MaxWordLength,
includeGeneratedCode: Options.IncludeGeneratedCode,
var options = new SpellcheckOptions()
{
ScopeFilter = ScopeFilter,
SymbolVisibility = visibilityFilter,
MinWordLength = Options.MinWordLength,
MaxWordLength = Options.MaxWordLength,
IncludeGeneratedCode = Options.IncludeGeneratedCode,
#if DEBUG
autofix: !Options.NoAutofix,
Autofix = !Options.NoAutofix,
#endif
interactive: Options.Interactive,
dryRun: Options.DryRun);
Interactive = Options.Interactive,
DryRun = Options.DryRun,
};

CultureInfo culture = (Options.Culture is not null) ? CultureInfo.GetCultureInfo(Options.Culture) : null;

Expand All @@ -74,12 +76,12 @@ public override async Task<SpellcheckCommandResult> ExecuteAsync(ProjectOrSoluti

private async Task<SpellcheckCommandResult> FixAsync(
ProjectOrSolution projectOrSolution,
SpellingFixerOptions options,
SpellcheckOptions options,
ProjectFilter projectFilter,
IFormatProvider formatProvider = null,
CancellationToken cancellationToken = default)
{
SpellingFixer spellingFixer = null;
SpellcheckAnalyzer spellingFixer = null;
ImmutableArray<SpellingFixResult> results = default;

if (projectOrSolution.IsProject)
Expand Down Expand Up @@ -113,11 +115,15 @@ private async Task<SpellcheckCommandResult> FixAsync(

WriteSummary(results);

return new SpellcheckCommandResult(CommandStatus.Success, results);
return new SpellcheckCommandResult(
(results.Length == 0 || (!options.DryRun && results.All(f => f.HasFix)))
? CommandStatus.Success
: CommandStatus.NotSuccess,
results);

SpellingFixer GetSpellingFixer(Solution solution)
SpellcheckAnalyzer GetSpellingFixer(Solution solution)
{
return new SpellingFixer(
return new SpellcheckAnalyzer(
solution,
spellingData: SpellingData,
formatProvider: formatProvider,
Expand Down Expand Up @@ -162,8 +168,12 @@ private void WriteSummary(ImmutableArray<SpellingFixResult> results)

isFirst = true;

foreach (IGrouping<string, SpellingFixResult> grouping in results
.Where(f => !f.HasFix)
IEnumerable<SpellingFixResult> filteredResults = results;

if (!Options.DryRun)
filteredResults = filteredResults.Where(f => !f.HasFix);

foreach (IGrouping<string, SpellingFixResult> grouping in filteredResults
.GroupBy(f => f.Value, comparer)
.OrderBy(f => f.Key, comparer))
{
Expand Down Expand Up @@ -206,8 +216,14 @@ private void WriteSummary(ImmutableArray<SpellingFixResult> results)
WriteMatchingLines(grouping, comparer, ConsoleColors.Green);
}

bool any1 = WriteResults(results, SpellingFixKind.Predefined, "Auto fixes:", comparer, isDetailed);
bool any2 = WriteResults(results, SpellingFixKind.User, "User-applied fixes:", comparer, isDetailed);
var any1 = false;
var any2 = false;

if (!Options.DryRun)
{
any1 = WriteResults(results, SpellingFixKind.Predefined, "Auto fixes:", comparer, isDetailed);
any2 = WriteResults(results, SpellingFixKind.User, "User-applied fixes:", comparer, isDetailed);
}

if (!isFirst
&& !any1
Expand Down
2 changes: 1 addition & 1 deletion src/CommandLine/Options/GenerateDocCommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public class GenerateDocCommandLineOptions : AbstractGenerateDocCommandLineOptio
public bool OmitAttributeArguments { get; set; }

[Option(
longName: "omit-inherited-atttributes",
longName: "omit-inherited-attributes",
HelpText = "Indicates whether inherited attributes should be omitted.")]
public bool OmitInheritedAttributes { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/CommandLine/Options/SpellcheckCommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public sealed class SpellcheckCommandLineOptions : MSBuildCommandLineOptions
[Option(
longName: "words",
Required = true,
HelpText = "Specified path to file and/or directory that contains list of allowed words.",
HelpText = "Specified path to file and/or directory that contains list of known words.",
MetaValue = "<PATH>")]
public IEnumerable<string> Words { get; set; } = null!;
}
2 changes: 1 addition & 1 deletion src/CommandLine/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"CommandLine": {
"commandName": "Project",
"commandLineArgs": "migrate \"E:\\Projects\\Roslynator\\src\\Migration.Test\" --target-version 3.0 --identifier roslynator.analyzers -d"
"commandLineArgs": "-h"
}
}
}
2 changes: 1 addition & 1 deletion src/Common/Configuration/VisualStudioCodeAnalysisConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public VisualStudioCodeAnalysisConfig(

public ImmutableDictionary<string, bool> CodeFixes { get; }

public VisualStudioCodeAnalysisConfig WithPrefixfieldIdentifierWithUnderscore(bool value)
public VisualStudioCodeAnalysisConfig WithPrefixFieldIdentifierWithUnderscore(bool value)
{
return new VisualStudioCodeAnalysisConfig(
value,
Expand Down
2 changes: 1 addition & 1 deletion src/Documentation/Extensions/XmlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static void WriteContentTo(this XElement element, DocumentationWriter wri
{
ISymbol symbol = writer.DocumentationModel.GetFirstSymbolForDeclarationId(commentId);

//XTODO: repair roslyn documentation
//TODO: repair roslyn documentation
Debug.Assert(
symbol is not null
|| commentId == "T:Microsoft.CodeAnalysis.CSharp.SyntaxNode"
Expand Down
2 changes: 1 addition & 1 deletion src/Documentation/MemberDocumentationParts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Roslynator.Documentation;

//XTODO: Security
//TODO: Security
[Flags]
public enum MemberDocumentationParts
{
Expand Down
1 change: 1 addition & 0 deletions src/Roslynator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\ChangeLog.md = ..\ChangeLog.md
Directory.Build.props = Directory.Build.props
..\README.md = ..\README.md
spellcheck = spellcheck
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{A1DB0C05-3710-4B69-955F-2F46E330591B}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ void M()
[InlineData("items.FirstOrDefault(_ => true) is null")]
[InlineData("items.FirstOrDefault() == null")]
[InlineData("items.FirstOrDefault() is null")]
public async Task TestNoDiagnostc_FirstOrDefault_IEnumerableOfNullableType(string source)
public async Task TestNoDiagnostic_FirstOrDefault_IEnumerableOfNullableType(string source)
{
await VerifyNoDiagnosticAsync(@"
using System.Linq;
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Analyzers.Tests/RCS1085UseAutoPropertyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ public double P
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseAutoProperty)]
public async Task TestNoDiagnostic_BackingFieldHasAttibute()
public async Task TestNoDiagnostic_BackingFieldHasAttribute()
{
await VerifyNoDiagnosticAsync(@"
using System;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Roslynator.CSharp.Analysis.Tests;

public class RCS1249UnnecessaryNullForgivingOperatorTests : AbstractCSharpDiagnosticVerifier<UnncessaryNullForgivingOperatorAnalyzer, TokenCodeFixProvider>
public class RCS1249UnnecessaryNullForgivingOperatorTests : AbstractCSharpDiagnosticVerifier<UnnecessaryNullForgivingOperatorAnalyzer, TokenCodeFixProvider>
{
public override DiagnosticDescriptor Descriptor { get; } = DiagnosticRules.UnnecessaryNullForgivingOperator;

Expand Down
2 changes: 1 addition & 1 deletion src/Workspaces.Core/Logging/LogHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void WriteDiagnostics(

public static void WriteSpellingDiagnostic(
SpellingDiagnostic diagnostic,
SpellingFixerOptions options,
SpellcheckOptions options,
SourceText sourceText,
string baseDirectoryPath,
string indentation,
Expand Down
Loading

0 comments on commit 4f0858b

Please sign in to comment.