-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
83 lines (72 loc) · 1.84 KB
/
Copy pathmain.go
File metadata and controls
83 lines (72 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"bufio"
"fmt"
"os"
"path/filepath"
"strings"
)
const VERSION = "v2.0.0"
type Issue struct {
File string
Line int
Severity string
Message string
}
func main() {
path := "."
if len(os.Args) > 1 {
path = os.Args[1]
}
fmt.Println("========================================")
fmt.Printf(" AI-Code-Reviewer %s\n", VERSION)
fmt.Println(" AI-powered code review assistant")
fmt.Println("========================================")
fmt.Println()
var issues []Issue
filepath.Walk(path, func(p string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() {
return nil
}
ext := filepath.Ext(p)
if ext == ".go" || ext == ".py" || ext == ".js" || ext == ".ts" {
reviewFile(p, &issues)
}
return nil
})
fmt.Printf("\nFound %d issues:\n\n", len(issues))
for _, issue := range issues {
icon := "[!]"
if issue.Severity == "warning" {
icon = "[-]"
} else if issue.Severity == "info" {
icon = "[i]"
}
fmt.Printf(" %s %s:%d - %s\n", icon, issue.File, issue.Line, issue.Message)
}
}
func reviewFile(path string, issues *[]Issue) {
file, err := os.Open(path)
if err != nil {
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
lineNum := 0
for scanner.Scan() {
lineNum++
line := scanner.Text()
if strings.Contains(line, "TODO") {
*issues = append(*issues, Issue{path, lineNum, "info", "TODO comment found"})
}
if strings.Contains(line, "FIXME") {
*issues = append(*issues, Issue{path, lineNum, "warning", "FIXME comment found - needs attention"})
}
if strings.Contains(line, "fmt.Println") && strings.HasSuffix(path, ".go") {
*issues = append(*issues, Issue{path, lineNum, "info", "Debug print statement - consider removing"})
}
if len(line) > 120 {
*issues = append(*issues, Issue{path, lineNum, "warning", "Line exceeds 120 characters"})
}
}
}