porto

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

README

Porto

Tool for adding vanity imports URI to Go files.

e.g. package zipkin -> package zipkin // import "github.com/openzipkin/zipkin-go"

Install

go install github.com/jcchavezs/porto/cmd/porto

Getting started

Run the tool and display the changes without applying them

porto path/to/library

If you want the changes to be applied to the files directly, run:

porto -w path/to/library

If you just want to list the files that porto would change vanity import, run:

porto -l path/to/library

Inclusion/exclusion rules

porto skips autogenerated, internal, third party and vendored files by default. You can customize what files get included using some flags:

  • If you want to ignore files (e.g. proto generated files), pass the --skip-files flag:
porto --skip-files ".*\\.pb\\.go$" path/to/library
  • If you want to ignore directories (e.g. tooling directories), pass the --skip-dirs flag:
porto --skip-dirs "^tools$" path/to/library
  • If you want to include internal folders and directories skipped by default:
porto --include-internal --skip-dirs-use-default=false path/to/library
  • If you want to restrict to certain files e.g. doc.go you can use:
porto --restrict-to-files "doc.go$" path/to/library

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StdExcludeDirRegexps = []*regexp.Regexp{
	regexp.MustCompile("^vendor$"),
	regexp.MustCompile("^third_party$"),
	regexp.MustCompile("^testdata$"),
	regexp.MustCompile("^examples$"),
	regexp.MustCompile("^Godeps$"),
	regexp.MustCompile("^builtin$"),
}

StdExcludeDirRegexps is the standard directory exclusion list from golangci-lint. See https://github.com/golangci/golangci-lint/blob/master/pkg/packages/skip.go.

Functions

func FindAndAddVanityImportForDir

func FindAndAddVanityImportForDir(workingDir, absDir string, opts Options) (int, error)

FindAndAddVanityImportForDir scans all files in a folder and based on go.mod files encountered decides wether add a vanity import or not.

func GetRegexpList added in v0.4.0

func GetRegexpList(regexps string) ([]*regexp.Regexp, error)

Types

type Options

type Options struct {
	// writes result to file directly
	WriteResultToFile bool
	// List files to be changed
	ListDiffFiles bool
	// Set of regex for matching files to be skipped
	SkipFilesRegexes []*regexp.Regexp
	// Set of regex for matching directories to be skipped
	SkipDirsRegexes []*regexp.Regexp
	// Include internal packages
	IncludeInternal bool
	// Set of regex for matching files to be included
	RestrictToFilesRegexes []*regexp.Regexp
	// Set of regex for matching dirs to be included
	RestrictToDirsRegexes []*regexp.Regexp
}

Options represents the options for adding vanity import.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL