Giter VIP home page Giter VIP logo

goconst's Introduction

Well, hello there, fancy seeing you here!

I'm Jonathan, a self-taught, full-stack software engineer hailing from Perros-Guirec, France, currently living in Katowice, Poland.

I've created many successful products from scratch, every time leading from the front lines their development, laying out the foundations in frontend, backend and infrastructure - with a strong competitive drive to take the product further ahead.

I specialize in:

  • ♻️ Backend engineering & architecture
  • ⚡️ High availability & scalability
  • 🔧 Infrastructure as code

Rust Go TypeScript AWS GCP Nodejs React GraphQL

goconst's People

Contributors

dnephin avatar ericcornelissen avatar iwankgb avatar jdosborne1 avatar jgautheron avatar macabu avatar studyzy avatar tarasmadan avatar thetorpedodog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

goconst's Issues

Don't count backticks as string members

goconst -min-length 3  ./...
goconst -min-length 4  ./...

return both e.g.

pagehandler.go:807:7:2 other occurrence(s) of "`xt`" found in: pagehandler.go:594:18 pagehandler.go:946:14

and

goconst -min-length 5  ./..

doesn't find anything (which is what I expect).
Obviously the backticks in the first two calls are counted as string-members – which they are not.

This is because #2 only expects " as string delimiter but not backticks and apostrophe.

Add flag for non-zero exit code if any error occurred

I understand the design choice to NOT exit with a non-zero exit code for a tool like this. However, I would like to at least have the possibility of this tool exiting with a non-zero exit code if an error occurred. What are the possibilities of adding a boolean flag to have the program exit with a non-zero exit code if any error occurred?

EDIT: this is used e.g. in the prealloc static analysis tool through -set_exit_status

Support filtering number literals in bases other than decimals

The filtering logic for numbers uses strconv.Atoi to parse the value of numbers. This however assumes decimal and values in other bases like 0x0 are ignored even though they might be under the minimum threshold.

Replacing it by something like ParseInt(s, 0, 0) would handle parsing it in bases 2, 8, or 16 (determined by the prefix) as well as base 10.

work on more than strings

This would be useful in cockroachdb/cockroach if it could also detect duplicate integers. In particular, we want to use constants for time.Durations in our tests - it'd be nice if this tool provided that check.

`ignore-tests` option does not ignore test files

As stated in the README:

-ignore-tests exclude tests from the search (default: true)

However, when using this linter as part of golangci-lint, I am met with errors in *_test.go files that live adjacent to their companion *.go file in the directory.

I still notice this issue when adding the following to my .golangci.yml config:

linters-settings:
  goconst:
    ignore-tests: true

Multiple ignored strings

Would be nice if this linter supported multiple strings to ignore.

  goconst:
    # Exclude strings matching the given regular expressions.
    # Default: ""
    ignore-strings: 
      - 'foo.+'
      - 'baa.+'

Relates to #22

Combine matches

Using the latest release (see #7) the program prints out all matches like

config.go:240:37:4 other occurrence(s) of "logStack" found in: config.go:241:26 config.go:366:20 config.go:368:20 pagehandler.go:160:31
config.go:241:26:4 other occurrence(s) of "logStack" found in: config.go:240:37  config.go:366:20 config.go:368:20 pagehandler.go:160:31
config.go:366:20:4 other occurrence(s) of "logStack" found in: config.go:240:37 config.go:241:26 config.go:368:20 pagehandler.go:160:31
config.go:368:20:4 other occurrence(s) of "logStack" found in: config.go:240:37 config.go:241:26 config.go:366:20 pagehandler.go:160:31

I'd prefer it if all matches were printed in a single line. (I seem to remember that goconst did that in the previous release.)
Thank you!

More options for golangci-lint

Hello!

I can see that the linter has a rich set of flags:

  -ignore            exclude files matching the given regular expression
  -ignore-tests      exclude tests from the search (default: true)
  -min-occurrences   report from how many occurrences (default: 2)
  -min-length        only report strings with the minimum given length (default: 3)
  -match-constant    look for existing constants matching the values
  -numbers           search also for duplicated numbers

but only a couple of options are available here

goconst:
    min-len: 3
    min-occurrences: 3

It would be very useful for us to ignore some constants, or turn off this linter for tests without touching other linters

Could you help with that? Thanks

Constant is not finding

I have following file, but when I run goconst -min-occurrences 1 -output text . , it does not return anything. As you can see in the code "http://" string has two occurrence, my expectation is that goconst will show some error but it does not display anything. Am I doing right?

package main
import "strings"

var url string

func getUrl() {
	if strings.HasPrefix(url,"http://"){
		url = strings.TrimPrefix(url,"http://")
	} //esle do not control
	url = strings.TrimPrefix(string(url),"/")
}

the releases should have `v` prefix

Hi,
Could you please re-tag (at least latest) releases by adding v prefix to each release?
Seems go get does not recognize the tags without v as versions.

golangci-lint uses github.com/jgautheron/goconst v0.0.0-20201117150253-ccae5bf973f3 in go.mod file, and I tried to update it to use the latest version and expected to see github.com/jgautheron/goconst v1.4.0, but no changes.
Then I found this issue: golang/go#30146
Seems the v is a convention

Keep getting slammed with 'multiple occurrences' warning

Sorry, I made an SO post on the issue here, before I found this git:
https://stackoverflow.com/questions/46389607/go-linter-on-atom

I'm using Atom, I keep getting a long list of warnings like so, but what's the reasoning for it?
"3 other occurrence(s) of "GET" found in: routes_pages.go:384:8 routes_pages.go:443:7 routes_pages.go:536:7 (goconst)", appears for each case of GET, POST, PUT, etc. basically a huge list of warnings.

My routes:

a.Router.HandleFunc("/login", a.PageLogin)
a.Router.HandleFunc("/register", a.PageRegister)
a.Router.HandleFunc("/event/add", a.PageEventCreate)

My typical route funcs:

func (a *App) PageEventCreate(w http.ResponseWriter, r *http.Request) {

    switch r.Method {
        case "GET":
            // Serve the resource.
        case "POST":
            // Create a new record.
        case "PUT":
            // Update an existing record.
        case "DELETE":
            // Remove the record.
        default:
            // Give an error message.
    }

}



func (a *App) PageLogin(res http.ResponseWriter, req *http.Request) {
        switch r.Method {
            case "GET":
                // Serve the resource.
            case "POST":
                // Create a new record.
            case "PUT":
                // Update an existing record.
            case "DELETE":
                // Remove the record.
            default:
                // Give an error message.
        }

}

Support `-min-length` flag

I feel like it would be useful to only report constants longer than some minimum length. For example, I don't really care if the constant "a" is repeated, but I do care if the constant "Some Long Text" is repeated, as it becomes more prone to error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.