codeclimate-duplication icon indicating copy to clipboard operation
codeclimate-duplication copied to clipboard

Import statements in golang should be ignored

Open ptxmac opened this issue 4 years ago • 1 comments

I often get warnings in my golang projects that my import blocks are duplicates and should be refactored. Unfortunately, that's not how golang works - everything a file references must be imported, there are no transitive imports.

A codeblock like:

package mypackage 

import (
   "fmt"
    "anotherpackage"
)

Will often occur in many files and the only way to get rid of duplication would be to put everything in one file which is a horrible way to improve maintainability

ptxmac avatar Jul 28 '21 09:07 ptxmac

Having the same issue, I noticed there is a piece of code that is supposed to do this but apparently it does not work as expected: https://github.com/codeclimate/codeclimate-duplication/blob/97be4bd0664fdc140d2c432a0aba5cd08801ce9f/lib/cc/engine/analyzers/go/main.rb#L17

I tried to come up with my own filter but with no success - is there a known workaround?

awiecek avatar Dec 06 '21 07:12 awiecek