Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anujc25 committed Feb 4, 2025
1 parent b6d6e7a commit 9ac514f
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ issues:
- staticcheck
text: "SA1019:"

# Ignore the copyright header checks in following files
- path: component/tabwriter/internal/tabwriter.go
linters:
- goheader

include:
- EXC0011 # disable excluding of issues about missing package comments from stylecheck

Expand Down
12 changes: 0 additions & 12 deletions component/characters/spaces.go

This file was deleted.

4 changes: 2 additions & 2 deletions component/colorable-tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func IsTTYEnabled() bool {
}

// Rpad adds padding to the right of a string.
// from https://github.com/spf13/cobra/blob/993cc5372a05240dfd59e3ba952748b36b2cd117/cobra.go#L29
// from https://github.com/spf13/cobra/blob/4ba5566f5704a9c0d205e1ef3efc4896156d33fa/cobra.go#L173-L177
//
// Deprecated: Rpad is being moved under `github.com/vmware-tanzu/tanzu-plugin-runtime/component/stringutils` package
func Rpad(s string, padding int) string {
Expand All @@ -59,7 +59,7 @@ func TrimRightSpace(s string) string {
return strings.TrimRightFunc(s, unicode.IsSpace)
}

// Deprecated: BeginsWith is being moved under `github.com/vmware-tanzu/tanzu-plugin-runtime/component/stringutils` package
// Deprecated: BeginsWith is being deprecated. Use strings.HasPrefix instead
func BeginsWith(s, prefix string) bool {
return strings.HasPrefix(s, prefix)
}
Expand Down
4 changes: 2 additions & 2 deletions component/characters/icon.go → component/icons/icon.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2025 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package characters
// Package icon is predefined set of icons that can be used for consistency

Check failure on line 4 in component/icons/icon.go

View workflow job for this annotation

GitHub Actions / Lint

ST1000: package comment should be of the form "Package icons..." (stylecheck)
package icons

type Icon rune

Expand All @@ -15,7 +16,6 @@ const (
Check Icon = '✓'
Exclamation Icon = '❗'
Factory Icon = '🏭'
HammerWrench Icon = '🛠'
Magnifying Icon = '🔎'
Package Icon = '📦'
Question Icon = '❓'
Expand Down
7 changes: 2 additions & 5 deletions component/stringutils/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import (
"unicode"
)

// TrimRightSpace removes space (including all unicode space character) from right
func TrimRightSpace(s string) string {
return strings.TrimRightFunc(s, unicode.IsSpace)
}

func BeginsWith(s, prefix string) bool {
return strings.HasPrefix(s, prefix)
}

// Rpad adds padding to the right of a string.
// from https://github.com/spf13/cobra/blob/993cc5372a05240dfd59e3ba952748b36b2cd117/cobra.go#L29
// from https://github.com/spf13/cobra/blob/4ba5566f5704a9c0d205e1ef3efc4896156d33fa/cobra.go#L173-L177
func Rpad(s string, padding int) string {
tmpl := fmt.Sprintf("%%-%ds", padding)
return fmt.Sprintf(tmpl, s)
Expand Down
21 changes: 0 additions & 21 deletions component/stringutils/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,6 @@ func TestTrimRightSpace(t *testing.T) {
}
}

func TestBeginsWith(t *testing.T) {
tests := []struct {
s string
prefix string
expected bool
}{
{"hello world", "hello", true},
{"hello world", "world", false},
{"", "", true},
{"", "nonempty", false},
{"prefix test", "prefix", true},
}

for _, tt := range tests {
result := BeginsWith(tt.s, tt.prefix)
if result != tt.expected {
t.Errorf("BeginsWith(%q, %q) = %v; want %v", tt.s, tt.prefix, result, tt.expected)
}
}
}

func TestRpad(t *testing.T) {
tests := []struct {
s string
Expand Down
36 changes: 27 additions & 9 deletions component/tabwriter/internal/tabwriter.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
// Copyright 2025 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Copyright 2009 The Go Authors.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google LLC nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Package implements a write filter (tabwriter.Writer) that
// translates tabbed columns in input into properly aligned text.
Expand All @@ -15,9 +36,6 @@
// The package is using the Elastic Tabstops algorithm described at
// http://nickgravgaard.com/elastictabstops/index.html.

// repackaged from https://github.com/liggitt/tabwriter/tree/6880f16551ff10c60d3989df2bbd68a55bb3517f
// adds IgnoreAnsiCodes

// Package internal is repackaged from https://github.com/liggitt/tabwriter/tree/6880f16551ff10c60d3989df2bbd68a55bb3517f and adds IgnoreAnsiCodes
//
//nolint:gocyclo,gocritic,unused,nakedret,stylecheck,whitespace
Expand Down
1 change: 1 addition & 0 deletions component/tabwriter/tabwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

// Package tabwriter exposes an tabwriter functionality
// from https://github.com/kubernetes/cli-runtime/blob/v0.28.1/pkg/printers/tabwriter.go
package tabwriter

import (
Expand Down
8 changes: 5 additions & 3 deletions component/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"strings"
)

// From https://github.com/kubernetes/cli-runtime/blob/v0.28.1/pkg/printers/terminal.go"

// terminalEscaper replaces ANSI escape sequences and other terminal special
// characters to avoid terminal escape character attacks (issue #101695).
// Add "\x1b", "^[" to the `NewReplacer` params to scape color
var terminalEscaper = strings.NewReplacer("\r", "\\r")
// characters to avoid terminal escape character attacks (https://github.com/kubernetes/kubernetes/issues/101695).
// Add "\x1b", "^[" to the `NewReplacer` params to escape color
var terminalEscaper = strings.NewReplacer("\x1b", "^[", "\r", "\\r")

// WriteEscaped replaces unsafe terminal characters with replacement strings
// and writes them to the given writer.
Expand Down
2 changes: 1 addition & 1 deletion plugin/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ var TemplateFuncs = template.FuncMap{
"bold": stringutils.Sboldf,
"underline": stringutils.Sunderlinef,
"trimTrailingWhitespaces": stringutils.TrimRightSpace,
"beginsWith": stringutils.BeginsWith,
"beginsWith": strings.HasPrefix,
}

func shouldPrintInvocationWithoutTarget(target types.Target, ic *InvocationContext) bool {
Expand Down

0 comments on commit 9ac514f

Please sign in to comment.