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 f80eccd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
16 changes: 14 additions & 2 deletions .prolayout.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
---
module: "github.com/wimspaargaren/prolayout"
root:
- name: "bar"
- name: "internal"
- name: ""
files:
- name: main.go
- name: main_test.go
# - name: .test
- name: bar
- name: internal
dirs:
- name: analyzer
files:
- name: analyzer.go
- name: analyzer_test.go
- name: errors
- name: model
- name: "tests"
45 changes: 38 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())

Check failure on line 55 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 55 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)

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], "packagePathWithoutModule: '%s' not allowed as folder: '%s' was not found in allowed names: [%s]", packagePathWithoutModule, folder, strings.Join(dirsNames(dirs), ","))
break
}
dir = res
Expand All @@ -92,12 +97,21 @@ func (r *runner) assessFiles(pass *analysis.Pass, dir *model.Dir) error {
if dir == nil || len(dir.Files) == 0 {
return nil
}

for _, file := range pass.Files {
fmt.Println("---------------------52------", file.Name.Name)

Check failure on line 102 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)

matchedFile, err := r.matchFiles(dir.Files, file.Name.Name)
if err != nil {
return err
}

if !matchedFile {

for _, f := range file.Comments {
fmt.Println("fdsfdsfs", f.List[0])

Check failure on line 112 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)
}

pass.ReportRangef(file, "file not allowed in this folder: %s", file.Name.Name)
}
}
Expand All @@ -106,6 +120,8 @@ func (r *runner) assessFiles(pass *analysis.Pass, dir *model.Dir) error {

func (r *runner) matchFiles(files []*model.File, name string) (bool, error) {
for _, f := range files {
fmt.Println("----------------------------45---------------------", f.Name)

Check failure on line 123 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)
fmt.Println("----------------------------46-----------------------------", name)

Check failure on line 124 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)
match, err := regexp.MatchString(f.Name, name+".go")
if err != nil {
return false, errors.ErrInvalidFileNameRegex{FileName: f.Name}
Expand All @@ -119,6 +135,21 @@ 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)

Check failure on line 139 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)
fmt.Println("-------44-------", name)

Check failure on line 140 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)
// }

if d.Name == "" {

if name == "" || name == ".test" {
// 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 f80eccd

Please sign in to comment.