mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-05 22:29:40 +00:00
Improved voice recording shortcut labels (#800)
Build and Release / Determine run mode (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Has been cancelled
Build and Release / Determine run mode (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Has been cancelled
This commit is contained in:
1 parent
e9da7d31df
commit
1c2d243c1f
11 files changed
+201
-57
No files matched your search
@@ -13,76 +13,94 @@ namespace SourceCodeRules.UsageAnalyzers;
|
||||
public sealed class EmptyStringAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
private const string DIAGNOSTIC_ID = Identifier.EMPTY_STRING_ANALYZER;
|
||||
|
||||
|
||||
private static readonly string TITLE = """
|
||||
Use string.Empty instead of ""
|
||||
""";
|
||||
|
||||
|
||||
private static readonly string MESSAGE_FORMAT = """
|
||||
Use string.Empty instead of ""
|
||||
""";
|
||||
|
||||
private static readonly string DESCRIPTION = """Empty string literals ("") should be replaced with string.Empty for better code consistency and readability except in const contexts.""";
|
||||
|
||||
|
||||
private static readonly string DESCRIPTION = """Empty string literals ("") should be replaced with string.Empty for better code consistency and readability except in contexts requiring compile-time constants.""";
|
||||
|
||||
private const string CATEGORY = "Usage";
|
||||
|
||||
|
||||
private static readonly DiagnosticDescriptor RULE = new(DIAGNOSTIC_ID, TITLE, MESSAGE_FORMAT, CATEGORY, DiagnosticSeverity.Error, isEnabledByDefault: true, description: DESCRIPTION);
|
||||
|
||||
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => [RULE];
|
||||
|
||||
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
|
||||
context.EnableConcurrentExecution();
|
||||
context.RegisterSyntaxNodeAction(AnalyzeEmptyStringLiteral, SyntaxKind.StringLiteralExpression);
|
||||
}
|
||||
|
||||
|
||||
private static void AnalyzeEmptyStringLiteral(SyntaxNodeAnalysisContext context)
|
||||
{
|
||||
var stringLiteral = (LiteralExpressionSyntax)context.Node;
|
||||
if (stringLiteral.Token.ValueText != string.Empty)
|
||||
return;
|
||||
|
||||
if (IsInConstContext(stringLiteral))
|
||||
|
||||
if (RequiresCompileTimeConstant(stringLiteral))
|
||||
return;
|
||||
|
||||
if (IsInParameterDefaultValue(stringLiteral))
|
||||
return;
|
||||
|
||||
|
||||
var diagnostic = Diagnostic.Create(RULE, stringLiteral.GetLocation());
|
||||
context.ReportDiagnostic(diagnostic);
|
||||
}
|
||||
|
||||
private static bool IsInConstContext(LiteralExpressionSyntax stringLiteral)
|
||||
|
||||
private static bool RequiresCompileTimeConstant(LiteralExpressionSyntax stringLiteral)
|
||||
{
|
||||
return IsInConstDeclarationInitializer(stringLiteral)
|
||||
|| IsInParameterDefaultValue(stringLiteral)
|
||||
|| IsInAttributeArgument(stringLiteral)
|
||||
|| IsInSwitchCaseLabel(stringLiteral)
|
||||
|| IsInConstantPattern(stringLiteral);
|
||||
}
|
||||
|
||||
private static bool IsInConstDeclarationInitializer(LiteralExpressionSyntax stringLiteral)
|
||||
{
|
||||
var variableDeclarator = stringLiteral.FirstAncestorOrSelf<VariableDeclaratorSyntax>();
|
||||
if (variableDeclarator is null)
|
||||
if (variableDeclarator?.Initializer is null || !ContainsNode(variableDeclarator.Initializer.Value, stringLiteral))
|
||||
return false;
|
||||
|
||||
|
||||
var declaration = variableDeclarator.Parent?.Parent;
|
||||
return declaration switch
|
||||
{
|
||||
FieldDeclarationSyntax fieldDeclaration => fieldDeclaration.Modifiers.Any(SyntaxKind.ConstKeyword),
|
||||
LocalDeclarationStatementSyntax localDeclaration => localDeclaration.Modifiers.Any(SyntaxKind.ConstKeyword),
|
||||
|
||||
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private static bool IsInParameterDefaultValue(LiteralExpressionSyntax stringLiteral)
|
||||
{
|
||||
// Prüfen, ob das String-Literal Teil eines Parameter-Defaults ist
|
||||
var parameter = stringLiteral.FirstAncestorOrSelf<ParameterSyntax>();
|
||||
if (parameter is null)
|
||||
return false;
|
||||
|
||||
// Überprüfen, ob das String-Literal im Default-Wert des Parameters verwendet wird
|
||||
if (parameter.Default is not null &&
|
||||
parameter.Default.Value == stringLiteral)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return parameter?.Default is not null && ContainsNode(parameter.Default.Value, stringLiteral);
|
||||
}
|
||||
|
||||
private static bool IsInAttributeArgument(LiteralExpressionSyntax stringLiteral)
|
||||
{
|
||||
var attributeArgument = stringLiteral.FirstAncestorOrSelf<AttributeArgumentSyntax>();
|
||||
return attributeArgument is not null && ContainsNode(attributeArgument.Expression, stringLiteral);
|
||||
}
|
||||
|
||||
private static bool IsInSwitchCaseLabel(LiteralExpressionSyntax stringLiteral)
|
||||
{
|
||||
var caseSwitchLabel = stringLiteral.FirstAncestorOrSelf<CaseSwitchLabelSyntax>();
|
||||
return caseSwitchLabel is not null && ContainsNode(caseSwitchLabel.Value, stringLiteral);
|
||||
}
|
||||
|
||||
private static bool IsInConstantPattern(LiteralExpressionSyntax stringLiteral)
|
||||
{
|
||||
var constantPattern = stringLiteral.FirstAncestorOrSelf<ConstantPatternSyntax>();
|
||||
return constantPattern is not null && ContainsNode(constantPattern.Expression, stringLiteral);
|
||||
}
|
||||
|
||||
private static bool ContainsNode(SyntaxNode parent, SyntaxNode child)
|
||||
{
|
||||
return parent.SpanStart <= child.SpanStart && child.Span.End <= parent.Span.End;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user