Tool for adding vanity import to Go code

Overview

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
Comments
  • Add support for skipping based on directories

    Add support for skipping based on directories

    The current --skip-files option can only skip files based on the base file name. This is useful to e.g. skip by extension, but It doesn't help when you want to skip all files in a directory. For example, in opentelemetry-go we may want to skip this third_party folder.

    One alternative to be able to do this would be to change the --skip-files flag to skip based on the full filepath instead of the base filename; another would be to add an analogous --skip-dirs to skip certain directories.

    opened by mx-psi 4
  • Add options for skipping directories

    Add options for skipping directories

    What does this PR do?

    • Add --skip-dirs flag
    • Add --skip-dirs-use-default flag
    • Update documentation

    See a test run on open-telemetry/opentelemetry-go#2280

    opened by mx-psi 1
  • fix: skips vanity import when applied directory to internal module.

    fix: skips vanity import when applied directory to internal module.

    This PR skips adding vanity import for internal modules, currently running porto -w ./something/internal/mymodule still adds the vanity import although this is an internal module.

    Comes from https://github.com/open-telemetry/opentelemetry-go/pull/2255/checks?check_run_id=3723701674#step:9:14

    opened by jcchavezs 0
  • Fails on list if found

    Fails on list if found

    This is specially useful for CI checks because otherwise we need to list the files and count the output if we want to fail e.g. https://github.com/elastic/apm-agent-go/pull/960/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R33.

    opened by jcchavezs 0
  • feat: adds support for ignoring files.

    feat: adds support for ignoring files.

    This PR adds support for ignoring files instead of making an assumption on what files to ignore (e.g. relaying on // Generated code from proto compilation).

    opened by jcchavezs 0
  • Add -l option

    Add -l option

    Since it is convenient to use same gofmt options, we should consider also adding -l function to list those files that differ from the output.

    -l list files whose formatting differs

    opened by jcchavezs 0
Releases(v0.4.0)
  • v0.4.0(Oct 27, 2021)

    What's Changed

    • Fix error message on incorrect regexp by @mx-psi in https://github.com/jcchavezs/porto/pull/14
    • Add options for skipping directories by @mx-psi in https://github.com/jcchavezs/porto/pull/15

    Full Changelog: https://github.com/jcchavezs/porto/compare/v0.3.0...v0.4.0

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Oct 12, 2021)

    What's Changed

    • Add --include-internal flag to include vanity import in internal packages by @mx-psi in https://github.com/jcchavezs/porto/pull/11
    • Skip generated files based on Go convention by @mx-psi in https://github.com/jcchavezs/porto/pull/12

    New Contributors

    • @mx-psi made their first contribution in https://github.com/jcchavezs/porto/pull/11

    Full Changelog: https://github.com/jcchavezs/porto/compare/v0.2.1...v0.3.0

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Sep 25, 2021)

Owner
José Carlos Chávez
Software engineer, Zipkin team member and Peruvian llama ambassador. Read me at https://medium.com/devthoughts
José Carlos Chávez
🐶 Automated code review tool integrated with any code analysis tools regardless of programming language

reviewdog - A code review dog who keeps your codebase healthy. reviewdog provides a way to post review comments to code hosting service, such as GitHu

reviewdog 5.9k Jan 2, 2023
A Golang tool that does static analysis, unit testing, code review and generate code quality report.

goreporter A Golang tool that does static analysis, unit testing, code review and generate code quality report. This is a tool that concurrently runs

360 Enterprise Security Group, Endpoint Security, inc. 3k Jan 8, 2023
🐶 Automated code review tool integrated with any code analysis tools regardless of programming language

reviewdog - A code review dog who keeps your codebase healthy. reviewdog provides a way to post review comments to code hosting service, such as GitHu

reviewdog 5.9k Jan 7, 2023
The most opinionated Go source code linter for code audit.

go-critic Highly extensible Go source code linter providing checks currently missing from other linters. There is never too much static code analysis.

null 1.5k Jan 6, 2023
Sloc, Cloc and Code: scc is a very fast accurate code counter with complexity calculations and COCOMO estimates written in pure Go

Sloc Cloc and Code (scc) A tool similar to cloc, sloccount and tokei. For counting physical the lines of code, blank lines, comment lines, and physica

Ben Boyter 4.1k Jan 4, 2023
a tool for code clone detection

dupl dupl is a tool written in Go for finding code clones. So far it can find clones only in the Go source files. The method uses suffix tree for seri

Michal Bohuslávek 302 Dec 12, 2022
depth is tool to retrieve and visualize Go source code dependency trees.

depth is tool to retrieve and visualize Go source code dependency trees. Install Download the appropriate binary for your platform from the Rele

Kyle Banks 810 Dec 30, 2022
Tool to populate your code with traceable and secure error codes

Essential part of any project, especially customer facing is proper and secure error handling. When error happens and customer reports it, it would be nice to know the context of the error and where it exactly occured.

vs 51 Sep 28, 2022
a simple golang SSA viewer tool use for code analysis or make a linter

ssaviewer A simple golang SSA viewer tool use for code analysis or make a linter ssa.html generate code modify from src/cmd/compile/internal/ssa/html.

null 7 May 17, 2022
Refactoring and code transformation tool for Go.

gopatch is a tool to match and transform Go code. It is meant to aid in refactoring and restyling.

Uber Go 532 Dec 30, 2022
[mirror] This is a linter for Go source code.

Golint is a linter for Go source code. Installation Golint requires a supported release of Go. go get -u golang.org/x/lint/golint To find out where g

Go 4k Dec 23, 2022
Run linters from Go code -

Lint - run linters from Go Lint makes it easy to run linters from Go code. This allows lint checks to be part of a regular go build + go test workflow

Surul Software Labs GmbH 67 Sep 27, 2022
A reference for the Go community that covers the fundamentals of writing clean code and discusses concrete refactoring examples specific to Go.

A reference for the Go community that covers the fundamentals of writing clean code and discusses concrete refactoring examples specific to Go.

Lasse Martin Jakobsen 2.5k Jan 1, 2023
A static code analyzer for annotated TODO comments

todocheck todocheck is a static code analyzer for annotated TODO comments. It let's you create actionable TODOs by annotating them with issues from an

Preslav Mihaylov 394 Dec 7, 2022
A little fast cloc(Count Lines Of Code)

gocloc A little fast cloc(Count Lines Of Code), written in Go. Inspired by tokei. Installation $ go get -u github.com/hhatto/gocloc/cmd/gocloc Usage

Hideo Hattori 635 Jan 6, 2023
🔒🌍 Security scanner for your Terraform code

????tfsec uses static analysis of your terraform templates to spot potential security issues.

tfsec 5.5k Dec 30, 2022
Know when GC runs from inside your golang code

gcnotifier gcnotifier provides a way to receive notifications after every run of the garbage collector (GC). Knowing when GC runs is useful to instruc

Carlo Alberto Ferraris 173 Dec 26, 2022
a Go code to detect leaks in JS files via regex patterns

a Go code to detect leaks in JS files via regex patterns

João Teles 113 Nov 13, 2022
go-linters How to grow Go code as a bonsai: the style, the rules, the linters

How to grow Go code as a bonsai: the style, the rules, the linters (Definition 2021 Hackaton) Build go build -buildmode=plugin plugin/plugin.go Run go

Mercuryo.io 2 Nov 9, 2022