mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Merge pull request #1811 from monopole/activateLintUnused
Activate lint for unused code.
This commit is contained in:
@@ -23,10 +23,12 @@ linters:
|
|||||||
- nakedret
|
- nakedret
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- structcheck
|
- structcheck
|
||||||
# - stylecheck (panics)
|
# stylecheck demands that acronyms not be treated as words
|
||||||
|
# in camelCase, so JsonOp become JSONOp, etc. Yuck.
|
||||||
|
# - stylecheck
|
||||||
# - typecheck (fails in lots of places)
|
# - typecheck (fails in lots of places)
|
||||||
- unconvert
|
- unconvert
|
||||||
# - unused (panics)
|
- unused
|
||||||
- unparam
|
- unparam
|
||||||
- varcheck
|
- varcheck
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func (p *HashTransformerPlugin) Config(
|
|||||||
// Transform appends hash to generated resources.
|
// Transform appends hash to generated resources.
|
||||||
func (p *HashTransformerPlugin) Transform(m resmap.ResMap) error {
|
func (p *HashTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||||
for _, res := range m.Resources() {
|
for _, res := range m.Resources() {
|
||||||
if res.NeedHashSuffix() {
|
if res.ShouldAddHashSuffixToName() {
|
||||||
h, err := p.hasher.Hash(res)
|
h, err := p.hasher.Hash(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -389,6 +389,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b h1:XfVGCX+0T4WOStkaOsJRllbsiImhB2jgVBGc9L0lPGc=
|
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b h1:XfVGCX+0T4WOStkaOsJRllbsiImhB2jgVBGc9L0lPGc=
|
||||||
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
|
||||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
|||||||
@@ -70,7 +70,9 @@ func (rv *refVarTransformer) replaceVars(in interface{}) (interface{}, error) {
|
|||||||
// This field can potentially contain a $(VAR) since it is
|
// This field can potentially contain a $(VAR) since it is
|
||||||
// of string type.
|
// of string type.
|
||||||
return expansion2.Expand(s, rv.mappingFunc), nil
|
return expansion2.Expand(s, rv.mappingFunc), nil
|
||||||
//nolint:staticcheck (erroneously claims that `case nil` is unreachable)
|
// staticcheck erroneously claims that `case nil`
|
||||||
|
// is unreachable here, so suppressing it.
|
||||||
|
//nolint:staticcheck
|
||||||
case nil:
|
case nil:
|
||||||
return nil, nil
|
return nil, nil
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ func TestUpdateResourceOptions(t *testing.T) {
|
|||||||
if !a.Equals(b) {
|
if !a.Equals(b) {
|
||||||
t.Errorf("expected %v got %v", a, b)
|
t.Errorf("expected %v got %v", a, b)
|
||||||
}
|
}
|
||||||
if a.NeedHashSuffix() != b.NeedHashSuffix() {
|
if a.ShouldAddHashSuffixToName() != b.ShouldAddHashSuffixToName() {
|
||||||
t.Errorf("")
|
t.Errorf("")
|
||||||
}
|
}
|
||||||
if a.Behavior() != b.Behavior() {
|
if a.Behavior() != b.Behavior() {
|
||||||
|
|||||||
@@ -222,11 +222,6 @@ func (kt *KustTarget) computeInventory(
|
|||||||
return ra.Transform(p)
|
return ra.Transform(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kt *KustTarget) shouldAddHashSuffixesToGeneratedResources() bool {
|
|
||||||
return kt.kustomization.GeneratorOptions == nil ||
|
|
||||||
!kt.kustomization.GeneratorOptions.DisableNameSuffixHash
|
|
||||||
}
|
|
||||||
|
|
||||||
// AccumulateTarget returns a new ResAccumulator,
|
// AccumulateTarget returns a new ResAccumulator,
|
||||||
// holding customized resources and the data/rules used
|
// holding customized resources and the data/rules used
|
||||||
// to do so. The name back references and vars are
|
// to do so. The name back references and vars are
|
||||||
|
|||||||
@@ -252,9 +252,10 @@ func (r *Resource) Behavior() types.GenerationBehavior {
|
|||||||
return r.options.Behavior()
|
return r.options.Behavior()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeedHashSuffix checks if the resource need a hash suffix
|
// ShouldAddHashSuffixToName returns true if a resource
|
||||||
func (r *Resource) NeedHashSuffix() bool {
|
// content hash should be appended to the name of the resource.
|
||||||
return r.options != nil && r.options.NeedsHashSuffix()
|
func (r *Resource) ShouldAddHashSuffixToName() bool {
|
||||||
|
return r.options != nil && r.options.ShouldAddHashSuffixToName()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNamespace returns the namespace the resource thinks it's in.
|
// GetNamespace returns the namespace the resource thinks it's in.
|
||||||
|
|||||||
@@ -28,18 +28,17 @@ func (g *GenArgs) String() string {
|
|||||||
}
|
}
|
||||||
return "{" +
|
return "{" +
|
||||||
strings.Join([]string{
|
strings.Join([]string{
|
||||||
"nsfx:" + strconv.FormatBool(g.NeedsHashSuffix()),
|
"nsfx:" + strconv.FormatBool(g.ShouldAddHashSuffixToName()),
|
||||||
"beh:" + g.Behavior().String()},
|
"beh:" + g.Behavior().String()},
|
||||||
",") +
|
",") +
|
||||||
"}"
|
"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
// NeedsHashSuffix returns true if the hash suffix is needed.
|
// ShouldAddHashSuffixToName returns true if a resource
|
||||||
// It is needed when the two conditions are both met
|
// content hash should be appended to the name of the resource.
|
||||||
// 1) GenArgs is not nil
|
func (g *GenArgs) ShouldAddHashSuffixToName() bool {
|
||||||
// 2) DisableNameSuffixHash in GeneratorOptions is not set to true
|
return g.args != nil &&
|
||||||
func (g *GenArgs) NeedsHashSuffix() bool {
|
(g.opts == nil || !g.opts.DisableNameSuffixHash)
|
||||||
return g.args != nil && (g.opts == nil || !g.opts.DisableNameSuffixHash)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Behavior returns Behavior field of GeneratorArgs
|
// Behavior returns Behavior field of GeneratorArgs
|
||||||
|
|||||||
Reference in New Issue
Block a user