Skip to content

Commit

Permalink
Port lint-filename to go
Browse files Browse the repository at this point in the history
Relates to #163
  • Loading branch information
kehiy authored and Sean-Der committed Sep 10, 2023
1 parent 13fc094 commit e0100b6
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 21 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/lint.reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ jobs:
name: Metadata
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: 'stable'

- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Checkout .goassets
uses: actions/checkout@v4
with:
Expand All @@ -32,7 +38,7 @@ jobs:
run: .github/.goassets/scripts/lint-commit-message.sh

- name: File names
run: .github/.goassets/scripts/lint-filename.sh
run: go run .github/.goassets/scripts/lint-filename.go

- name: Logging messages should not have trailing newlines
run: .github/.goassets/scripts/lint-no-trailing-newline-in-log-messages.sh
Expand Down
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Aurken Bilbao <[email protected]>
Benny Daon <[email protected]>
Daniele Sluijters <[email protected]>
David Zhao <[email protected]>
Kay <[email protected]>
Luke S <[email protected]>
Michiel De Backker <[email protected]>
Sean DuBois <[email protected]>
Expand Down
20 changes: 0 additions & 20 deletions scripts/lint-filename.sh

This file was deleted.

48 changes: 48 additions & 0 deletions scripts/lint_filename.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
SPDX-License-Identifier: MIT
*/
package main

import (
"fmt"
"os"
"path/filepath"
"regexp"
)

func main() {
parentDir, err := os.Getwd()
if err != nil {
fmt.Println(err)
os.Exit(1)
}

goRegex := regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9_]*\.go$`)

err = filepath.Walk(parentDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if info.IsDir() {
return nil
}

if filepath.Ext(path) != ".go" {
return nil
}

filename := filepath.Base(path)

if !goRegex.MatchString(filename) {
return fmt.Errorf("%s is not a valid filename for Go code, only alpha, numbers and underscores are supported", filename)
}

return nil
})
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}

0 comments on commit e0100b6

Please sign in to comment.