Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
  • Loading branch information
meziantou committed Nov 13, 2024
commit a3a2b8135a3fb3338d704d803efd3a1e6668a71c
10 changes: 7 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ indent_size = 2
insert_final_newline = true

[*.cs]
dotnet_diagnostic.IDE0058.severity = none
dotnet_diagnostic.IDE0303.severity = none
dotnet_diagnostic.CA1508.severity = none
dotnet_diagnostic.CA2000.severity = none
dotnet_diagnostic.RS1041.severity = none
dotnet_diagnostic.RS2008.severity = none
dotnet_diagnostic.CA1508.severity = none
dotnet_diagnostic.IDE0303.severity = none

[src/ListDotNetTypes/*.cs]
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.MA0004.severity = none
dotnet_diagnostic.MA0004.severity = none


2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Meziantou.DotNet.CodingStandard" Version="1.0.139">
<PackageReference Include="Meziantou.DotNet.CodingStandard" Version="1.0.142">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
3 changes: 1 addition & 2 deletions src/ListDotNetTypes/ListDotNetTypes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NuGet.Protocol" Version="6.11.1" />
<PackageReference Include="System.Formats.Asn1" Version="9.0.0" />
<PackageReference Include="NuGet.Protocol" Version="6.12.1" />
</ItemGroup>

</Project>
4 changes: 3 additions & 1 deletion src/ListDotNetTypes/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
Console.WriteLine(packageName + "@" + latestVersion);

using var packageStream = new MemoryStream();
await resource.CopyNupkgToStreamAsync(packageName, latestVersion, packageStream, cache, NullLogger.Instance, CancellationToken.None);
if (!await resource.CopyNupkgToStreamAsync(packageName, latestVersion, packageStream, cache, NullLogger.Instance, CancellationToken.None))
throw new InvalidOperationException("Cannot copy NuGet package");

packageStream.Seek(0, SeekOrigin.Begin);

using var zipArchive = new ZipArchive(packageStream, ZipArchiveMode.Read);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma warning disable CS1591
#pragma warning disable IDE0060
#pragma warning disable CA1019
#nullable disable

namespace Meziantou.Analyzer.Annotations;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#pragma warning disable IDE0060
#pragma warning disable IDE0290
#pragma warning disable CA1019
#nullable disable

namespace Meziantou.Analyzer.Annotations;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ internal sealed class AvoidUsingRedundantElseFixAllProvider : DocumentBasedFixAl
{
public static AvoidUsingRedundantElseFixAllProvider Instance { get; } = new AvoidUsingRedundantElseFixAllProvider();

protected override string CodeActionTitle => "Remove redundant else";
protected override string GetFixAllTitle(FixAllContext fixAllContext) => "Remove redundant else";

/// <inheritdoc/>
protected override async Task<SyntaxNode?> FixAllInDocumentAsync(FixAllContext fixAllContext, Document document, ImmutableArray<Diagnostic> diagnostics)
protected override async Task<Document?> FixAllAsync(FixAllContext fixAllContext, Document document, ImmutableArray<Diagnostic> diagnostics)
{
if (diagnostics.IsEmpty)
return null;

var newDocument = await AvoidUsingRedundantElseFixer.RemoveRedundantElseClausesInDocument(document, diagnostics, fixAllContext.CancellationToken).ConfigureAwait(false);

return await newDocument.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false);
return newDocument;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,15 @@ internal sealed class MakeMemberReadOnlyFixAllProvider : DocumentBasedFixAllProv
{
public static MakeMemberReadOnlyFixAllProvider Instance { get; } = new MakeMemberReadOnlyFixAllProvider();

protected override string CodeActionTitle => "Add readonly";
protected override string GetFixAllTitle(FixAllContext fixAllContext) => "Add readonly";

/// <inheritdoc/>
protected override async Task<SyntaxNode?> FixAllInDocumentAsync(FixAllContext fixAllContext, Document document, ImmutableArray<Diagnostic> diagnostics)
protected override async Task<Document?> FixAllAsync(FixAllContext fixAllContext, Document document, ImmutableArray<Diagnostic> diagnostics)
{
if (diagnostics.IsEmpty)
return null;

var newDocument = await MakeReadOnly(document, diagnostics, fixAllContext.CancellationToken).ConfigureAwait(false);
return await newDocument.GetSyntaxRootAsync(fixAllContext.CancellationToken).ConfigureAwait(false);
return newDocument;
}

internal static async Task<Document> MakeReadOnly(Document document, ImmutableArray<Diagnostic> diagnostics, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,12 @@ private static async Task<Document> Refactor(Document document, SyntaxNode nodeT

var attribute = editor.Generator.Attribute(
generator.TypeExpression(attributeUsageAttribute, addImport: true),
new[]
{
[
generator.AttributeArgument(
generator.MemberAccessExpression(
generator.TypeExpression(attributeTargets, addImport: true),
nameof(AttributeTargets.All))),
});
]);

editor.AddAttribute(classNode, attribute);
return editor.GetChangedDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
equivalenceKey: title);
context.RegisterCodeFix(codeAction, context.Diagnostics);
}

{
var title = "Negate all or patterns";
var codeAction = CodeAction.Create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Meziantou.Analyzer.Internals;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ private static async Task<Document> Refactor(Document document, SyntaxNode nodeT

var attribute = editor.Generator.Attribute(
generator.TypeExpression(structLayoutAttribute).WithAdditionalAnnotations(Simplifier.AddImportsAnnotation),
new[]
{
[
generator.AttributeArgument(
generator.MemberAccessExpression(
generator.TypeExpression(layoutKindEnum).WithAdditionalAnnotations(Simplifier.AddImportsAnnotation),
layoutKind.ToString())),
});
]);

editor.AddAttribute(nodeToFix, attribute);
return editor.GetChangedDocument();
Expand Down
2 changes: 1 addition & 1 deletion src/Meziantou.Analyzer/Internals/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace Meziantou.Analyzer;
namespace Meziantou.Analyzer.Internals;

internal static class EnumerableExtensions
{
Expand Down
2 changes: 1 addition & 1 deletion src/Meziantou.Analyzer/Internals/OperationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Operations;

namespace Meziantou.Analyzer;
namespace Meziantou.Analyzer.Internals;

internal static class OperationExtensions
{
Expand Down
2 changes: 1 addition & 1 deletion src/Meziantou.Analyzer/Internals/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Runtime.InteropServices;

namespace Meziantou.Analyzer.Rules;
namespace Meziantou.Analyzer.Internals;

internal static partial class StringExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static IEnumerable<ISymbol> GetParameters(IOperation operation)
return GetParameters(delegateCreation.Target);
}

return Enumerable.Empty<ISymbol>();
return [];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private static IEnumerable<string> FindLocalIdentifiersIn(SyntaxNode node)
{
foreach (var child in node.DescendantNodes())
{
#pragma warning disable
switch (child)
{
case VariableDeclaratorSyntax variableDeclarator:
Expand All @@ -90,6 +91,7 @@ private static IEnumerable<string> FindLocalIdentifiersIn(SyntaxNode node)
yield return singleVariableDesignation.Identifier.Text;
break;
}
#pragma warning restore IDE0010 // Add missing cases
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ internal static IEnumerable<SyntaxNode> GetElseClauseChildren(ElseClauseSyntax e
{
return elseClauseSyntax.Statement is BlockSyntax elseBlockSyntax ?
elseBlockSyntax.ChildNodes() :
new[] { elseClauseSyntax.Statement };
[elseClauseSyntax.Statement];
}
}
1 change: 1 addition & 0 deletions src/Meziantou.Analyzer/Rules/FixToDoAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using Meziantou.Analyzer.Internals;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
Expand Down
2 changes: 1 addition & 1 deletion src/Meziantou.Analyzer/Rules/NamedParameterAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public override void Initialize(AnalysisContext context)
{
IMethodSymbol methodSymbol => methodSymbol.Parameters,
IPropertySymbol propertySymbol => propertySymbol.Parameters,
_ => ImmutableArray<IParameterSymbol>.Empty,
_ => [],
};

if (invokedMethodParameters.Length < GetMinimumMethodArgumentsConfiguration(syntaxContext.Options, expression))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ private void AnalyzeNotPatternSyntax(SyntaxNodeAnalysisContext context)
}
}
}
#endif
#endif
2 changes: 1 addition & 1 deletion src/Meziantou.Analyzer/Rules/UseArrayEmptyAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private static ImmutableArray<IParameterSymbol> GetParameters(ISymbol symbol)
{
SymbolKind.Method => ((IMethodSymbol)symbol).Parameters,
SymbolKind.Property => ((IPropertySymbol)symbol).Parameters,
_ => ImmutableArray<IParameterSymbol>.Empty,
_ => [],
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ private static void AnalyzeObjectCreation(OperationAnalysisContext context)
return;
}

var properties = ImmutableDictionary.CreateRange(new[]
{
var properties = ImmutableDictionary.CreateRange(
[
new KeyValuePair<string, string?>(UseRegexSourceGeneratorAnalyzerCommon.PatternIndexName, "0"),
new KeyValuePair<string, string?>(UseRegexSourceGeneratorAnalyzerCommon.RegexOptionsIndexName, op.Arguments.Length > 1 ? "1" : null),
new KeyValuePair<string, string?>(UseRegexSourceGeneratorAnalyzerCommon.RegexTimeoutIndexName, op.Arguments.Length > 2 ? "2" : null),
new KeyValuePair<string, string?>(UseRegexSourceGeneratorAnalyzerCommon.RegexTimeoutName, op.Arguments.Length > 2 ? TimeSpanOperation.GetMilliseconds(op.Arguments[2].Value)?.ToString(CultureInfo.InvariantCulture) : null),
});
]);

context.ReportDiagnostic(RegexSourceGeneratorRule, properties, op);
}
Expand Down Expand Up @@ -110,13 +110,13 @@ private static void AnalyzeInvocation(OperationAnalysisContext context)
return;
}

var properties = ImmutableDictionary.CreateRange(new[]
{
var properties = ImmutableDictionary.CreateRange(
[
new KeyValuePair<string, string?>(UseRegexSourceGeneratorAnalyzerCommon.PatternIndexName, "1"),
new KeyValuePair<string, string?>(UseRegexSourceGeneratorAnalyzerCommon.RegexOptionsIndexName, op.Arguments.Length > 2 ? "2" : null),
new KeyValuePair<string, string?>(UseRegexSourceGeneratorAnalyzerCommon.RegexTimeoutIndexName, op.Arguments.Length > 3 ? "3" : null),
new KeyValuePair<string, string?>(UseRegexSourceGeneratorAnalyzerCommon.RegexTimeoutName, op.Arguments.Length > 3 ? TimeSpanOperation.GetMilliseconds(op.Arguments[3].Value)?.ToString(CultureInfo.InvariantCulture) : null),
});
]);

context.ReportDiagnostic(RegexSourceGeneratorRule, properties, op);
}
Expand Down
Loading