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

Linter Error with Generic Type T When check-type-param is Enabled #34

Open
githoober opened this issue Dec 2, 2024 · 0 comments
Open

Comments

@githoober
Copy link

I encountered an issue when using a generic type T in combination with the linter setting check-type-param: true. The following code results in a linting error:

func NewStorageValueUnexpectedError[T int | string](key string, value T, cause error) *UnexpectedStorageValueError[T] {
	var ger *GenInfraError

	if cause != nil {
		ger = NewGenInfraErrorWithCause(fmt.Sprintf("Unexpected value '%v' of '%s'", value, key), cause)
	} else {
		ger = NewGenInfraError(fmt.Sprintf("Unexpected value '%v' of '%s'", value, key))
	}

	return &UnexpectedStorageValueError[T]{
		value:         value,
		key:           key,
		GenInfraError: ger,
	}
}

I am getting the following error

internal/infrastructure/infraerr/err__unexpected.go:15:37: type parameter name 'T' is too short for the scope of its usage (varnamelen)
func NewStorageValueUnexpectedError[T int | string](key string, value T, cause error) *UnexpectedStorageValueError[T] {
                                    ^
make: *** [Makefile:40: lint-go] Error 1

Question:
When check-type-param is enabled, should commonly used single-character generic types like T be renamed to something more descriptive? Or is there a recommended way to handle such cases without violating the rule?

Any guidance or clarification on the expected behavior would be appreciated.

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

1 participant