Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add staticcheck to actions #96

Merged
merged 3 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.17

- name: Cache Go modules
uses: actions/cache@v2
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.17

- name: Cache Go modules
uses: actions/cache@v2
Expand Down Expand Up @@ -58,3 +58,9 @@ jobs:
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=c.out -service=github

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Run staticcheck for possible optimizations
run: staticcheck -tests=false
6 changes: 4 additions & 2 deletions iflist.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,18 @@ func parseInterfaces(content []byte) *InterfaceList {
output := string(content)
lines := strings.Split(output, "\n")

interfaceRegex := regexp.MustCompile(`\*INTERFACES\*`)
routesRegex := regexp.MustCompile(`\*ROUTES\*`)
Comment on lines +70 to +71
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually regexp.MustCompile statements are kept outside of the function body, in var declarations at the top of the files they are used in. WDYT?

See discussion about it in the noglobals linter if you're curious

Copy link
Collaborator Author

@elivlo elivlo May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change this. @ChnMig mentioned it but I was not sure if we really need this.

for i, line := range lines {
if match, _ := regexp.MatchString(`[\*]INTERFACES[\*]`, line); match {
if interfaceRegex.MatchString(line) {
for _, l := range lines[i+2:] {
if iface := convertInterface(l); iface != nil {
list.Interfaces = append(list.Interfaces, iface)
}
}
}

if match, _ := regexp.MatchString(`[\*]ROUTES[\*]`, line); match {
if routesRegex.MatchString(line) {
for _, l := range lines[i+2:] {
if route := convertRoute(l); route != nil {
list.Routes = append(list.Routes, route)
Expand Down
4 changes: 1 addition & 3 deletions nmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,7 @@ func (s *Scanner) RunWithStreamer(stream Streamer, file string) (warnings []stri
// Process nmap stderr output containing none-critical errors and warnings.
// Everyone needs to check whether one or some of these warnings is a hard issue in their use case.
if stderrBuf.Len() > 0 {
for _, v := range strings.Split(strings.Trim(stderrBuf.String(), "\n"), "\n") {
warnings = append(warnings, v)
}
warnings = append(warnings, strings.Split(strings.Trim(stderrBuf.String(), "\n"), "\n")...)
}

// Check for warnings that will inevitably lead to parsing errors, hence, have priority.
Expand Down