No description
  • Go 97.7%
  • Makefile 2.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2024-03-27 13:32:40 +01:00
.github/workflows chore: update dependency, CI, and linter 2024-03-27 03:50:49 +01:00
testdata/src chore: clean 2023-06-25 21:27:40 +02:00
.gitignore chore: setup 2023-06-25 14:23:06 +02:00
.golangci.yml chore: update dependency, CI, and linter 2024-03-27 03:50:49 +01:00
go.mod chore: update dependency, CI, and linter 2024-03-27 03:50:49 +01:00
go.sum chore: update dependency, CI, and linter 2024-03-27 03:50:49 +01:00
LICENSE chore: migrate to golangci 2023-06-25 21:26:16 +02:00
Makefile feat: birth 2023-06-25 14:35:31 +02:00
module.go fix: fallback on error 2024-03-27 13:32:40 +01:00
module_test.go test: improve tests 2023-06-26 03:31:51 +02:00
readme.md docs: fix typo 2024-03-27 02:04:53 +01:00

modinfo

This module contains:

  • an analyzer that returns module information.
  • methods to find and read go.mod file

Examples

package main

import (
	"fmt"

	"github.com/golangci/modinfo"
	"golang.org/x/tools/go/analysis"
	"golang.org/x/tools/go/analysis/passes/inspect"
)

var Analyzer = &analysis.Analyzer{
    Name: "example",
    Doc:  "Example",
    Run: func(pass *analysis.Pass) (interface{}, error) {
        file, err := modinfo.ReadModuleFileFromPass(pass)
        if err != nil {
          return nil, err
        }

        fmt.Println("go.mod", file)

        // TODO

        return nil, nil
    },
    Requires: []*analysis.Analyzer{
        inspect.Analyzer,
        modinfo.Analyzer,
    },
}
package main

import (
	"fmt"

	"github.com/golangci/modinfo"
	"golang.org/x/tools/go/analysis"
	"golang.org/x/tools/go/analysis/passes/inspect"
)

var Analyzer = &analysis.Analyzer{
    Name: "example",
    Doc:  "Example",
    Run: func(pass *analysis.Pass) (interface{}, error) {
        info, err := modinfo.FindModuleFromPass(pass)
        if err != nil {
          return nil, err
        }

        fmt.Println("Module", info.Dir)

        // TODO

        return nil, nil
    },
    Requires: []*analysis.Analyzer{
        inspect.Analyzer,
        modinfo.Analyzer,
    },
}