magefile / mage

a Make/rake-like dev tool using Go

Home Page:https://magefile.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error for "Imported and not Used"

sheldonhull opened this issue · comments

./mage_output_file.go:18:2: imported and not used: "github.com/sheldonhull/magetools/tooling" as tooling_mageimport
Error: error compiling magefiles

I'm trying to test importing a remote package for "retooling" based on your original blog post on this.

I've tried a lot of combinations to get the import to work and it just won't.

Reproducing

  • Grab modules
go get -u github.com/sheldonhull/magetools@main
go get -u github.com/pterm/pterm@latest
  • Add import line
//+build mage

// upgrade remote packages like this: go get github.com/sheldonhull/magetools/tooling
package main

import (
	"github.com/magefile/mage/mg"
	"github.com/pterm/pterm"
	// mage:import tooling
	_ "github.com/sheldonhull/magetools/tooling"
)

// tools is a list of Go tools to install to avoid polluting global modules.
var toolList = []string{ //nolint:gochecknoglobals // ok to be global for tooling setup
	"github.com/goreleaser/goreleaser@v0.174.1",
	"golang.org/x/tools/cmd/goimports@master",
	"github.com/sqs/goreturns@master",
	"github.com/golangci/golangci-lint/cmd/golangci-lint@master",
	"github.com/dustinkirkland/golang-petname/cmd/petname@master",
}

// Init runs multiple tasks to initialize all the requirements for running a project for a new contributor.
func Init() error {
	pterm.Success.Println("running Init()...")
	tooling.InstallTools(toolList)
	return nil
}

I've tried without namespace, and it seems to go into a recursive loop when VSCode runs format, by adding the underscored package over and over.

The current source magefile I'm trying to modify is here: magetools any insight would be appreciated. Really trying to figure out the remote imports.

Duplicate of #363