Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Rex-82 committed Jul 14, 2024
0 parents commit 7fd7e94
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
go.work.sum

# env file
.env
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Simone Ferretti

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
100 changes: 100 additions & 0 deletions app/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package main

import (
"bufio"
"fmt"
"io/fs"
"os"
"path/filepath"
"strconv"
"strings"
)

func main() {
command := os.Args
if len(command) > 1 {
path := command[1]
err := walkDirectory(path)
if err != nil {
println(err)
}
}
}

func scanFile(file *os.File) ([]string, error) {
scanner := bufio.NewScanner(file)

line := 1
found := false
var foundLines []string

for scanner.Scan() {
if strings.Contains(scanner.Text(), "TODO:") {
found = true
foundLines = append(foundLines, strconv.Itoa(line))
} else if found && len(scanner.Text()) == 0 {
found = false
}
if found {
foundLines = append(foundLines, strings.Trim(scanner.Text(), " "))
}

line++
}

if err := scanner.Err(); err != nil {
return foundLines, err
}

return foundLines, nil

}

func readFile(path string) error {
file, err := os.Open(path)
if err != nil {
return err
}

defer file.Close()

foundLine, err := scanFile(file)
if err != nil {
return err
}

if len(foundLine) > 0 {

fmt.Println("=>", path)
fmt.Println("-----------------------------------------------------------------------")

for i := 0; i < len(foundLine); i++ {

fmt.Println(" ", foundLine[i])
}

fmt.Println("-----------------------------------------------------------------------")
}
return nil

}

func walkDirectory(path string) error {
err := filepath.WalkDir(path, func(path string, res fs.DirEntry, err error) error {
// fmt.Println(res.Name(), res.IsDir())
if !res.IsDir() {
err := readFile(path)
if err != nil {
return err
}
}
return nil
})

if err != nil {
return err
}

return nil

}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module todocheck

go 1.22.5

0 comments on commit 7fd7e94

Please sign in to comment.