From 5247ce48bbcd89051ad0cb4a8a0c0165460ea786 Mon Sep 17 00:00:00 2001 From: prak132 Date: Sun, 22 Sep 2024 12:11:20 -0700 Subject: [PATCH] CppCheck Warnings --- README.md | 10 +++++++++- build.gradle | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d22f609..e9390fe 100644 --- a/README.md +++ b/README.md @@ -160,4 +160,12 @@ I need to go back to a previous commit: - ```git checkout HASH``` To undo the going back: -- ```git switch -``` <-- goes back to latest commit \ No newline at end of file +- ```git switch -``` <-- goes back to latest commit + +## CppCheck Warnings +``` +src/frc846/cpp/frc846/other/trajectory_generator.cc:68:18: warning: Consider using std::transform algorithm instead of a raw loop. [useStlAlgorithm] +src/y2024/cpp/commands/teleop/drive_command.cc:67:8: warning: Condition 'is_robot_centric' is always false [knownConditionTrueFalse] +src/frc846/cpp/frc846/util/math.cc:19:0: warning: The function 'VerticalDeadband' is never used. [unusedFunction] +src/frc846/cpp/frc846/util/math.cc:46:0: warning: The function 'CoterminalSum' is never used. [unusedFunction] +``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index b634b0e..4fd55e3 100644 --- a/build.gradle +++ b/build.gradle @@ -113,8 +113,31 @@ spotless { check.dependsOn spotlessApply task runCppcheck(type: Exec) { + def outputBuffer = new ByteArrayOutputStream() commandLine 'cppcheck', '--enable=all', '--template=gcc', '--force', '--suppress=missingIncludeSystem', '--suppress=missingInclude', '--check-level=exhaustive', 'src/' + standardOutput = outputBuffer + errorOutput = outputBuffer + doLast { + def cppcheckOutput = outputBuffer.toString("UTF-8") + def warnings = cppcheckOutput.readLines().findAll { it.contains("warning") && !it.contains("nofile:") } + def reportContent = warnings.isEmpty() ? "No warnings or errors found." : warnings.join("\n") + def cppcheckSection = """ +## CppCheck Warnings +``` +${reportContent.trim()} +``` +""" + def readmeFile = file('README.md') + def readmeContent = readmeFile.text + def cppcheckRegex = /## CppCheck Warnings\n```[\s\S]*?```/ + if (readmeContent.find(cppcheckRegex)) { + readmeContent = readmeContent.replaceAll(cppcheckRegex, cppcheckSection.trim()) + } else { + readmeContent += "\n" + cppcheckSection.trim() + } + readmeFile.text = readmeContent + } } check.dependsOn runCppcheck