LCOV - code coverage report
Current view: top level - lintrule - root.go Coverage Total Hit
Test: coverage.lcov Lines: 69.2 % 13 9
Test Date: 2026-11-19 00:25:22 Functions: - 0 0

            Line data    Source code
       1              : package lintrule
       2              : 
       3              : import (
       4              :         "errors"
       5              :         "os"
       6              :         "path/filepath"
       7              : )
       8              : 
       9              : // ErrModuleRootNotFound は go.mod を上位へ辿っても見つからないことを表す。
      10              : var ErrModuleRootNotFound = errors.New("go.mod not found in any parent directory")
      11              : 
      12              : // ModuleRoot は go.mod のあるディレクトリを現在位置から上位へ辿って返す。
      13              : // 検査はリポジトリ全体を歩くので、テストの実行位置に依存しない起点が要る。
      14              : func ModuleRoot() (string, error) {
      15            1 :         dir, err := os.Getwd()
      16            1 :         if err != nil {
      17            0 :                 return "", err
      18            0 :         }
      19            1 :         for {
      20            1 :                 if _, statErr := os.Stat(filepath.Join(dir, "go.mod")); statErr == nil {
      21            1 :                         return dir, nil
      22            1 :                 }
      23            1 :                 parent := filepath.Dir(dir)
      24            1 :                 if parent == dir {
      25            0 :                         return "", ErrModuleRootNotFound
      26            0 :                 }
      27            1 :                 dir = parent
      28              :         }
      29              : }
        

Generated by: LCOV version 2.0-1