mirror of
https://github.com/go-gitea/gitea.git
synced 2024-08-22 20:33:46 +02:00
* update code.gitea.io/sdk/gitea v0.13.1 -> v0.13.2 * update github.com/go-swagger/go-swagger v0.25.0 -> v0.26.0 * update github.com/google/uuid v1.1.2 -> v1.2.0 * update github.com/klauspost/compress v1.11.3 -> v1.11.7 * update github.com/lib/pq 083382b7e6fc -> v1.9.0 * update github.com/markbates/goth v1.65.0 -> v1.66.1 * update github.com/mattn/go-sqlite3 v1.14.4 -> v1.14.6 * update github.com/mgechev/revive 246eac737dc7 -> v1.0.3 * update github.com/minio/minio-go/v7 v7.0.6 -> v7.0.7 * update github.com/niklasfasching/go-org v1.3.2 -> v1.4.0 * update github.com/olivere/elastic/v7 v7.0.21 -> v7.0.22 * update github.com/pquerna/otp v1.2.0 -> v1.3.0 * update github.com/xanzy/go-gitlab v0.39.0 -> v0.42.0 * update github.com/yuin/goldmark v1.2.1 -> v1.3.1
78 lines
2.5 KiB
Go
Vendored
78 lines
2.5 KiB
Go
Vendored
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Package imports implements a Go pretty-printer (like package "go/format")
|
|
// that also adds or removes import statements as necessary.
|
|
package imports // import "golang.org/x/tools/imports"
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"log"
|
|
|
|
"golang.org/x/tools/internal/gocommand"
|
|
intimp "golang.org/x/tools/internal/imports"
|
|
)
|
|
|
|
// Options specifies options for processing files.
|
|
type Options struct {
|
|
Fragment bool // Accept fragment of a source file (no package statement)
|
|
AllErrors bool // Report all errors (not just the first 10 on different lines)
|
|
|
|
Comments bool // Print comments (true if nil *Options provided)
|
|
TabIndent bool // Use tabs for indent (true if nil *Options provided)
|
|
TabWidth int // Tab width (8 if nil *Options provided)
|
|
|
|
FormatOnly bool // Disable the insertion and deletion of imports
|
|
}
|
|
|
|
// Debug controls verbose logging.
|
|
var Debug = false
|
|
|
|
// LocalPrefix is a comma-separated string of import path prefixes, which, if
|
|
// set, instructs Process to sort the import paths with the given prefixes
|
|
// into another group after 3rd-party packages.
|
|
var LocalPrefix string
|
|
|
|
// Process formats and adjusts imports for the provided file.
|
|
// If opt is nil the defaults are used, and if src is nil the source
|
|
// is read from the filesystem.
|
|
//
|
|
// Note that filename's directory influences which imports can be chosen,
|
|
// so it is important that filename be accurate.
|
|
// To process data ``as if'' it were in filename, pass the data as a non-nil src.
|
|
func Process(filename string, src []byte, opt *Options) ([]byte, error) {
|
|
var err error
|
|
if src == nil {
|
|
src, err = ioutil.ReadFile(filename)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
if opt == nil {
|
|
opt = &Options{Comments: true, TabIndent: true, TabWidth: 8}
|
|
}
|
|
intopt := &intimp.Options{
|
|
Env: &intimp.ProcessEnv{
|
|
GocmdRunner: &gocommand.Runner{},
|
|
},
|
|
LocalPrefix: LocalPrefix,
|
|
AllErrors: opt.AllErrors,
|
|
Comments: opt.Comments,
|
|
FormatOnly: opt.FormatOnly,
|
|
Fragment: opt.Fragment,
|
|
TabIndent: opt.TabIndent,
|
|
TabWidth: opt.TabWidth,
|
|
}
|
|
if Debug {
|
|
intopt.Env.Logf = log.Printf
|
|
}
|
|
return intimp.Process(filename, src, intopt)
|
|
}
|
|
|
|
// VendorlessPath returns the devendorized version of the import path ipath.
|
|
// For example, VendorlessPath("foo/bar/vendor/a/b") returns "a/b".
|
|
func VendorlessPath(ipath string) string {
|
|
return intimp.VendorlessPath(ipath)
|
|
}
|