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

Cleanup: multiple unnecessarily exported methods #3262

Closed
imjasonh opened this issue Sep 19, 2020 · 8 comments · Fixed by #4296
Closed

Cleanup: multiple unnecessarily exported methods #3262

imjasonh opened this issue Sep 19, 2020 · 8 comments · Fixed by #4296
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.

Comments

@imjasonh
Copy link
Member

Repurposing a script used to find unused test builder methods from #3178 (comment) to try to find exported method names that aren't invoked from outside their package.

$ git grep -o "^func [A-Z][^(]*" pkg/ | grep -v "pkg/client" | grep -v " Test" | cut -d' '  -f 2 | sort | uniq | xargs -n 1 -I{} sh -c "git grep -c '\.{}(' > /dev/null || echo {}"
ApplyResourceSubstitution
ConvertErrorf
DagFromState
EmitErrorEvent
EmitEvent
EventForObjectWithCondition
EventForPipelineRun
EventForTaskRun
GetPVCSpec
GetPersistentVolumeClaim
HasDefaultConfigurationName
IsPodHitConfigError
MarkStatusFailure
MarkStatusRunning
MarkStatusSuccess
NeedsPVC
NewArtifactBucketFromConfig
NewFakeClient
NewPipelineRunTest
NewTektonCloudEventData
ResolvePipelineTaskResources
ShowRef
SubmoduleFetch
ValidateDeclaredWorkspaces
ValidateResults
WithDefaultConfigurationName

This greps for exported function names like Foo which aren't found in the codebase .Foo(, which would indicate that it's called by another package -- callers in the same package wouldn't need to reference the package name with a .

This also:

  • ignores funcs in pkg/client since those are generated
  • ignores funcs with Test in the name, since those are test methods called by go test

Spot-checking some of these:

  • SubmoduleFetch is exported in pkg/git/git.go and only ever called in that package. It could be unexported.
  • ValidateDeclaredWorkspaces, same story.
  • NeedsPVC is exported and only called in its corresponding test, it could be unexported.
  • DagFromState is defined in a _test.go file and only called from other tests, it could be unexported. (If it stays exported it should also be renamed to DAGFromState to adhere to Go style advice for initialisms

I have a strong suspicion we could rename all these methods to be unexported (e.g., ValidateResults becomes validateResults) and check that tests still pass and images still build.


Exported methods present a potential maintenance burden on Tekton contributors, since some external user might come to depend on the method, and could be broken if we change or remove the method.

Exported methods are effectively part of our Go library API, and while we don't have any support/deprecation policy around that, that wouldn't stop users from depending on it and being upset when we change it.

In general, methods should not be exported unless they need to be.

/kind cleanup

@imjasonh imjasonh added the good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. label Sep 19, 2020
@tekton-robot tekton-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Sep 19, 2020
@imjasonh imjasonh changed the title Cleanup: multiple unnecessarily unexported methods Cleanup: multiple unnecessarily exported methods Sep 19, 2020
@vigneshashokan
Copy link

@imjasonh If no one is working on this, I can take a stab at this issue.

@imjasonh
Copy link
Member Author

@imjasonh If no one is working on this, I can take a stab at this issue.

Great! It should be pretty straightforward, let me know if you have any questions or find any difficulties.

@vigneshashokan
Copy link

Hi @imjasonh, I created this PR #3327 for this issue. Let me know what you think.

@tekton-robot
Copy link
Collaborator

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale with a justification.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close with a justification.
If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.

/lifecycle stale

Send feedback to tektoncd/plumbing.

@tekton-robot tekton-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 1, 2021
@tekton-robot
Copy link
Collaborator

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten with a justification.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close with a justification.
If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.

/lifecycle rotten

Send feedback to tektoncd/plumbing.

@tekton-robot tekton-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jan 31, 2021
@chmouel
Copy link
Member

chmouel commented Feb 1, 2021

I think it still there :

% git grep -o "^func [A-Z][^(]*" pkg/ | grep -v "pkg/client" | grep -v " Test" | cut -d' '  -f 2 | sort | uniq | xargs -n 1 -I{} sh -c "git grep -c '\.{}(' > /dev/null || echo {}"
ApplyResourceSubstitution
ConvertErrorf
EmitErrorEvent
EmitEvent
EventForObjectWithCondition
EventForPipelineRun
EventForTaskRun
GetPersistentVolumeClaim
GetPVCSpec
GetRunName
HasDefaultConfigurationName
IsPodHitConfigError
MakeLabels
MarkStatusFailure
MarkStatusRunning
MarkStatusSuccess
NeedsPVC
NewArtifactBucketFromConfig
NewFakeClient
NewPipelineRunTest
NewTektonCloudEventData
ResolvePipelineTaskResources
ShowRef
SubmoduleFetch
ValidateDeclaredWorkspaces
ValidateGitSSHURLFormat
WithDefaultConfigurationName

the PR on #3327 is still open @vigneshashokan would you like to rebase it ?

/remove-lifecycle rotten

/assign @vigneshashokan

@tekton-robot tekton-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Feb 1, 2021
@vdemeester
Copy link
Member

/lifecycle frozen

@tekton-robot tekton-robot added the lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. label Feb 4, 2021
@abayer
Copy link
Contributor

abayer commented Oct 11, 2021

Fwiw, I'd change the git grep here to:

git grep -o "^func [A-Z][^(]*" pkg/ | grep -v "pkg/client" | grep -v " Test" | cut -d' '  -f 2 | sort | uniq | xargs -n 1 -I{} sh -c "git grep -c '\.{}\W' > /dev/null || echo {}"

i.e., change the last sh -c "git grep -c '\.{}(' ... to sh -c "git grep -c '\.{}\W' .... This is because pkg/pipelinemetrics/WithInformer and pkg/taskrunmetrics/WithInformer are used in their respective .../fake/fake.gos, but as function references, not function calls. Anyway, I've got a PR incoming. =)

abayer added a commit to abayer/tektoncd-pipeline that referenced this issue Oct 11, 2021
fixes tektoncd#3262

There are a few things left, either by design or uncertainty:
* `pkg/apis/pipeline/v1beta1/conversion_error.go`'s `ConvertErrorf` - I'm not entirely clear on whether this should be around or not. `CannotConvertError` is still used in tests in `pkg/apis/pipeline/v1alpha1`, and the whole thing is just messy enough that I'm not sure what to do.
* `pkg/apis/pipeline/v1beta1/version_validation.go`'s `ValidateEnabledAPIFields` - it's referenced in `docs/developers/README.md` and I can't tell if that's something that could be intended to eb used in something depending on Tekton, not just in Tekton itself.
* `pkg/pipelinerunmetrics/injection.go` and `pkg/taskrunmetrics/injection.go`'s `WithInformer` - these are both used as function references in their respective `.../fake/fake.go`s.

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
abayer added a commit to abayer/tektoncd-pipeline that referenced this issue Oct 11, 2021
fixes tektoncd#3262

There are a few things left, either by design or uncertainty:
* `pkg/apis/pipeline/v1beta1/conversion_error.go`'s `ConvertErrorf` - I'm not entirely clear on whether this should be around or not. `CannotConvertError` is still used in tests in `pkg/apis/pipeline/v1alpha1`, and the whole thing is just messy enough that I'm not sure what to do.
* `pkg/apis/pipeline/v1beta1/version_validation.go`'s `ValidateEnabledAPIFields` - it's referenced in `docs/developers/README.md` and I can't tell if that's something that could be intended to eb used in something depending on Tekton, not just in Tekton itself.
* `pkg/pipelinerunmetrics/injection.go` and `pkg/taskrunmetrics/injection.go`'s `WithInformer` - these are both used as function references in their respective `.../fake/fake.go`s.

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
tekton-robot pushed a commit that referenced this issue Oct 11, 2021
fixes #3262

There are a few things left, either by design or uncertainty:
* `pkg/apis/pipeline/v1beta1/conversion_error.go`'s `ConvertErrorf` - I'm not entirely clear on whether this should be around or not. `CannotConvertError` is still used in tests in `pkg/apis/pipeline/v1alpha1`, and the whole thing is just messy enough that I'm not sure what to do.
* `pkg/apis/pipeline/v1beta1/version_validation.go`'s `ValidateEnabledAPIFields` - it's referenced in `docs/developers/README.md` and I can't tell if that's something that could be intended to eb used in something depending on Tekton, not just in Tekton itself.
* `pkg/pipelinerunmetrics/injection.go` and `pkg/taskrunmetrics/injection.go`'s `WithInformer` - these are both used as function references in their respective `.../fake/fake.go`s.

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
chenbh pushed a commit to chenbh/pipeline that referenced this issue Oct 27, 2021
fixes tektoncd#3262

There are a few things left, either by design or uncertainty:
* `pkg/apis/pipeline/v1beta1/conversion_error.go`'s `ConvertErrorf` - I'm not entirely clear on whether this should be around or not. `CannotConvertError` is still used in tests in `pkg/apis/pipeline/v1alpha1`, and the whole thing is just messy enough that I'm not sure what to do.
* `pkg/apis/pipeline/v1beta1/version_validation.go`'s `ValidateEnabledAPIFields` - it's referenced in `docs/developers/README.md` and I can't tell if that's something that could be intended to eb used in something depending on Tekton, not just in Tekton itself.
* `pkg/pipelinerunmetrics/injection.go` and `pkg/taskrunmetrics/injection.go`'s `WithInformer` - these are both used as function references in their respective `.../fake/fake.go`s.

Signed-off-by: Andrew Bayer <andrew.bayer@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants