Skip to content

AntonBraer/constantcheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

constantcheck


constantcheck is a golang analyzer for checking the possibility of replacing the literals used in the code with constants from already imported packages.

Usage

./constantcheck ./...

Examples

Let's say we have a project structure like this:

Structure main.go helps.go
├── helps
│   ├── helps.go
├──main.go
package main

import (
	"fmt"

	"example/helps"
)

func main() {
	if err := helps.Ping(); err != nil{
		fmt.Println("myImportantError")	
    }
}
package helps

import (
	"fmt"
)

const CustomError = "myImportantError"

func Ping() error{
	fmt.Println("Pong")
	return nil
}

After checking the linter, we should get an error that we can use a constant from helps package with name CustomError


I couldn't show it in tests because there is some problem with imports in testing. But the linter parses ALL imported packages of the file, not just standard ones

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages