qbs icon indicating copy to clipboard operation
qbs copied to clipboard

Use google go linter

Open wwwdata opened this issue 10 years ago • 9 comments

I suggest that the source code get's linted with https://github.com/golang/lint

According to the linter, it is for example necessary to name all methods that contain the keyword id uppercase, for example getId must be getID and so on.

here is a complete list of those uppercase keywords: https://github.com/golang/lint/blob/master/lint.go#L656

wwwdata avatar Oct 24 '14 08:10 wwwdata

+1

sharpner avatar Oct 24 '14 08:10 sharpner

Thank you for the suggestion. But it breaks the API.

coocood avatar Oct 24 '14 08:10 coocood

Okay. But I have currently a problem using qbs for my models.

Currently the id fields of a struct must be "Id" when using qbs. Unfortunately the correct usage of "ID" results in "i_d".

Can you add an exceptional case for ID?

mantenie avatar Oct 24 '14 08:10 mantenie

It does not have break the api if both methods are possible.

sharpner avatar Oct 24 '14 08:10 sharpner

I think adding extra APIs or special case just for golint is not worth it. I don't feel like hacking for coding style. If I were to build a new package I may follow golint's suggestions.

coocood avatar Oct 24 '14 08:10 coocood

most packages provide an aliasing feature with go tags (sql:"last_name"), like sqlx, gorm etc.

this is not "hacking for coding style" its also to allow using existing database schemes etc. I know that qbs provides an optional function for rename magic, but this feature would be much cleaner.

Maybe this would be an acceptable option for you.

sharpner avatar Oct 24 '14 09:10 sharpner

I've written a small library to solve this problem. Maybe it is useful for some other users who wants to code without golint warnings. https://github.com/serenize/snaker

mantenie avatar Oct 24 '14 16:10 mantenie

Neat solution.

coocood avatar Oct 24 '14 16:10 coocood

Thx. You can use it like this:

qbs.ColumnNameToFieldName = snaker.SnakeToCamel
qbs.FieldNameToColumnName = snaker.CamelToSnake

mantenie avatar Oct 24 '14 16:10 mantenie