Skip to content

Commit

Permalink
Fix for emojis not working on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
antfie committed Mar 22, 2023
1 parent 693031e commit b9f7f0d
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 33 deletions.
31 changes: 15 additions & 16 deletions analyze_files.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"sort"
"strings"
)
Expand All @@ -19,8 +18,8 @@ func (data Data) analyzeUploadedFiles() {
sort.Strings(files[:])

if len(files) > 10000 {
report.WriteString(fmt.Sprintf(
"⚠️ %d files were present. This is a lot of files which is usually an indicator that something is not correct\n",
report.WriteString(formatWarningStringFormat(
"%d files were present. This is a lot of files which is usually an indicator that something is not correct\n",
len(files)))
}

Expand Down Expand Up @@ -63,8 +62,8 @@ func detectSensitiveFiles(data Data, report *strings.Builder, files []string) {
return
}

report.WriteString(fmt.Sprintf(
"%d sensitive file%s were found: %s\n",
report.WriteString(formatErrorStringFormat(
"%d sensitive file%s were found: %s\n",
len(foundFiles),
pluralise(len(foundFiles)),
top5StringList(foundFiles)))
Expand All @@ -87,8 +86,8 @@ func detectTestArtefacts(data Data, report *strings.Builder, files []string) {
return
}

report.WriteString(fmt.Sprintf(
"%d test artefact%s were found: %s\n",
report.WriteString(formatErrorStringFormat(
"%d test artefact%s were found: %s\n",
len(foundFiles),
pluralise(len(foundFiles)),
top5StringList(foundFiles)))
Expand Down Expand Up @@ -123,7 +122,7 @@ func detectNodeModules(data Data, report *strings.Builder) {
data.makeRecommendation("Review the JavaScript/TypeScript packaging cheatsheet: https://nhinv11.github.io/#/JavaScript%20/%20TypeScript")
data.makeRecommendation("Consider using the unofficial JavaScript/TypeScript packaging tool: https://github.com/fw10/veracode-javascript-packager")

report.WriteString("⚠️ One or more node_modules folders were detected\n")
report.WriteString(formatWarningString("One or more node_modules folders were detected\n"))
}

func detectGit(data Data, report *strings.Builder, files []string) {
Expand All @@ -139,7 +138,7 @@ func detectGit(data Data, report *strings.Builder, files []string) {
return
}

report.WriteString("❌ A git repository was found\n")
report.WriteString(formatErrorString("A git repository was found\n"))

data.makeRecommendation("Do not upload .git folders")
}
Expand All @@ -157,7 +156,7 @@ func detectRoslyn(data Data, report *strings.Builder, files []string) {
return
}

report.WriteString("⚠️ The .NET Roslyn compiler was found\n")
report.WriteString(formatWarningString("The .NET Roslyn compiler was found\n"))

data.makeRecommendation("Review the .NET packaging cheatsheet: https://nhinv11.github.io/#/.NET")
}
Expand All @@ -181,8 +180,8 @@ func detectUnwantedFiles(data Data, report *strings.Builder, files []string, suf
data.makeRecommendation(recommendation)
}

report.WriteString(fmt.Sprintf(
"%d %s%s: %s\n",
report.WriteString(formatErrorStringFormat(
"%d %s%s: %s\n",
len(foundFiles),
name,
pluralise(len(foundFiles)),
Expand Down Expand Up @@ -217,14 +216,14 @@ func (data Data) reportDuplicateFiles() {

if len(md5s) > 1 {
if count == len(md5s) {
warningReport.WriteString(fmt.Sprintf(
"⚠️ %d duplicate occurance%s of \"%s\"\n",
warningReport.WriteString(formatWarningStringFormat(
"%d duplicate occurance%s of \"%s\"\n",
count,
pluralise(count),
file.Name))
} else {
errorReport.WriteString(fmt.Sprintf(
"%d duplicate occurance%s of \"%s\" with %d different MD5 hashes\n",
errorReport.WriteString(formatErrorStringFormat(
"%d duplicate occurance%s of \"%s\" with %d different MD5 hashes\n",
count,
pluralise(count),
file.Name,
Expand Down
29 changes: 14 additions & 15 deletions analyze_modules.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
package main

import (
"fmt"
"strings"
)

func (data Data) analyzeModules() {
var report strings.Builder

// if data.PrescanModuleList.TotalSize > 1e+9 {
// report.WriteString(fmt.Sprintf(
// "⚠️ The size of the modules was %s. This is a very large scan and will likely take a long time to run\n",
// report.WriteString(formatWarningStringFormat(
// "The size of the modules was %s. This is a very large scan and will likely take a long time to run\n",
// humanize.Bytes(uint64(data.PrescanModuleList.TotalSize))))
// }

if len(data.PrescanModuleList.Modules) > 1000 {
report.WriteString(fmt.Sprintf(
"⚠️ %d modules were identified. This is a lot of modules which is usually an indicator that something is not correct\n",
report.WriteString(formatWarningStringFormat(
"%d modules were identified. This is a lot of modules which is usually an indicator that something is not correct\n",
len(data.PrescanModuleList.Modules)))
}

if len(data.DetailedReport.StaticAnalysis.Modules) > 100 {
report.WriteString(fmt.Sprintf(
"⚠️ %d modules were selected for analysis. This is a lot of modules which is usually an indicator that something is not correct\n",
report.WriteString(formatWarningStringFormat(
"%d modules were selected for analysis. This is a lot of modules which is usually an indicator that something is not correct\n",
len(data.DetailedReport.StaticAnalysis.Modules)))
}

Expand All @@ -40,16 +39,16 @@ func (data Data) analyzeModules() {
}

if len(thirdPartyModules) > 0 {
report.WriteString(fmt.Sprintf(
"⚠️ %d 3rd-party module%s selected that likely should not be: %s\n",
report.WriteString(formatWarningStringFormat(
"%d 3rd-party module%s selected that likely should not be: %s\n",
len(thirdPartyModules),
pluralise(len(thirdPartyModules)),
top5StringList(thirdPartyModules)))
}

if len(junkModulesSelected) > 0 {
report.WriteString(fmt.Sprintf(
"⚠️ %d module%s selected that likely should not be: %s\n",
report.WriteString(formatWarningStringFormat(
"%d module%s selected that likely should not be: %s\n",
len(junkModulesSelected),
pluralise(len(junkModulesSelected)),
top5StringList(junkModulesSelected)))
Expand Down Expand Up @@ -81,8 +80,8 @@ func (data Data) analyzeModuleFatalErrors() {
}

for errorMessage, affectedModules := range errors {
report.WriteString(fmt.Sprintf(
"%d %s: %s\n",
report.WriteString(formatErrorStringFormat(
"%d %s: %s\n",
len(affectedModules),
errorMessage,
top5StringList(affectedModules)))
Expand Down Expand Up @@ -179,8 +178,8 @@ func (data Data) analyzeModuleWarnings() {
}

for warningMessage, affectedModules := range warnings {
report.WriteString(fmt.Sprintf(
"⚠️ %d %s: %s\n",
report.WriteString(formatWarningStringFormat(
"%d %s: %s\n",
len(affectedModules),
warningMessage,
top5StringList(affectedModules)))
Expand Down
7 changes: 7 additions & 0 deletions icon_notwindows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build !windows

package main

const icon_error = "❌"
const icon_warning = "⚠️ "
const icon_recommendation = "💡"
7 changes: 7 additions & 0 deletions icon_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build windows

package main

const icon_error = "ERROR:"
const icon_warning = "WARNING:"
const icon_recommendation = "*"
4 changes: 2 additions & 2 deletions recommendations.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func (data Data) outputRecommendations(region string) {

var report strings.Builder
for _, recommendation := range *data.Recommendations {
report.WriteString(fmt.Sprintf(
"💡 %s\n",
report.WriteString(formatRecommendationStringFormat(
"%s\n",
recommendation))
}

Expand Down
20 changes: 20 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,23 @@ func top5StringList(items []string) string {

return strings.Join(items, ", ")
}

func formatWarningStringFormat(format string, a ...any) string {
return fmt.Sprintf(icon_warning+" "+format, a...)
}

func formatWarningString(a string) string {
return formatWarningStringFormat("%s", a)
}

func formatErrorStringFormat(format string, a ...any) string {
return fmt.Sprintf(icon_error+" "+format, a...)
}

func formatErrorString(a string) string {
return formatErrorStringFormat("%s", a)
}

func formatRecommendationStringFormat(format string, a ...any) string {
return fmt.Sprintf(icon_recommendation+" "+format, a...)
}

0 comments on commit b9f7f0d

Please sign in to comment.