Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ignore like gocyclo #18

Closed
wy98926 opened this issue Dec 28, 2022 · 10 comments
Closed

Add support for ignore like gocyclo #18

wy98926 opened this issue Dec 28, 2022 · 10 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@wy98926
Copy link

wy98926 commented Dec 28, 2022

Shall we add support for the ignore in both command flag and code directive?

Example: gocyclo

We expect to do as the following:

  • Command flag

     $ gocognit
     Usage:
     		gocognit [flags] <Go file or directory> ...
     Flags:
     		-ignore REGEX

    Examples

     $ gocognit "_test|vendor/|code_gen|" .
  • Ignoring specific functions

     //gocognit:ignore
     func f1() {
     	// ...
     }
     	
     //gocognit:ignore
     var f2 = func() {
     	// ...
     }
@uudashr
Copy link
Owner

uudashr commented Jan 5, 2023

You are using gocognit command line?
Can you explain why you want to ignore?

@krasi-georgiev
Copy link

for example the main function is something that can contain a lot of logic that can't be broken down and it is ok to have more complexity

for example having run groups is something that usually results in larger main files

@uudashr
Copy link
Owner

uudashr commented Jun 5, 2023

Understand, we can add this feature of course.

Btw , I want to understand your needs.
gocognit can be used directly using the command line interface or we can use the API as well.
For example, if we prefer to use linter runners such as golangci-lint, then we can use ignore feature provided by golangci-lint.

For your case, are you using gocognit CLI?

@krasi-georgiev
Copy link

I am using golangci-lint

@uudashr
Copy link
Owner

uudashr commented Jun 5, 2023

I use it as well, such a great project.
AFAIK "golangci-lint" already have "ignore" feature, do you think we still need "ignore" for "gocognit"?

@uudashr
Copy link
Owner

uudashr commented Jun 5, 2023

Would love to have @wy98926 in the discussion (since the original request is from @wy98926 )

@ainar-g
Copy link

ainar-g commented Jul 7, 2023

I am not OP, but to add to the discussion, I'm using gocognit CLI, and I have generated code (protobuf) I'd like to ignore. Either adding --ignore, like gocyclo, or just ignoring all generated files by default would do.

@uudashr uudashr added the help wanted Extra attention is needed label Jul 26, 2023
@Nr18
Copy link

Nr18 commented Aug 29, 2023

Just ran into this issue as well, I use the cli tool as followed:

gocognit -over 3 -avg .

I also use gocyclo in the following matter:

gocyclo -over 3 -avg -ignore "_test" .

Would be great to have the same option as gocyclo to exclude test files. Typically you want to keep your methods in your application code small and simple. (Hence using this complexity tool to test this)

But unit tests are way more verbose and can have multiple assertions. Resulting in a higher cognitive complexity score.

Not sure if my use case is the same as @wy98926, but at first glance it does look like it. It was that this issue already existed otherwise I would have opened it myself.

@uudashr uudashr self-assigned this Sep 6, 2023
@uudashr
Copy link
Owner

uudashr commented Sep 6, 2023

Implemented in #27
The gocognit:ignore directive extracted to #29

@uudashr uudashr closed this as completed Sep 6, 2023
@Nr18
Copy link

Nr18 commented Sep 6, 2023

Thanks @uudashr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants