-
Notifications
You must be signed in to change notification settings - Fork 25
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
Ability to use dupl as a library #18
base: master
Are you sure you want to change the base?
Conversation
Hi, sorry for the delay.
I think that's a great idea and I'm open to make this module available as a library. I have a slight problem with the pull request: there's too many, too chaotic commits. (I understand there's a history behind the commit chain.) Would you be willing to collaborate with me on turning these commits into a reasonable commit chain? I've already merge one of your commits, the one fixing the unchecked error. I want dupl to stay compatible as much as possible. So far, this concerned only the CLI binary itself. If we're about to make some library packages part of the public interface (thus covered by the compatibility rules), I want to make a clear distinction between those: all private packages should go under As the first step, I'd like to define how exactly should the public API look like. I tried inferring the API from the client perspective from this code block, but I'm not sure that's all of it. Could you reply with your vision of how the public API should look like (something like a brief package API with types and function signatures)? The goal is to come up with a small public API I'd feel comfortable staying compatible with in the following years. Thank you! |
To elaborate further, this is the API implemented in your fork (if I understood correctly): package api
type Issue struct {
From, To clones.Clone
}
func Run(files []string, threshold int) ([]Issue, error)
package clones
type ByNameAndLine []Clone
type Clone struct {
Filename string
LineStart int
LineEnd int
Fragment []byte
}
func PrepareClonesInfo(fread ReadFile, dups [][]*syntax.Node) ([]Clone, error)
type ReadFile func(filename string) ([]byte, error) It's questionable why e.g. |
internal package sounds great :) I will find some time to work on the PR during the weekend. |
dacd1b4
to
991d1f5
Compare
…ibk\/dupl/github.com\/golangci\/dupl/g'; git grep -l github.com/mibk/dupl | xargs goimports -w
991d1f5
to
a7c1664
Compare
@mibk does it look acceptable? |
First let's discuss the package interface. Originally dupl was design to find clone groups, not necessarily pairs. Would that be a problem? I was thinking about names as well and this is I've come up with: package clone
type Pos struct {
Line int
Column int
}
type Clone struct {
Filename string
From, To Pos
}
type Group struct {
Clones []Clone
}
// SearchFiles searches files for clone groups.
func SearchFiles(files []string, threshold int) ([]Group, error) I named the package "clone" because "api" felt too vague. What do you think?
I'd prefare there be no unnecessary changes, e.g. s/mibk/golangci/ and back, but please, let's talk first and implement second so we're not wasting each other's time. Thank you! BTW I have also considered implementing dupl as Go Analyzer, which seems to be a more standard way of writing Go linters nowadays. |
I think that we can swap type Group struct {
Clones []Clone
} for type Group []Clone ( |
First of all, sorry for my late response.
That's true, but having the container gives us more power in the future should a new group field (in addition to Clones) be added.
One argument would be that the client can always obtain the fragment by reading the file at the specified position. I'm not entirely against keeping the Fragment field, though. |
@iwankgb Would it be possible to you to finish this work? |
@SVilgelm yes. |
thank you! |
For some historical reason golanci/golangci-lint uses for of mibk/dupl. I am in the process of moving
golangci-lint
away from forks towards upstream versions of all used linters. To achieve this we must be able to usedupl
as a library and this PR introduces such an ability.