英文:
How to force VSCode to ignore linting the next line of golang code?
问题
我喜欢我的代码看起来整洁。我尽量遵循建议等等。这有助于保持一切井然有序、符合规范和体面。
但有时候,你需要打败代码检查器,因为它可能有 bug,或者它不能理解你的意图。
在这种情况下,我有以下代码:
fmt.Println("Enter values between %00 and %0f.")
VSCode 抱怨说:
fmt.Println call has possible formatting directive %0f (printf)
它这样想是合理的,我非常感谢它警告我可能犯的错误……但在这个特定的情况下,我真的希望它按原样打印 %0f
。我真的非常清楚我在这里做什么。
通常情况下,我可能会这样做:
//lint:ignore printf No, really, this is what I want
fmt.Println("Enter values between %00 and %0f.")
但是 VSCode 仍然显示黄色波浪线,并完全忽略了 lint:ignore
指令。
我必须通过以下方式解决这个烦恼:
fmt.Printf("Enter values between %%00 and %%0f.\n")
但我更愿意使用原始语法,因为意图更清晰,并且这行代码与我在整个代码的这部分中编写的内容相匹配。
那么,我该如何坚决地告诉这个该死的程序停止放置错误的黄色波浪线,因为我真的知道我在做什么?这不仅令人分心,而且浪费我的时间,因为我一直在查看这个“linting error”,只是发现它并不是一个问题。
编辑
一些额外的信息可能会有用。
为了尽可能保持事情的简单,我使用了 "Go" 扩展,没有对它默认使用的代码检查器进行任何更改。
检查这些设置,看起来它正在使用 staticcheck
。而且,我在本地的 bin 文件夹中确实看到了它。
但是 staticcheck
不在乎。即使我在运行它时没有在上面加上 //lint:ignore
行,它也不会对我编写的 fmt.Println()
抱怨任何东西。
英文:
I like my code to look clean. I try to follow recommendations, etc. It helps keep everything tidy, conforming, and decent.
But sometimes, you need to defeat the linter because it has a bug, or it just doesn't understand what you intend.
In this case, I have the following code:
fmt.Println("Enter values between %00 and %0f.")
VSCode complains with:
fmt.Println call has possible formatting directive %0f (printf)
That's a reasonable thing for it to think, and I thank it very much for warning me of a possible mistake I might have made... but in this specific case, I really do want it to print %0f
as-is. I really, really know what I'm doing here.
Normally, I might do something like this:
//lint:ignore printf No, really, this is what I want
fmt.Println("Enter values between %00 and %0f.")
But VSCode still gives the yellow wavy line and completely ignores the lint:ignore directive.
I must work around this annoyance with:
fmt.Printf("Enter values between %%00 and %%0f.\n")
But I'd prefer to use the original syntax, as the intent is clearer, and the line matches what I've written everywhere else in this part of the overall code.
So, how do I put my foot down and freaking tell the cursed program to stop placing its errant yellow wavy line because, dammit, I really do know what the I'm doing? It is not only distracting, but it wastes my time as I keep looking over the 'linting error' only to see it's not an issue.
Edit
Some additional information might be useful.
In my desire to keep things as uncomplicated as reasonably possible, I use the 'Go' extension, with no changes to the linter it defaults to using.
Examining these settings, it looks like it's using staticcheck
. And, indeed, I see that in the local bin folder.
But staticcheck
doesn't care. It doesn't complain at all about the fmt.Println()
I wrote, even if I don't have a //lint:ignore
line above it, when I run it explicitly.
答案1
得分: 2
问题在于这个特定的检查是由go vet
而不是staticcheck
进行的,并且go vet
有意地没有忽略检查的机制。
英文:
The problem is that this specific check is made by go vet
, not staticcheck
, and go vet
intentionally does not have a mechanism to ignore checks.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论