clang-tidy parser and executor #26

Merged
张泊明518370910136 merged 26 commits from clang-tidy into master 2024-05-18 02:50:13 +08:00
3 changed files with 56 additions and 5 deletions
Showing only changes of commit 061664eb70 - Show all commits

@ -1 +1 @@
Subproject commit 267f23cc74cea628850633dd39d7a1f37d7f7eb3
Subproject commit bb8c33dc62742f7fc9f25ac91582fc4fa4ac3d5d

View File

@ -47,7 +47,7 @@ func Parse(executorResult stage.ExecutorResult, conf Conf) stage.ParserResult {
// }
return stage.ParserResult{
Score: get_score(formatted_messages, conf),
Comment: "",
Comment: get_comment(formatted_messages),
}
}
zjc_he marked this conversation as resolved Outdated

We just put all the output of the parser in Comment.

We just put all the output of the parser in Comment.

Do you mean the json file which shows the whole detail of outputs? That might be really really long

Do you mean the json file which shows the whole detail of outputs? That might be really really long

The comment just gives human readable results. We may log the actual output for further details, but the comment will be replied in gitea issues. So we can just keep it short.

The comment just gives human readable results. We may log the actual output for further details, but the comment will be replied in gitea issues. So we can just keep it short.

A current version of comment:

Test results summary

  1. codequality-unchecked-malloc-result: 0
  2. codequality-no-global-variables: 0
  3. codequality-no-header-guard: 0
  4. codequality-no-fflush-stdin: 0
  5. readability-function-size: 0
  6. readability-identifier-naming: 0
  7. readability-redundant: 0
  8. readability-misleading-indentation: 0
  9. readability-misplaced-array-index: 0
  10. cppcoreguidelines-init-variables: 1
  11. bugprone-suspicious-string-compare: 0
  12. google-global-names-in-headers: 0
  13. clang-diagnostic: 1
  14. clang-analyzer: 0
  15. misc: 8
  16. performance: 4
  17. others: 187

I followed the version in ve482 issue

A current version of comment: ### Test results summary 1. codequality-unchecked-malloc-result: 0 2. codequality-no-global-variables: 0 3. codequality-no-header-guard: 0 4. codequality-no-fflush-stdin: 0 5. readability-function-size: 0 6. readability-identifier-naming: 0 7. readability-redundant: 0 8. readability-misleading-indentation: 0 9. readability-misplaced-array-index: 0 10. cppcoreguidelines-init-variables: 1 11. bugprone-suspicious-string-compare: 0 12. google-global-names-in-headers: 0 13. clang-diagnostic: 1 14. clang-analyzer: 0 15. misc: 8 16. performance: 4 17. others: 187 I followed the version in ve482 issue

View File

@ -1,10 +1,14 @@
package clang_tidy
func Contains[T comparable](arr []T, element T) bool {
import (
"fmt"
"strings"
)
func Contains(arr []string, element string) bool {
for i := range arr {
// TODO: The keyword in json report might also be an array, need to split it
// TODO: Might use string.Contains() rather than ==
if element == arr[i] {
if strings.Contains(arr[i], element) {
return true
}
}
@ -24,3 +28,50 @@ func get_score(json_messages []json_message, conf Conf) int {
}
return fullmark
}
func get_comment(json_messages []json_message) string {
res := "```\n### Test results summary\n\n"
keys := [...]string{
"codequality-unchecked-malloc-result",
"codequality-no-global-variables",
"codequality-no-header-guard",
"codequality-no-fflush-stdin",
"readability-function-size",
"readability-identifier-naming",
"readability-redundant",
"readability-misleading-indentation",
"readability-misplaced-array-index",
"cppcoreguidelines-init-variables",
"bugprone-suspicious-string-compare",
"google-global-names-in-headers",
"clang-diagnostic",
"clang-analyzer",
"misc",
"performance",
"others",
}
mapping := map[string]int{}
for _, key := range keys {
mapping[key] = 0
}
for _, json_message := range json_messages {
keyword := json_message.Check_name
flag := true
for key := range mapping {
if strings.Contains(keyword, key) {
mapping[key] += 1
flag = false
break
}
}
if flag {
mapping["others"] += 1
}
}
for i, key := range keys {
res = fmt.Sprintf("%s%d. %s: %d\n", res, i+1, key, mapping[key])
}
res += "```"
return res
}