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

How are we supposed to ignore "chained" function calls using regex? #39

Open
macintacos opened this issue Jul 1, 2024 · 0 comments
Open

Comments

@macintacos
Copy link

Short summary

I would like to be able to use mnd for most things but skip it in situations like the following where "function chaining" is used to "compose" things:

huh.NewText().
	Title("Special Instructions").
	CharLimit(400). // <--- I think that this "magic number" is fine, given the context of how it's supposed to be used
	Value(&instructions),

Right now, it's not really clear how I should do this, given the available options.

Steps to reproduce the behavior

Follow the tutorial for the huh package and then run go-mnd on the code. You'll get an output like the following (I'm using golangci-lint to run this tool, if that matters):

cmd/test.go:60:12: Magic number: 4, in <argument> detected (mnd)
					Limit(4). // there’s a 4 topping limit!
					      ^
cmd/test.go:71:30: Magic number: 2, in <argument> detected (mnd)
						huh.NewOption("A lot", 2),
						                       ^
cmd/test.go:92:16: Magic number: 400, in <argument> detected (mnd)
					CharLimit(400).

The second one I can understand as "magic" numbers, but the first and third I think are "fine". I want to get this tool to ignore those, but it's not really clear without just adding Limit or whatever as a regex, which I think is probably not specific enough. I just want to make sure that huh's Limit and CharLimit are ignored, and if I use some other package with Limit those are still checked.

It seems like most of my confusion stems from the fact that it's not clear how I'm supposed to deal with "chained" functions like what are used in the huh library.

go-mnd version or commit ref

Whatever is current when running golangci-lint latest.

Go version (output of 'go version')

$ go version
go version go1.22.4 darwin/arm64

Operating system / Environment

macOS 14.5

Expected behavior

I expected to be able to pass '^huh\.' as an option for functions to ignore everything chained by huh.<whatever> methods.

Actual behavior

It doesn't work. It seems to only support ignoring a function call that initially starts with huh, but it doesn't continue checking chained methods. I would like a way to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant