All Projects → alexkohler → unimport

alexkohler / unimport

Licence: MIT license
unimport is a Go static analysis tool to find unnecessary import aliases.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to unimport

eba
EBA is a static bug finder for C.
Stars: ✭ 14 (-78.12%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
Sonar Dotnet
Code analyzer for C# and VB.NET projects https://redirect.sonarsource.com/plugins/vbnet.html
Stars: ✭ 466 (+628.13%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
Phpstan Doctrine
Doctrine extensions for PHPStan
Stars: ✭ 338 (+428.13%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
phpstan-nette
Nette Framework class reflection extension for PHPStan & framework-specific rules
Stars: ✭ 87 (+35.94%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
lints
Lint all your JavaScript, CSS, HTML, Markdown and Dockerfiles with a single command
Stars: ✭ 14 (-78.12%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
nakedret
nakedret is a Go static analysis tool to find naked returns in functions greater than a specified function length.
Stars: ✭ 82 (+28.13%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
Dg
[LLVM Static Slicer] Various program analyses, construction of dependence graphs and program slicing of LLVM bitcode.
Stars: ✭ 242 (+278.13%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
identypo
identypo is a Go static analysis tool to find typos in identifiers (functions, function calls, variables, constants, type declarations, packages, labels).
Stars: ✭ 26 (-59.37%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
Sonar Java
☕️ SonarSource Static Analyzer for Java Code Quality and Security
Stars: ✭ 745 (+1064.06%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
Sonarjs
SonarSource Static Analyzer for JavaScript and TypeScript
Stars: ✭ 696 (+987.5%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
sonarlint4netbeans
SonarLint integration for Apache Netbeans
Stars: ✭ 23 (-64.06%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
Phpinspectionsea
A Static Code Analyzer for PHP (a PhpStorm/Idea Plugin)
Stars: ✭ 1,211 (+1792.19%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
Prealloc
prealloc is a Go static analysis tool to find slice declarations that could potentially be preallocated.
Stars: ✭ 419 (+554.69%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
Phpdoc Parser
Next-gen phpDoc parser with support for intersection types and generics
Stars: ✭ 569 (+789.06%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
Cfmt
cfmt is a tool to wrap Go comments over a certain length to a new line.
Stars: ✭ 28 (-56.25%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
Phpstan
PHP Static Analysis Tool - discover bugs in your code without running it!
Stars: ✭ 10,534 (+16359.38%)
Mutual labels:  static-code-analysis, static-analysis, static-analyzer
Pyt
A Static Analysis Tool for Detecting Security Vulnerabilities in Python Web Applications
Stars: ✭ 2,061 (+3120.31%)
Mutual labels:  static-code-analysis, static-analysis
klara
Automatic test case generation for python and static analysis library
Stars: ✭ 250 (+290.63%)
Mutual labels:  static-code-analysis, static-analysis
Infer
A static analyzer for Java, C, C++, and Objective-C
Stars: ✭ 12,823 (+19935.94%)
Mutual labels:  static-code-analysis, static-analysis
Codeclimate
Code Climate CLI
Stars: ✭ 2,273 (+3451.56%)
Mutual labels:  static-code-analysis, static-analysis

unimport

unimport is a Go static analysis tool to find unnecessary import aliases.

Installation

go get -u github.com/alexkohler/unimport

Usage

Similar to other Go static anaylsis tools (such as golint, go vet) , unimport can be invoked with one or more filenames, directories, or packages named by its import path. Unimport also supports the ... wildcard.

unimport files/directories/packages

Currently, no flag are supported. A -w flag may be added in the future to automatically remove aliases where possible (Similar to gofmt's -w flag).

Purpose

As noted in Go's Code Review comments:

Avoid renaming imports except to avoid a name collision; good package names should not require renaming. In the event of collision, prefer to rename the most local or project-specific import.

This tool will check if any import aliases are truly needed (by ensuring there is a name collision that would exist without the import alias). This tool will ignore import paths containing dashes and dots, as these are generally useful aliases while importing a specific revision. For example, in gometalinter, there are some imports like kingpin "gopkg.in/alecthomas/kingpin.v3-unstable". This is a reasonable import alias and will not be flagged.

Example

Running unimports on the Go source:

$ unimport $GOROOT/src/...
cmd/go/pkg.go:18 unnecessary import alias pathpkg
go/build/build.go:19 unnecessary import alias pathpkg
go/internal/gcimporter/gcimporter.go:23 unnecessary import alias exact
os/pipe_test.go:14 unnecessary import alias osexec
os/os_windows_test.go:10 unnecessary import alias osexec

Below are some of the arguably unneeded import aliases it found:

// go/internal/gcimporter/gcimporter.go
import (                                                                                       
    "bufio"                                                                                    
    "errors"                                                                                   
    "fmt"                                                                                      
    "go/build"                                                                                 
    "go/token"                                                                                 
    "io"                                                                                       
    "io/ioutil"                                                                                
    "os"                                                                                       
    "path/filepath"                                                                            
    "sort"                                                                                     
    "strconv"                                                                                  
    "strings"                                                                                  
    "text/scanner"                                                                             
                                                                                               
    exact "go/constant"                                                                        
    "go/types"                                                                                 
)


// os/pipe_test.go.go
import (                                                                                       
    "fmt"                                                                                      
    "internal/testenv"                                                                         
    "os"                                                                                       
    osexec "os/exec"                                                                           
    "os/signal"                                                                                
    "syscall"                                                                                  
    "testing"                                                                                  
)

TODO

  • Unit tests
  • Flagging of packages that contain an uppercase letter or underscore
  • -w flag to write changes to file where/if possible
  • Globbing support (e.g. unimport *.go)

Contributing

Pull requests welcome!

  • nakedret - Finds naked returns.
  • prealloc - Finds slice declarations that could potentially be preallocated.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].