1
0

chore: Introduce Qodana static analysis configuration and apply minor code formatting and C# 12 collection expressions.

This commit is contained in:
2026-03-01 20:07:20 +01:00
parent ec575ab5f9
commit 15f9647f8a
24 changed files with 344 additions and 80 deletions

View File

@@ -106,7 +106,8 @@ public class OpenAiCompatibleClient : ISpeechClient, ILlmClient
var jsonContent = new StringContent(JsonSerializer.Serialize(requestBody, AppJsonSerializerContext.Default.OpenAiRequest), System.Text.Encoding.UTF8, "application/json"); var jsonContent = new StringContent(JsonSerializer.Serialize(requestBody, AppJsonSerializerContext.Default.OpenAiRequest), System.Text.Encoding.UTF8, "application/json");
using var request = new HttpRequestMessage(HttpMethod.Post, "chat/completions") { Content = jsonContent }; using var request = new HttpRequestMessage(HttpMethod.Post, "chat/completions");
request.Content = jsonContent;
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/event-stream")); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/event-stream"));
Logger.LogDebug($"Sending OpenAi Steam API request (model: {requestBody.Model})..."); Logger.LogDebug($"Sending OpenAi Steam API request (model: {requestBody.Model})...");

View File

@@ -70,7 +70,7 @@ public static class SkillRegistry
{ {
Name = "Terminal", Name = "Terminal",
Description = "Translates the spoken command into a bash command and types it.", Description = "Translates the spoken command into a bash command and types it.",
Hotwords = new[] { "System terminal", "System run", "System execute" }, Hotwords = ["System terminal", "System run", "System execute"],
Action = "type", Action = "type",
SystemPrompt = @"You are a Linux terminal expert. SystemPrompt = @"You are a Linux terminal expert.
Translate the user's request into a single, valid bash command. Translate the user's request into a single, valid bash command.
@@ -80,7 +80,7 @@ Output ONLY the raw command, no formatting, no markdown."
{ {
Name = "Translate", Name = "Translate",
Description = "Translates the spoken text into another language on the fly.", Description = "Translates the spoken text into another language on the fly.",
Hotwords = new[] { "System translate to", "System translate into" }, Hotwords = ["System translate to", "System translate into"],
Action = "type", Action = "type",
SystemPrompt = @"You are an expert translator. The user wants to translate the following text. SystemPrompt = @"You are an expert translator. The user wants to translate the following text.
The first few words identify the target language (e.g. 'Translate to Spanish:', 'Translate into Hungarian:'). The first few words identify the target language (e.g. 'Translate to Spanish:', 'Translate into Hungarian:').
@@ -91,7 +91,7 @@ Output ONLY the final translated text. Do not include markdown, explanations, or
{ {
Name = "Professional", Name = "Professional",
Description = "Rewrites text into a formal, articulate tone.", Description = "Rewrites text into a formal, articulate tone.",
Hotwords = new[] { "System professional", "System formalize", "System formal" }, Hotwords = ["System professional", "System formalize", "System formal"],
Action = "type", Action = "type",
SystemPrompt = @"Rewrite the following text to be articulate and formal. SystemPrompt = @"Rewrite the following text to be articulate and formal.
The text will start with 'System professional', 'System formalize', or 'System formal', The text will start with 'System professional', 'System formalize', or 'System formal',
@@ -105,7 +105,7 @@ Text: {transcript}"
{ {
Name = "Summary", Name = "Summary",
Description = "Provides a direct, crisp summary of the dictation.", Description = "Provides a direct, crisp summary of the dictation.",
Hotwords = new[] { "System summary", "System concise", "System summarize" }, Hotwords = ["System summary", "System concise", "System summarize"],
Action = "type", Action = "type",
SystemPrompt = @"Summarize the following text to be as concise SystemPrompt = @"Summarize the following text to be as concise
and direct as possible. and direct as possible.

View File

@@ -10,9 +10,9 @@ public class Program
{ {
var rootCommand = new RootCommand("Toak: High-speed Linux Dictation"); var rootCommand = new RootCommand("Toak: High-speed Linux Dictation");
var pipeOption = new Option<bool>(new[] { "--pipe", "-p" }, "Output transcription to stdout instead of typing"); var pipeOption = new Option<bool>(["--pipe", "-p"], "Output transcription to stdout instead of typing");
var copyOption = new Option<bool>("--copy", "Copy to clipboard instead of typing"); var copyOption = new Option<bool>("--copy", "Copy to clipboard instead of typing");
var verboseOption = new Option<bool>(new[] { "--verbose", "-v" }, "Enable detailed debug logging"); var verboseOption = new Option<bool>(["--verbose", "-v"], "Enable detailed debug logging");
rootCommand.AddGlobalOption(verboseOption); rootCommand.AddGlobalOption(verboseOption);
@@ -84,7 +84,7 @@ public class Program
// History Command // History Command
var historyCmd = new Command("history", "Display recent transcriptions with timestamps"); var historyCmd = new Command("history", "Display recent transcriptions with timestamps");
var numArg = new Option<int>(new[] { "-n", "--num" }, () => 10, "Number of recent entries to show"); var numArg = new Option<int>(["-n", "--num"], () => 10, "Number of recent entries to show");
var grepArg = new Option<string>("--grep", "Search through transcription history"); var grepArg = new Option<string>("--grep", "Search through transcription history");
var exportArg = new Option<string>("--export", "Export transcription history to a Markdown file"); var exportArg = new Option<string>("--export", "Export transcription history to a Markdown file");
var shredArg = new Option<bool>("--shred", "Securely delete transcription history"); var shredArg = new Option<bool>("--shred", "Securely delete transcription history");

6
qodana.yaml Normal file
View File

@@ -0,0 +1,6 @@
#################################################################################
# WARNING: Do not store sensitive information in this file, #
# as its contents will be included in the Qodana report. #
#################################################################################
version: "1.0"
linter: qodana-cdnet

257
qodana_problems.md Normal file
View File

@@ -0,0 +1,257 @@
# Qodana Inspection Results
This document outlines the problems detected in the codebase by the Qodana scan.
## ArrangeObjectCreationWhenTypeEvident
Found 6 occurrences.
- **Configuration/ToakConfig.cs** (Line 20): Redundant type specification [note]
- **Core/Skills/SkillRegistry.cs** (Line 12): Redundant type specification [note]
- **Core/Skills/SkillRegistry.cs** (Line 69): Redundant type specification [note]
- **Core/Skills/SkillRegistry.cs** (Line 79): Redundant type specification [note]
- **Core/Skills/SkillRegistry.cs** (Line 90): Redundant type specification [note]
- **Core/Skills/SkillRegistry.cs** (Line 104): Redundant type specification [note]
## AsyncMethodWithoutAwait
Found 9 occurrences.
- **Commands/ConfigUpdaterCommand.cs** (Line 9): This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls or drop 'async' to avoid generating state machine for this method [note]
- **Commands/HistoryCommand.cs** (Line 14): This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls or drop 'async' to avoid generating state machine for this method [note]
- **Commands/OnboardCommand.cs** (Line 13): This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls or drop 'async' to avoid generating state machine for this method [note]
- **Commands/ShowCommand.cs** (Line 9): This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls or drop 'async' to avoid generating state machine for this method [note]
- **Commands/SkillCommand.cs** (Line 37): This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls or drop 'async' to avoid generating state machine for this method [note]
- **Commands/SkillCommand.cs** (Line 68): This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls or drop 'async' to avoid generating state machine for this method [note]
- **Commands/SkillCommand.cs** (Line 110): This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls or drop 'async' to avoid generating state machine for this method [note]
- **Commands/StatsCommand.cs** (Line 12): This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls or drop 'async' to avoid generating state machine for this method [note]
- **Core/TranscriptionOrchestrator.cs** (Line 45): This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls or drop 'async' to avoid generating state machine for this method [note]
## ClassNeverInstantiated.Global
Found 1 occurrences.
- **Program.cs** (Line 7): Class 'Program' is never instantiated [note]
## ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
Found 4 occurrences.
- **Api/OpenAiCompatibleClient.cs** (Line 89): Conditional access qualifier expression is never null according to nullable reference types' annotations [warning]
- **Api/OpenAiCompatibleClient.cs** (Line 89): Conditional access qualifier expression is never null according to nullable reference types' annotations [warning]
- **Api/OpenAiCompatibleClient.cs** (Line 135): Conditional access qualifier expression is never null according to nullable reference types' annotations [warning]
- **Api/OpenAiCompatibleClient.cs** (Line 135): Conditional access qualifier expression is never null according to nullable reference types' annotations [warning]
## ConvertClosureToMethodGroup
Found 1 occurrences.
- **Commands/SkillCommand.cs** (Line 31): Convert into method group [note]
## ConvertIfStatementToConditionalTernaryExpression
Found 3 occurrences.
- **Core/DaemonService.cs** (Line 58): Convert into '?:' expression [note]
- **Commands/LatencyTestCommand.cs** (Line 76): Convert into method call with '?:' expression inside [note]
- **Commands/StatusCommand.cs** (Line 36): Convert into method call with '?:' expression inside [note]
## ConvertToPrimaryConstructor
Found 6 occurrences.
- **Audio/AudioRecorder.cs** (Line 16): Convert into primary constructor [note]
- **Audio/FfmpegAudioRecorder.cs** (Line 17): Convert into primary constructor [note]
- **Core/Skills/DynamicSkill.cs** (Line 16): Convert into primary constructor [note]
- **Core/TranscriptionOrchestrator.cs** (Line 23): Convert into primary constructor [note]
- **IO/ClipboardManager.cs** (Line 11): Convert into primary constructor [note]
- **IO/TextInjector.cs** (Line 13): Convert into primary constructor [note]
## EmptyConstructor
Found 2 occurrences.
- **Configuration/ConfigManager.cs** (Line 15): Empty constructor is redundant. The compiler generates the same by default. [warning]
- **Core/HistoryManager.cs** (Line 16): Empty constructor is redundant. The compiler generates the same by default. [warning]
## EmptyGeneralCatchClause
Found 1 occurrences.
- **Core/DaemonService.cs** (Line 42): Empty general catch clause suppresses any errors [warning]
## FieldCanBeMadeReadOnly.Global
Found 1 occurrences.
- **Core/Skills/SkillRegistry.cs** (Line 12): Field can be made readonly [note]
## InconsistentNaming
Found 7 occurrences.
- **Configuration/ConfigManager.cs** (Line 12): Name 'ConfigDir' does not match rule 'Instance fields (private)'. Suggested name is '_configDir'. [warning]
- **Configuration/ConfigManager.cs** (Line 13): Name 'ConfigPath' does not match rule 'Instance fields (private)'. Suggested name is '_configPath'. [warning]
- **Core/HistoryManager.cs** (Line 13): Name 'HistoryDir' does not match rule 'Instance fields (private)'. Suggested name is '_historyDir'. [warning]
- **Core/HistoryManager.cs** (Line 14): Name 'HistoryFile' does not match rule 'Instance fields (private)'. Suggested name is '_historyFile'. [warning]
- **Core/StateTracker.cs** (Line 7): Name 'StateFilePath' does not match rule 'Instance fields (private)'. Suggested name is '_stateFilePath'. [warning]
- **Audio/AudioRecorder.cs** (Line 12): Name 'WavPath' does not match rule 'Instance fields (private)'. Suggested name is '_wavPath'. [warning]
- **Audio/FfmpegAudioRecorder.cs** (Line 13): Name 'WavPath' does not match rule 'Instance fields (private)'. Suggested name is '_wavPath'. [warning]
## MemberCanBePrivate.Global
Found 1 occurrences.
- **Core/Constants.cs** (Line 8): Constant 'AppName' can be made private [note]
## MergeIntoPattern
Found 1 occurrences.
- **Core/TranscriptionOrchestrator.cs** (Line 101): Merge into pattern [note]
## MethodHasAsyncOverload
Found 9 occurrences.
- **Commands/HistoryCommand.cs** (Line 58): Method has async overload [note]
- **Commands/HistoryCommand.cs** (Line 59): Method has async overload [note]
- **Commands/HistoryCommand.cs** (Line 63): Method has async overload [note]
- **Commands/HistoryCommand.cs** (Line 64): Method has async overload [note]
- **Commands/HistoryCommand.cs** (Line 65): Method has async overload [note]
- **Commands/LatencyTestCommand.cs** (Line 37): Method has async overload [note]
- **Commands/OnboardCommand.cs** (Line 119): Method has async overload [note]
- **Commands/SkillCommand.cs** (Line 51): Method has async overload [note]
- **Commands/SkillCommand.cs** (Line 105): Method has async overload [note]
## MoveVariableDeclarationInsideLoopCondition
Found 1 occurrences.
- **Api/OpenAiCompatibleClient.cs** (Line 125): Variable 'line' can be declared inside loop condition [note]
## NotAccessedField.Local
Found 1 occurrences.
- **Core/DaemonService.cs** (Line 21): Field '_lockFile' is assigned but its value is never used [warning]
## RedundantDefaultMemberInitializer
Found 2 occurrences.
- **Api/Models/OpenAiModels.cs** (Line 20): Initializing property by default value is redundant [warning]
- **Core/Logger.cs** (Line 5): Initializing property by default value is redundant [warning]
## RedundantExplicitParamsArrayCreation
Found 7 occurrences.
- **Commands/OnboardCommand.cs** (Line 31): Redundant explicit collection creation in argument of 'params' parameter [note]
- **Commands/OnboardCommand.cs** (Line 44): Redundant explicit collection creation in argument of 'params' parameter [note]
- **Commands/OnboardCommand.cs** (Line 51): Redundant explicit collection creation in argument of 'params' parameter [note]
- **Commands/OnboardCommand.cs** (Line 60): Redundant explicit collection creation in argument of 'params' parameter [note]
- **Commands/OnboardCommand.cs** (Line 66): Redundant explicit collection creation in argument of 'params' parameter [note]
- **Commands/OnboardCommand.cs** (Line 93): Redundant explicit collection creation in argument of 'params' parameter [note]
- **Commands/SkillCommand.cs** (Line 81): Redundant explicit collection creation in argument of 'params' parameter [note]
## RedundantNameQualifier
Found 35 occurrences.
- **Api/OpenAiCompatibleClient.cs** (Line 25): Qualifier is redundant [warning]
- **Api/OpenAiCompatibleClient.cs** (Line 35): Qualifier is redundant [warning]
- **Api/OpenAiCompatibleClient.cs** (Line 60): Qualifier is redundant [warning]
- **Api/OpenAiCompatibleClient.cs** (Line 64): Qualifier is redundant [warning]
- **Api/OpenAiCompatibleClient.cs** (Line 92): Qualifier is redundant [warning]
- **Api/OpenAiCompatibleClient.cs** (Line 96): Qualifier is redundant [warning]
- **Commands/ConfigUpdaterCommand.cs** (Line 11): Qualifier is redundant [warning]
- **Commands/OnboardCommand.cs** (Line 15): Qualifier is redundant [warning]
- **Commands/OnboardCommand.cs** (Line 124): Qualifier is redundant [warning]
- **Commands/ShowCommand.cs** (Line 11): Qualifier is redundant [warning]
- **Configuration/ToakConfig.cs** (Line 15): Qualifier is redundant [warning]
- **Configuration/ToakConfig.cs** (Line 17): Qualifier is redundant [warning]
- **Core/Interfaces/Interfaces.cs** (Line 16): Qualifier is redundant [warning]
- **Core/Interfaces/Interfaces.cs** (Line 21): Qualifier is redundant [warning]
- **Core/Interfaces/Interfaces.cs** (Line 22): Qualifier is redundant [warning]
- **Core/Skills/SkillDefinition.cs** (Line 7): Qualifier is redundant [warning]
- **Core/TranscriptionOrchestrator.cs** (Line 99): Qualifier is redundant [warning]
- **IO/ClipboardManager.cs** (Line 28): Qualifier is redundant [warning]
- **IO/ClipboardManager.cs** (Line 38): Qualifier is redundant [warning]
- **IO/Notifications.cs** (Line 19): Qualifier is redundant [warning]
- ... and 15 more occurrences.
## RedundantStringInterpolation
Found 6 occurrences.
- **IO/TextInjector.cs** (Line 28): Redundant string interpolation [note]
- **IO/TextInjector.cs** (Line 39): Redundant string interpolation [note]
- **IO/TextInjector.cs** (Line 50): Redundant string interpolation [note]
- **IO/TextInjector.cs** (Line 78): Redundant string interpolation [note]
- **IO/TextInjector.cs** (Line 90): Redundant string interpolation [note]
- **IO/TextInjector.cs** (Line 109): Redundant string interpolation [note]
## RedundantTypeDeclarationBody
Found 2 occurrences.
- **Serialization/AppJsonSerializerContext.cs** (Line 24): Redundant empty class declaration body [note]
- **Serialization/AppJsonSerializerContext.cs** (Line 30): Redundant empty class declaration body [note]
## RedundantUsingDirective
Found 62 occurrences.
- **Api/OpenAiCompatibleClient.cs** (Line 3): Using directive is not required by the code and can be safely removed [warning]
- **Audio/AudioRecorder.cs** (Line 4): Using directive is not required by the code and can be safely removed [warning]
- **Audio/FfmpegAudioRecorder.cs** (Line 1): Using directive is not required by the code and can be safely removed [warning]
- **Audio/FfmpegAudioRecorder.cs** (Line 3): Using directive is not required by the code and can be safely removed [warning]
- **Audio/FfmpegAudioRecorder.cs** (Line 6): Using directive is not required by the code and can be safely removed [warning]
- **Commands/ConfigUpdaterCommand.cs** (Line 1): Using directive is not required by the code and can be safely removed [warning]
- **Commands/DiscardCommand.cs** (Line 1): Using directive is not required by the code and can be safely removed [warning]
- **Commands/DiscardCommand.cs** (Line 3): Using directive is not required by the code and can be safely removed [warning]
- **Commands/HistoryCommand.cs** (Line 1): Using directive is not required by the code and can be safely removed [warning]
- **Commands/HistoryCommand.cs** (Line 2): Using directive is not required by the code and can be safely removed [warning]
- **Commands/HistoryCommand.cs** (Line 3): Using directive is not required by the code and can be safely removed [warning]
- **Commands/HistoryCommand.cs** (Line 4): Using directive is not required by the code and can be safely removed [warning]
- **Commands/HistoryCommand.cs** (Line 5): Using directive is not required by the code and can be safely removed [warning]
- **Commands/HistoryCommand.cs** (Line 6): Using directive is not required by the code and can be safely removed [warning]
- **Commands/LatencyTestCommand.cs** (Line 1): Using directive is not required by the code and can be safely removed [warning]
- **Commands/LatencyTestCommand.cs** (Line 3): Using directive is not required by the code and can be safely removed [warning]
- **Commands/LatencyTestCommand.cs** (Line 4): Using directive is not required by the code and can be safely removed [warning]
- **Commands/OnboardCommand.cs** (Line 1): Using directive is not required by the code and can be safely removed [warning]
- **Commands/OnboardCommand.cs** (Line 3): Using directive is not required by the code and can be safely removed [warning]
- **Commands/OnboardCommand.cs** (Line 4): Using directive is not required by the code and can be safely removed [warning]
- ... and 42 more occurrences.
## UnusedMember.Global
Found 2 occurrences.
- **Core/Interfaces/Interfaces.cs** (Line 41): Method 'InjectTextAsync' is never used [note]
- **Core/Skills/ISkill.cs** (Line 6): Property 'Description' is never used [note]
## UnusedMemberInSuper.Global
Found 3 occurrences.
- **Core/Interfaces/Interfaces.cs** (Line 48): Only implementations of method 'ClearHistory' are used [note]
- **Core/Interfaces/Interfaces.cs** (Line 47): Only implementations of method 'LoadHistory' are used [note]
- **Core/Interfaces/Interfaces.cs** (Line 11): Only implementations of method 'SaveConfig' are used [note]
## UnusedParameter.Global
Found 1 occurrences.
- **Commands/SkillCommand.cs** (Line 14): Parameter 'verboseOption' is never used [note]
## UnusedVariable
Found 2 occurrences.
- **Commands/LatencyTestCommand.cs** (Line 60): Local variable 'refinedText' is never used [warning]
- **Commands/LatencyTestCommand.cs** (Line 54): Local variable 'transcript' is never used [warning]
## UseAwaitUsing
Found 3 occurrences.
- **Api/OpenAiCompatibleClient.cs** (Line 29): Use 'await using' [note]
- **Api/OpenAiCompatibleClient.cs** (Line 122): Use 'await using' [note]
- **Commands/HistoryCommand.cs** (Line 57): Use 'await using' [note]
## UseCollectionExpression
Found 12 occurrences.
- **Api/OpenAiCompatibleClient.cs** (Line 67): Use collection expression [note]
- **Api/OpenAiCompatibleClient.cs** (Line 100): Use collection expression [note]
- **Commands/StatsCommand.cs** (Line 33): Use collection expression [note]
- **Configuration/ToakConfig.cs** (Line 20): Use collection expression [note]
- **Core/HistoryManager.cs** (Line 43): Use collection expression [note]
- **Core/Skills/SkillRegistry.cs** (Line 73): Use collection expression [note]
- **Core/Skills/SkillRegistry.cs** (Line 83): Use collection expression [note]
- **Core/Skills/SkillRegistry.cs** (Line 94): Use collection expression [note]
- **Core/Skills/SkillRegistry.cs** (Line 108): Use collection expression [note]
- **Program.cs** (Line 13): Use collection expression [note]
- **Program.cs** (Line 15): Use collection expression [note]
- **Program.cs** (Line 87): Use collection expression [note]
## UsingStatementResourceInitialization
Found 1 occurrences.
- **Api/OpenAiCompatibleClient.cs** (Line 109): Initialize object properties inside the 'using' statement to ensure that the object is disposed if an exception is thrown during initialization [warning]