Closed samherrmann closed 1 year ago
I don't think the package comment adds much value. Generated code is usually exempted from certain code quality checks. If the file written by moq is not being recognised as generated code, we should look to fix that instead.
I gave this a bit more thought and at the end I agree with you. If staticcheck
is the linting tool being used, then users can drop a staticcheck.conf file in the folder/package containing the mocks and tell it to ignore the package. Alternatively, if users really wanted the generated code to be checked by the linting tool, then for the package comment case users can drop a separate Go file in the folder that contains nothing but the package name and the comment. E.g.:
mocks/mocks.go (human created file):
// Package mocks is a generated Moq package.
package mocks
mocks/foo.go (Moq generated file):
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package mocks
// ...
Based on Go's code review comments guide, packages should have a comment [1]. This rule is also enforced by staticcheck [2], which is the default lint tool in the Go extension for VSCode. The -write-pkg-comment flag is particularly useful when combined with the -pkg flag where the defined package may only contain generated mock files. Additionally, the -write-pkg-comment flag also exists in mockgen [3].
References