nlreturn icon indicating copy to clipboard operation
nlreturn copied to clipboard

Fix C.GoBytes parsed as *ast.ReturnStmt

Open bombsimon opened this issue 5 years ago • 1 comments

C.GoBytes() is seen as an *ast.ReturnStmt so it must be excluded from the linter. When returned, two return statements will be seen so it will always report a false positive.

Closes #4


I added tests to prove this behaviour but sadly this adds a dependency to CGO. To be honest I don't think it's an issue since it's only tests - the linter will continue to work without CGO. Since this new dependency also compiles files to the cache (which is passed as pass.Fset, I had to add a check that we only lint .go files. I've seen this issue with other linters as well, not sure how else this could be solved to only process .go files in the passed package.

Let me know if you wan't me to drop the tests, that way we will not depend on CGO and we won't need the new check of file extension, however we cannot assert that the bug is fixed.

Lastly, I only compare towards the known function right now (_Cfunc_GoBytes) but it would be easy to add more special cases if needed. By looking at the AST, I saw no other obvious solution other than actually checking the specific *ast.Ident.

bombsimon avatar Oct 17 '20 15:10 bombsimon

It's not just C.GoBytes, I'm getting it for a bunch of other C functions (from a 3rd party library) as well.

corani avatar Aug 19 '21 05:08 corani