go-tools icon indicating copy to clipboard operation
go-tools copied to clipboard

stylecheck: flag capitalized local variable names

Open cespare opened this issue 5 years ago • 5 comments

I see this style mistake from time to time.

cespare avatar Aug 19 '19 21:08 cespare

I think that this is closer to a stylecheck check than it is to a staticcheck one.

ainar-g avatar Aug 19 '19 21:08 ainar-g

I don't know about/use "stylecheck". I'm referring to ST???? checks in staticcheck.

cespare avatar Aug 19 '19 21:08 cespare

The checks in staticcheck are grouped into categories (and the implementation into packages): simple, staticcheck, stylecheck and unused (S, SA, ST and U). But you don't have to worry about that distinction, I'll happily edit issue titles to match my organizational scheme.

As for actually adding the check: I'll have to play around with it. There are certainly valid capitalized local variable names. For example, T is a common occurrence in this very code base, referring to an object's type. Unfortunately that includes variations of the name with random suffixes.

I'll have to sample a large code base and see how many noisy positives there are, and whether the check can be useful, at least as a disabled-by-default one.

dominikh avatar Aug 20 '19 00:08 dominikh

As for actually adding the check: I'll have to play around with it. There are certainly valid capitalized local variable names. For example, T is a common occurrence in this very code base, referring to an object's type. Unfortunately that includes variations of the name with random suffixes.

Interesting. I disagree with this -- I wouldn't use T for these cases. (I often use typ.)

But I'm happy with a disabled-by-default check, if you're willing to add it.

cespare avatar Aug 20 '19 00:08 cespare

In 2023 I think this check ought to enforce that function parameters and local vars use lowercase names and type parameters start with uppercase.

cespare avatar Oct 12 '23 08:10 cespare