Skip to content

Commit

Permalink
scopelint: Fix improper range loop var reference
Browse files Browse the repository at this point in the history
Error from `scopelint` linter:

"Using a reference for the variable on range scope `img`"

Fix:

Use index from range loop to *reach into* the slice argument
to retrieve the address of those values instead of using the
range loop variable, which likely would have been a subtle
source of bugs later on.

refs #6, #11, #12
  • Loading branch information
atc0005 committed Apr 9, 2020
1 parent 823a70e commit 605953a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions messagecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,17 @@ func (mcs *MessageCardSection) AddFactFromKeyValue(key string, values ...string)
// AddImage adds an image to a MessageCard section. These images are used to
// provide a photo gallery inside a MessageCard section.
func (mcs *MessageCardSection) AddImage(sectionImage ...MessageCardSectionImage) error {
for _, img := range sectionImage {
if img.Image == "" {

for i := range sectionImage {
if sectionImage[i].Image == "" {
return fmt.Errorf("cannot add empty image URL")
}

if img.Title == "" {
if sectionImage[i].Title == "" {
return fmt.Errorf("cannot add empty image title")
}

mcs.Images = append(mcs.Images, &img) // nolint:scopelint
mcs.Images = append(mcs.Images, &sectionImage[i])
}

return nil
Expand Down

0 comments on commit 605953a

Please sign in to comment.