Skip to content
Open
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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
if: steps.filter.outputs.source_code == 'true'
run: nix develop .#ci -c bash -c "make fmt && git diff --exit-code"

- name: Linter check
if: steps.filter.outputs.source_code == 'true'
run: nix develop .#ci -c make linter

- name: Check
if: steps.filter.outputs.source_code == 'true'
run: nix develop .#ci -c make check
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ check-sql: ## Lint all sql files
fix-sql: ## Fix all sql files
sqlfluff fix --dialect sqlite

linter:
go run cmd/linter/main.go

release: ## Create a new release tag
@echo "Current version: $(VERSION)"
@read -p "Enter new version (e.g., v0.2.0): " version; \
Expand All @@ -69,4 +72,4 @@ clean: ## Clean up binaries and build artifacts
help: ## Display this help screen
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: help fmt run build all api cli check test check-sql fix-sql clean release generate
.PHONY: help fmt run build all api cli check test check-sql fix-sql clean release generate linter
62 changes: 62 additions & 0 deletions cmd/linter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"errors"
"go/ast"
"go/parser"
"go/token"
"io/fs"
"log"
"os"
"path/filepath"
"slices"
"strconv"
)

var filesToSkip []string = []string{".", "swagger.go"}

func main() {

// Go to api/handlers
// This should be run in the project root
handlersPath := "internal/api/handlers/"
os.Chdir(handlersPath)

err := filepath.Walk(".", func(path string, info fs.FileInfo, err error) error {
if slices.Contains(filesToSkip, path) {
return nil
}

// Creating an AST tree by parsing
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, path, nil, parser.ParseComments)
if err != nil {
log.Println(err)
os.Exit(1)
}

// Now we can search for specific things like functions and imports
ast.Inspect(file, func(n ast.Node) bool {
// looking for an import, we shouldn't have dbmodels in handler
switch x := n.(type) {
case *ast.ImportSpec:

importedModule, _ := strconv.Unquote(x.Path.Value)

// yah messy, but for the sake of proposal
check := (importedModule == "github.com/acmcsufoss/api.acmcsuf.com/internal/api/store/dbmodels")
if check {
// This error is going to make me throw up lol
log.Println(errors.New("Bad import found: " + importedModule + " in " + handlersPath + path))
os.Exit(1)
}
}
return true
})
return nil
})
if err != nil {
log.Println(err)
os.Exit(1)
}
}
Loading