Repository: mgechev/revive (go)

Issue:
var-naming rule to check that plural vars with ID are capitalised
**Is your feature request related to a problem? Please describe.**
the var-naming rule only checks that vars ending in ID are capitalised (e.g. userId => userID). I think it would be nice that it also check that vars ending in IDs are checked. (e.g. userIds => userIDs).

**Describe the solution you'd like**
Add a condition to the check that plurals vars such as userIDs are well capitalised.

Pull request description:
feat: capitalise var naming to IDs
`var-naming` does not check that ID is capitalised when it is plural such as IDs. For example if I have `uIds := []string{}` it will allow this var name where really it should return var `uIds should be uIDs`.

Closes #947

Patch:
diff --git a/lint/utils.go b/lint/utils.go
index 1efa41f..6ccfb0e 100644
--- a/lint/utils.go
+++ b/lint/utils.go
@@ -71,6 +71,10 @@ func Name(name string, allowlist, blocklist []string) (should string) {
 			if w == 0 && unicode.IsLower(runes[w]) {
 				u = strings.ToLower(u)
 			}
+			// Keep lowercase s for IDs
+			if u == "IDS" {
+				u = "IDs"
+			}
 			// All the common initialisms are ASCII,
 			// so we can replace the bytes exactly.
 			copy(runes[w:], []rune(u))
@@ -99,6 +103,7 @@ var commonInitialisms = map[string]bool{
 	"HTTP":  true,
 	"HTTPS": true,
 	"ID":    true,
+	"IDS":   true,
 	"IP":    true,
 	"JSON":  true,
 	"LHS":   true,


Test patch:
diff --git a/testdata/var-naming.go b/testdata/var-naming.go
index 2cf86f3..4a96dd8 100644
--- a/testdata/var-naming.go
+++ b/testdata/var-naming.go
@@ -2,6 +2,7 @@ package fixtures
 
 func foo() string {
 	customId := "result"
-	customVm := "result" // MATCH /var customVm should be customVM/
+	customVm := "result"  // MATCH /var customVm should be customVM/
+	customIds := "result" // MATCH /var customIds should be customIDs/
 	return customId
 }