Skip to content

Commit bc3f0f8

Browse files
committed
Initialize fieldNameSplit with the last word of credNameSplit so that it's clearer while reading the code, and prepend the rest of the words from credNameSplit, working backwards. More specifically, we also check if the second to the last word and the last word included are still lesser than the cutoff and use the second to the last word too, instead of just using the last word
1 parent aa7eb56 commit bc3f0f8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

cmd/contrib/main.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,24 +191,25 @@ func newPlugin() error {
191191

192192
// As a placeholder, assume the field name is the short version (max 7 chars) of the credential name, starting from the last word.
193193
//
194+
// When the last word of the credential name is greater than seven characters, the last word is used as the field name.
195+
//
194196
// For example:
195197
// "Personal Access Token" => "Token"
196198
// "Secret Key" => "Key"
197199
// "API Key" => "API Key"
198-
//
199-
// When the last word of the credential name is greater than seven characters, the last word is used as the field name
200-
var fieldNameSplit []string
200+
// "GitHub API Key" => "API Key"
201+
// "Credentials" => "Credentials"
201202
lengthCutoff := 7
202-
for i := range credNameSplit {
203-
word := credNameSplit[len(credNameSplit)-1-i]
203+
fieldNameSplit := []string{credNameSplit[len(credNameSplit)-1]}
204+
for i := range credNameSplit[:len(credNameSplit)-1] {
205+
// Skip credNameSplit's last word because it's already added to fieldNameSplit
204206
if i == 0 {
205-
fieldNameSplit = append([]string{word}, fieldNameSplit...)
206207
continue
207208
}
209+
word := credNameSplit[len(credNameSplit)-1-i]
208210
if len(strings.Join(append(fieldNameSplit, word), " ")) > lengthCutoff {
209211
break
210212
}
211-
212213
fieldNameSplit = append([]string{word}, fieldNameSplit...)
213214
}
214215
result.FieldName = strings.Join(fieldNameSplit, " ")

0 commit comments

Comments
 (0)