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

false positive(?): flags proto fields which are being written, not read #4

Closed
spencerschrock opened this issue Oct 24, 2023 · 2 comments

Comments

@spencerschrock
Copy link

I have some code here which sets fields in a proto.

	metadata := data.ShardMetadata{
		NumShard:  new(int32),
		ShardLoc:  new(string),
		CommitSha: new(string),
	}
	*metadata.NumShard = shardNum + 1
	*metadata.ShardLoc = bucket + "/" + data.GetBlobFilename("", t)
	*metadata.CommitSha = version.GetVersionInfo().GitCommit
	metadataJSON, err := protojson.Marshal(&metadata)

The linter flags this:

cron/internal/controller/main.go:159:3: avoid direct access to proto field metadata.NumShard, use metadata.GetNumShard() instead (protogetter)
        *metadata.NumShard = shardNum + 1

The provided fix (when I use the --fix flag) doesn't compile.

	*metadata.GetNumShard() = shardNum + 1
	*metadata.GetShardLoc() = bucket + "/" + data.GetBlobFilename("", t)
	*metadata.GetCommitSha() = version.GetVersionInfo().GitCommit
invalid operation: cannot indirect metadata.GetShardLoc() (value of type string)compiler (InvalidIndirection)

Should the linter be flagging non-get operations?

@ghostiam
Copy link
Owner

Thanks for the issue, yes, you are right, this is a false positive.
I'll fix it as soon as I can.

ghostiam added a commit that referenced this issue Oct 24, 2023
@ghostiam
Copy link
Owner

Fixed in version v0.2.4
Check, please.
Thanks for the issue!

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

2 participants