-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port lint-no-trailing-newline-in-log-messages
sh -> Go
- Loading branch information
1 parent
51bda7c
commit c6c47a7
Showing
3 changed files
with
52 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> | ||
SPDX-License-Identifier: MIT | ||
*/ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
parentDir, err := os.Getwd() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
logReg, err := regexp.Compile(`\.(Trace|Debug|Info|Warn|Error)f?\("[^"]*\\n"\)?`) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
err = filepath.Walk(parentDir, func(path string, info os.FileInfo, err error) error { | ||
if err != nil || info.IsDir() || filepath.Ext(path) != ".go" { | ||
return err | ||
} | ||
|
||
fileContents, err := os.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, match := range logReg.FindAll(fileContents, -1) { | ||
if !strings.Contains(string(match), "nolint") { | ||
return fmt.Errorf("Log format strings should have trailing new-line: %s\n", match) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
return nil | ||
}) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |