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

New Feature: support nolint range #2007

Closed
wants to merge 2 commits into from

Conversation

sanposhiho
Copy link
Member

@sanposhiho sanposhiho commented May 22, 2021

Hi team :D

Fixes #129

Support the new feature nolint range.
Now, we can ignore reports with nolint-begin and nolint-end

func Save() {
  //nolint-begin:lll
  very long line of code 
  another very long line of code
  one more 
  ...
  //nolint-end:lll
}

I've opened it early to hear any feedback on the syntax. I'll open it as a formal PR once I've written some tests and can get everyone to agree on the above syntax.

@ldez
Copy link
Member

ldez commented May 22, 2021

Hello,

I'm not sure about the syntax with a hyphen.

Maybe nolint:begin:lll or nolint:lll:begin.
But there is also interaction with the nolint syntax for multiple linter.

I'm also not sure that discuss that in a PR is a good idea.

🤔

@ldez ldez added blocked Need's direct action from maintainer enhancement New feature or improvement labels May 22, 2021
@sanposhiho sanposhiho force-pushed the feature/nolint-range branch from 2c1be42 to 0f8df04 Compare May 22, 2021 16:15
@sanposhiho
Copy link
Member Author

sanposhiho commented May 22, 2021

Hi

Maybe nolint:begin:lll or nolint:lll:begin.

Yes, I also considered the syntax you mentioned.
But, since not all users know the names of all linter in golangci-lint, I thought that the syntax nolint:begin: or nolint:begin(the case user want to ignore all linter's reports) might cause users to think that they are ignoring the linter named "begin". 🤔 💭

I'm also not sure that discuss that in a PR is a good idea.

Yeah, If there are some problems with this syntax or other ideas about it, discuss it in the issue 👍

@sanposhiho sanposhiho marked this pull request as ready for review June 9, 2021 09:51
@sanposhiho sanposhiho force-pushed the feature/nolint-range branch from b6ae874 to 86ad4d9 Compare June 9, 2021 09:58
@bombsimon
Copy link
Member

bombsimon commented Jun 9, 2021

Is this really needed, this can be solved with an anonymous block.

package main

import "fmt"

func main() {
	//nolint:forbidigo // Let's OK them here
	{
		fmt.Println("x")
		fmt.Println("x")
		fmt.Println("x")
	}

	// Not here.
	fmt.Println("x")
}
$ golangci-lint run --no-config --disable-all --enable forbidigo
main.go:14:2: use of `fmt.Println` forbidden by pattern `^fmt\.Print(|f|ln)$` (forbidigo)
        fmt.Println("x")
        ^

@sanposhiho sanposhiho force-pushed the feature/nolint-range branch from 86ad4d9 to 7bda5d6 Compare June 9, 2021 10:11
@ldez
Copy link
Member

ldez commented Jun 9, 2021

Sorry, I forget to answer.

My main concern with that related to #1658
I think this issue is more important than nolint range, and it can be difficult "to migrate" this nolint annotation in the future.

@sanposhiho
Copy link
Member Author

sanposhiho commented Jun 9, 2021

Is this really needed, this can be solved with an anonymous block.

As you know, {} means scope. So I think nolint with {} can only solve certain cases.
For example, If a user wants to nolint lines only 2-5 of example1, nolinting with {} is not possible as in example2.

example1:

func main() {
	var superLongName int  // lll reports "this is long line"
	var superLongName2 int // lll reports "this is long line"
	var superLongName3 int // lll reports "this is long line"
	var superLongName4 int // lll reports "this is long line"

	println(superLongName) // lll reports "this is long line"
	fmt.Println("Hello, playground")
}

example2:

func main() {
        //nolint: lll
	{
		var superLongName int
		var superLongName2 int
		var superLongName3 int
		var superLongName4 int
	}

	println(superLongName) // ERROR undefined: superLongName
	fmt.Println("Hello, playground")
}

As the other case, users can't do nolint across multiple functions or scope.

@sanposhiho
Copy link
Member Author

sanposhiho commented Jun 9, 2021

My main concern with that related to #1658
I think this issue is more important than nolint range, and it can be difficult "to migrate" this nolint annotation in the future.

Hmm, I didn't know about that issue, thanks.
Yeah, as you say, I think that issue has a higher priority than this nolint range feature.

I think there are several actions that can be taken here, and I'd like to hear your opinions..

@ldez
Copy link
Member

ldez commented Jun 9, 2021

My opinion:

@sanposhiho
Copy link
Member Author

I agree with you.
So, if no one else has some opinion, let's wait #1658 to be resolved

@ldez
Copy link
Member

ldez commented Aug 21, 2022

I will close the PR and keep issue #129 to track the topic.

@ldez ldez closed this Aug 21, 2022
@ldez ldez added declined and removed blocked Need's direct action from maintainer labels Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
declined enhancement New feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Idea: support "nolint ranges"
3 participants