Skip to content

Commit

Permalink
CppCheck Warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
prak132 committed Sep 22, 2024
1 parent 66ecb48 commit 5247ce4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- ```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]
```
23 changes: 23 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5247ce4

Please sign in to comment.