Skip to content

fix: rule confusing-naming false positive on multiple blank identifiers#1536

Merged
chavacava merged 4 commits intomgechev:masterfrom
emmanuel-ferdman:master
Oct 6, 2025
Merged

fix: rule confusing-naming false positive on multiple blank identifiers#1536
chavacava merged 4 commits intomgechev:masterfrom
emmanuel-ferdman:master

Conversation

@emmanuel-ferdman
Copy link
Copy Markdown
Contributor

PR Summary

The confusing-naming rule was incorrectly reporting false positives when Go structs contained multiple blank identifier (_) fields, which are commonly used for padding and alignment. The rule's checkStructFields function was treating all field names equally, including blank identifiers, causing it to flag the second occurrence of _ as differing only by capitalization from the first. This fix adds a simple check to skip blank identifiers before performing the capitalization comparison, as blank identifiers are special in Go and explicitly allowed to appear multiple times in the same struct according to the language specification.

Example:

// test.go
package main

type siginfoChild struct {
    signo    int32
    errno    int32
    exitCode int32
    _        int32

    pid    int32
    uid    uint32
    status int32

    _ [25]uint32 // Pad to 128 bytes
}

Old output:

Field '_' differs only by capitalization to other field in the struct type siginfoChild

Fixes #1535.

emmanuel-ferdman and others added 4 commits October 5, 2025 16:40
…iers

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
…iers

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
@chavacava chavacava merged commit c930786 into mgechev:master Oct 6, 2025
10 checks passed
@chavacava
Copy link
Copy Markdown
Collaborator

Hi @emmanuel-ferdman, thanks for the PR.

@alexandear alexandear mentioned this pull request Nov 6, 2025
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

Successfully merging this pull request may close these issues.

False positive "differs only by captalization" on alignment fields in struct

2 participants