Skip to content

Commit

Permalink
fix: [#5] Ensure that file names get tested in the root
Browse files Browse the repository at this point in the history
  • Loading branch information
sbp-bvanb committed Nov 2, 2024
1 parent 1e350ba commit 6cc0956
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .prolayout.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
---
module: "github.com/wimspaargaren/prolayout"
root:
- name: ""
files:
- name: main.go
- name: ".test"
- name: "bar"
- name: "internal"
dirs:
- name: analyzer
- name: errors
- name: model
- name: "tests"
31 changes: 24 additions & 7 deletions internal/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package analyzer

import (
"fmt"
"regexp"
"strings"

Expand Down Expand Up @@ -51,26 +52,30 @@ func (r *runner) assess(pass *analysis.Pass) error {

func (r *runner) assessDir(pass *analysis.Pass) (*model.Dir, error) {
module := r.Root.Module
// fmt.Println("----1---", pass.Pkg.Path())

packagePathWithoutModule := strings.ReplaceAll(pass.Pkg.Path(), module, "")
packagePathWithoutModule = strings.TrimPrefix(packagePathWithoutModule, "/")
packageSplittedPerFolder := splitPath(packagePathWithoutModule)
packageSplitPerFolder := splitPath(packagePathWithoutModule)
dirs := r.Root.Root
dir := &model.Dir{}

for _, folder := range packageSplittedPerFolder {
if len(dirs) == 0 || strings.HasSuffix(folder, ".test") {
return nil, nil
}
for _, folder := range packageSplitPerFolder {
// if len(dirs) == 0 || strings.HasSuffix(folder, ".test") {
// return nil, nil
// }

fmt.Println("-------42-------", folder)

Check failure on line 68 in internal/analyzer/analyzer.go

View workflow job for this annotation

GitHub Actions / MCVS-golang-action (lint)

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)

Check failure on line 68 in internal/analyzer/analyzer.go

View workflow job for this annotation

GitHub Actions / MCVS-golang-action (lint)

unhandled-error: Unhandled error in call to function fmt.Println (revive)
res, ok, err := matchDir(dirs, folder)
if err != nil {
return nil, err
}
if !ok {
if len(pass.Files) == 0 || packagePathWithoutModule == "" {
// if len(pass.Files) == 0 || packagePathWithoutModule == "" {
if len(pass.Files) == 0 {
continue
}
pass.ReportRangef(pass.Files[0], "package not allowed: %s, %s not found in allowed names: [%s]", packagePathWithoutModule, folder, strings.Join(dirsNames(dirs), ","))
pass.ReportRangef(pass.Files[0], "folder not allowed: %s, %s not found in allowed names: [%s]", packagePathWithoutModule, folder, strings.Join(dirsNames(dirs), ","))
break
}
dir = res
Expand Down Expand Up @@ -119,6 +124,18 @@ func (r *runner) matchFiles(files []*model.File, name string) (bool, error) {

func matchDir(dir []*model.Dir, name string) (*model.Dir, bool, error) {
for _, d := range dir {
// if d.Name == "" {
fmt.Println("-------43----", d.Name, name, "===")

Check failure on line 128 in internal/analyzer/analyzer.go

View workflow job for this annotation

GitHub Actions / MCVS-golang-action (lint)

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)

Check failure on line 128 in internal/analyzer/analyzer.go

View workflow job for this annotation

GitHub Actions / MCVS-golang-action (lint)

unhandled-error: Unhandled error in call to function fmt.Println (revive)
// }

if d.Name == "" {
if name == "" {
return d, true, nil
}
// return nil, false, nil
continue
}

match, err := regexp.MatchString(d.Name, name)
if err != nil {
return nil, false, errors.ErrInvalidDirNameRegex{DirName: d.Name}
Expand Down

0 comments on commit 6cc0956

Please sign in to comment.