Skip to content

Commit

Permalink
Fix minor linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisWiegman committed May 5, 2024
1 parent ae4742d commit 45764ec
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion internal/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)

// Add checks the hosts file that the provided hosts are assigned to the ip
// Add checks the hosts file that the provided hosts are assigned to the ip.
func Add(cmd *cobra.Command, args []string) error {
hosts, err := goodhosts.NewHosts(flags.Section)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)

// Check checks the hosts file that the provided hosts are assigned to the ip
// Check checks the hosts file that the provided hosts are assigned to the ip.
func Check(cmd *cobra.Command, args []string) error {
hosts, err := goodhosts.NewHosts(flags.Section)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package flags

import "github.com/spf13/cobra"

// AllLines Set to true to display comments when listing
// AllLines Set to true to display comments when listing.
var AllLines bool

// Comment Adds a comment to the entry for better identification later
// Comment Adds a comment to the entry for better identification later.
var Comment string

// Section Is a named section with which to edit hosts in.
Expand Down
2 changes: 1 addition & 1 deletion internal/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/spf13/cobra"
)

// List lists all the entries in the hosts file
// List lists all the entries in the hosts file.
func List(cmd *cobra.Command, args []string) error {
hosts, err := goodhosts.NewHosts(flags.Section)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/remove/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)

// Remove deletes a host/ip entry
// Remove deletes a host/ip entry.
func Remove(cmd *cobra.Command, args []string) error {
hosts, err := goodhosts.NewHosts(flags.Section)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/removesection/removesection.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)

// RemoveSection deletes a section from the hosts file
// RemoveSection deletes a section from the hosts file.
func RemoveSection(cmd *cobra.Command, args []string) error {
if flags.Section == "" {
return errors.New("you must provide the `--section` flag to use this command")
Expand Down
2 changes: 1 addition & 1 deletion pkg/goodhosts/goodhosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// NewHosts Return a new instance of “Hosts“.
func NewHosts(sectionName string) (Hosts, error) {
osHostsFilePath := ""
var osHostsFilePath string

if os.Getenv("HOSTS_PATH") == "" {
osHostsFilePath = os.ExpandEnv(filepath.FromSlash(hostsFilePath))
Expand Down
10 changes: 5 additions & 5 deletions pkg/goodhosts/hostsFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ func (h *Hosts) Flush() error {
}

if len(h.SectionLines) > 0 {
if len(h.Section) > 0 {
if h.Section != "" {
h.FileLines = append(h.FileLines, NewHostsLine(""), NewHostsLine(fmt.Sprintf("%s %s", sectionStart, h.Section)))
}

h.FileLines = append(h.FileLines, h.SectionLines...)

if len(h.Section) > 0 {
if h.Section != "" {
h.FileLines = append(h.FileLines, NewHostsLine(fmt.Sprintf("%s %s", sectionEnd, h.Section)), NewHostsLine(""))
}
}
Expand Down Expand Up @@ -145,7 +145,7 @@ func (h *Hosts) Has(ip, host string, forceFile bool) bool {
return pos != -1
}

// RemoveSection removes an entire section from the hostsfile
// RemoveSection removes an entire section from the hostsfile.
func (h *Hosts) RemoveSection() error {
if h.Section == "" {
return errors.New("no section provided")
Expand Down Expand Up @@ -191,7 +191,7 @@ func (h *Hosts) Remove(ip string, hosts ...string) error {
newLineRaw = fmt.Sprintf("%s %s", newLineRaw, host)
}

if len(line.Comment) > 0 {
if line.Comment != "" {
newLineRaw = fmt.Sprintf("%s #%s", newLineRaw, line.Comment)
}

Expand All @@ -212,7 +212,7 @@ func (h *Hosts) Remove(ip string, hosts ...string) error {
func (h *Hosts) getHostPosition(ip, host string, forceFile bool) int {
checkLines := h.FileLines

if len(h.Section) > 0 && !forceFile {
if h.Section != "" && !forceFile {
checkLines = h.SectionLines
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/goodhosts/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
)

// intemInSlice Returns true if the item string is in the provided slice or false
// intemInSlice Returns true if the item string is in the provided slice or false.
func itemInSlice(item string, list []string) bool {
for _, i := range list {
if i == item {
Expand All @@ -16,13 +16,13 @@ func itemInSlice(item string, list []string) bool {
return false
}

// buildRawLine builds a line for insertion into the hosts file
// buildRawLine builds a line for insertion into the hosts file.
func buildRawLine(ip, host, comment string) string {
output := ip

output = fmt.Sprintf("%s %s", output, host)

if len(comment) > 0 {
if comment != "" {
comment = "#" + comment
output = fmt.Sprintf("%s %s", output, comment)
}
Expand Down

0 comments on commit 45764ec

Please sign in to comment.