Skip to content

Commit 8726b3a

Browse files
committed
Change how we deal with singular/plural
1 parent 6eda207 commit 8726b3a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

go/extractor/diagnostics/diagnostics.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,19 @@ func EmitPackageDifferentOSArchitecture(pkgPath string) {
129129
)
130130
}
131131

132+
func plural(n int, singular, plural string) string {
133+
if n == 1 {
134+
return singular
135+
} else {
136+
return plural
137+
}
138+
}
139+
132140
const maxNumPkgPaths = 5
133141

134142
func EmitCannotFindPackages(pkgPaths []string) {
135143
numPkgPaths := len(pkgPaths)
136144

137-
ending := "s"
138-
if numPkgPaths == 1 {
139-
ending = ""
140-
}
141-
142145
numPrinted := numPkgPaths
143146
truncated := false
144147
if numPrinted > maxNumPkgPaths {
@@ -154,7 +157,11 @@ func EmitCannotFindPackages(pkgPaths []string) {
154157
emitDiagnostic(
155158
"go/autobuilder/package-not-found",
156159
"Some packages could not be found",
157-
fmt.Sprintf("%d package%s could not be found:\n\n%s.\n\nDefinitions in those packages may not be recognized by CodeQL, and files that use them may only be partially analyzed.\n\nCheck that the paths are correct and make sure any private packages can be accessed. If any of the packages are present in the repository then you may need a [custom build command](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-the-codeql-workflow-for-compiled-languages).", numPkgPaths, ending, secondLine),
160+
fmt.Sprintf(
161+
"%d package%s could not be found:\n\n%s.\n\nDefinitions in those packages may not be recognized by CodeQL, and files that use them may only be partially analyzed.\n\nCheck that the paths are correct and make sure any private packages can be accessed. If any of the packages are present in the repository then you may need a [custom build command](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-the-codeql-workflow-for-compiled-languages).",
162+
numPkgPaths,
163+
plural(len(pkgPaths), "", "s"),
164+
secondLine),
158165
severityWarning,
159166
fullVisibility,
160167
noLocation,

0 commit comments

Comments
 (0)