GithubHelp home page GithubHelp logo

funlen's People

Contributors

jirfag avatar martialblog avatar nisevoid avatar pranavgaikwad avatar robinknaapen 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

funlen's Issues

funlen fails on variadic args

I have a New() method which instantiates a Logger (based on the ubser zap logger.).

The following fails on funlen...

 func New(level string, opts ...interface{}) Logger {
         r := &Resource{}

         var zopts []zap.Option
         for _, iopt := range opts {
                 if opt, ok := iopt.(zap.Option); ok {
                         zopts = append(zopts, opt)
                 }
        }
       ...

which seems harsh as I have no control over the number of options in the zap logger. Also the args list to this method is simple and does not break the rule of being difficult to read.

This seems to be a bug in the funlen linter.

any thoughts?

Revise funlen default behavior/configurations

Issue Requirements

Thank you for creating the issue!

Please include the following information:

  1. Version of golangci-lint: golangci-lint --version (or git commit if you don't use binary distribution)
    golangci-lint has version v1.19.1

  2. Config file: cat .golangci.yml
    Not applicable

  3. Go environment: go version && go env

GO111MODULE=""
GOARCH="amd64"
GOBIN="/home/u0/bin"
GOCACHE="/home/u0/.cache/go-build"
GOENV="/home/u0/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/u0"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/u0/Documents/gosandbox/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build509950643=/tmp/go-build -gno-record-gcc-switches"
  1. Verbose output of running: golangci-lint run -v
    Not applicable

Problem

I getting a lot of funlen false positive and this linter's configurations make no sense. The command I use on daily basis is:

$ golangci-lint run --color never --enable-all "$dirpath"

Now I have to alter it to either:

$ golangci-lint run --color never --enable-all --disable=funlen "$dirpath"
OR
create a configuration file that set `funlen` instead of
using golang-lint off the shelves.
OR
commit new codes all over the places with //nolint:funlen

Reason for Changes

package float

//nolint:funlen
func testENDECScenarios() []testENDECScenario {
	return []testENDECScenario{
		{
			UID:      1,
			TestType: testToString,
			Description: `
Float.ToString is able to convert:
1. positive float32
2. positive accuracy
3. to Normal format
`,
			Switches: map[string]bool{
				useNormalFormat:     true,
				usePositiveFloat32:  true,
				usePositiveAccuracy: true,
			},
		}, {
			UID:      2,
			TestType: testToString,
			Description: `
Float.ToString is able to convert:
1. zero float32
2. positive accuracy
3. to Normal format
`,
			Switches: map[string]bool{
				useNormalFormat:     true,
				useZeroFloat32:      true,
				usePositiveAccuracy: true,
			},
		}, {
			UID:      3,
			TestType: testToString,
			Description: `
Float.ToString is able to convert:
1. negative good float32
2. positive accuracy
3. to Normal format
`,
			Switches: map[string]bool{
				useNormalFormat:     true,
				useNegativeFloat32:  true,
				usePositiveAccuracy: true,
			},
		}, {
			UID:      4,
			TestType: testToString,
			Description: `
Float.ToString is able to convert:
1. none
2. positive accuracy
3. to Normal format
`,
			Switches: map[string]bool{
				useNormalFormat:     true,
				usePositiveAccuracy: true,
			},
		}, {
			UID:      5,
			TestType: testToString,
			Description: `
Float.ToString is able to convert:
1. positive float32
2. zero accuracy
3. to Normal format
`,
			Switches: map[string]bool{
				useNormalFormat:    true,
				usePositiveFloat32: true,
				useZeroAccuracy:    true,
			},
		}, {
			UID:      6,
			TestType: testToString,
			Description: `
Float.ToString is able to convert:
1. positive float32
2. negative accuracy
3. to Normal format
`,
			Switches: map[string]bool{
				useNormalFormat:     true,
				usePositiveFloat32:  true,
				useNegativeAccuracy: true,
			},
		}, {
			UID:      7,
			TestType: testToString,
			Description: `
Float.ToString is able to convert:
1. positive float32
2. positive accuracy
3. to Scientific format
`,
			Switches: map[string]bool{
				useScientificFormat: true,
				usePositiveFloat32:  true,
				usePositiveAccuracy: true,
			},
		}, {
			UID:      8,
			TestType: testToString,
			Description: `
Float.ToString is able to convert:
1. zero float32
2. positive accuracy
3. to Scientific format
`,
			Switches: map[string]bool{
				useScientificFormat: true,
				useZeroFloat32:      true,
				usePositiveAccuracy: true,
			},
		}, {
			UID:      9,
			TestType: testToString,
			Description: `
Float.ToString is able to convert:
1. negative good float32
2. positive accuracy
3. to Scientific format
`,
			Switches: map[string]bool{
				useScientificFormat: true,
				useNegativeFloat32:  true,
				usePositiveAccuracy: true,
			},
...
}

This is a generator function that generates configurations data structure slices. It is obviously went over the limit of 60. Keeping it outside the function means the encouragement of using global variable, which is a bigger concern that keeping a function to a fix 60 length, 40 statements rule.

Some logical functions can easily go beyond 60 like https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/garbagecollector/garbagecollector.go#L164.
By setting 60:40, the tool encourages programmers to spin multiple unnecessary small functions consisting of multiple functions OR forcing them not to tidy up their codes (E.g. braces management).

It takes a passionate Go programmer to the extend of altering the configurations so it will generate a lot of unnecessary noises between the new comers and seasoned developers.


Suggestion

  1. Do add heuristic analysis against the function natively OR
  2. Do not fix some brules to 60 lines, 40 statements without thorough research about practical meta-programming and take some actions like:
    2.1. Study and revise the brules with thorough discussions and data-driven.
    2.2. Setting the linter to only provide information, not warning / action-required.

Ignore function lines lint

Sometimes we need to init a huge structure which must consume more than 60 lines. It can't be split to multiple function.

Ignore empty lines

funlen counts lines, but if you 2 functions with the same effective lines of code, one can produce a report and the other not, only because there are empty lines.

By following this rule, you promote the fact to remove the empty lines, I'm not sure this is expected.

I will great if you can, at least, add an option to ignore empty line from the count or just don't add the empty lines to the counters.

Why lint on func length?

In the face of some resistance to this linter being applied (and engineers just doing nolint:funlen whenever they want, I wonder if it might be a good idea to add a "Why?" kind of section to the readme.md . Do you have any sources to encourage folks to use funlen? Would you be open to such a PR if I were to write it?

Disable funlen for *_test.go files

Is there any option to disable this linter for all test files?
Often table tests have input tables very long and it is not a problem for reading test function.

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.