Skip to content

Commit 4ec595e

Browse files
committed
Cleanup array output concats
1 parent d6a8e86 commit 4ec595e

File tree

5 files changed

+172
-209
lines changed

5 files changed

+172
-209
lines changed

src/commands/cli.test.mts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ describe('socket root command', async () => {
2020
2121
Main commands
2222
23-
socket login Setup the Socket CLI with an API token and defaults
24-
socket scan create Create a new Scan and report
25-
socket npm/[email protected] Request the security score of a particular package
23+
socket login Setup Socket CLI with an API token and defaults
24+
socket scan create Create a new Socket scan and report
25+
socket npm/[email protected] Request the Socket score of a package
2626
socket ci Shorthand for CI; socket scan create --report --no-interactive
2727
2828
Socket API
2929
3030
analytics Look up analytics data
3131
audit-log Look up the audit log for an organization
32-
organization Manage organization account details
32+
organization Manage Socket organization account details
3333
package Look up published package details
3434
repository Manage registered repositories
3535
scan Manage Socket scans
@@ -42,16 +42,16 @@ describe('socket root command', async () => {
4242
npm npm wrapper functionality
4343
npx npx wrapper functionality
4444
optimize Optimize dependencies with @socketregistry overrides
45-
raw-npm Temporarily disable the Socket npm wrapper
46-
raw-npx Temporarily disable the Socket npx wrapper
45+
raw-npm Run npm without the Socket npm wrapper
46+
raw-npx Run npx without the Socket npx wrapper
4747
4848
CLI configuration
4949
50-
config Manage the CLI configuration directly
51-
install Manually install CLI tab completion on your system
50+
config Manage Socket CLI configuration directly
51+
install Install Socket CLI tab completion on your system
5252
login Socket API login and CLI setup
5353
logout Socket API logout
54-
uninstall Remove the CLI tab completion from your system
54+
uninstall Remove Socket CLI tab completion from your system
5555
wrapper Enable or disable the Socket npm/npx wrapper
5656
5757
Options (Note: all CLI commands have these flags even when not displayed in their help)

src/commands/package/output-purls-deep-score.mts

Lines changed: 92 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function outputPurlsDeepScore(
1111
purl: string,
1212
result: CResult<PurlDataResponse>,
1313
outputKind: OutputKind,
14-
) {
14+
): Promise<void> {
1515
if (!result.ok) {
1616
process.exitCode = result.code ?? 1
1717
}
@@ -39,7 +39,7 @@ export async function outputPurlsDeepScore(
3939
logger.log('')
4040
}
4141

42-
export function createMarkdownReport(data: PurlDataResponse) {
42+
export function createMarkdownReport(data: PurlDataResponse): string {
4343
const {
4444
self: {
4545
alerts: selfAlerts,
@@ -57,162 +57,158 @@ export function createMarkdownReport(data: PurlDataResponse) {
5757
},
5858
} = data
5959

60-
const arr: string[] = []
61-
62-
arr.push('# Complete Package Score')
63-
arr.push('')
60+
const o: string[] = ['# Complete Package Score', '']
6461
if (dependencyCount) {
65-
arr.push(
62+
o.push(
6663
`This is a Socket report for the package *"${purl}"* and its *${dependencyCount}* direct/transitive dependencies.`,
6764
)
6865
} else {
69-
arr.push(
66+
o.push(
7067
`This is a Socket report for the package *"${purl}"*. It has *no dependencies*.`,
7168
)
7269
}
73-
arr.push('')
70+
o.push('')
7471
if (dependencyCount) {
75-
arr.push(
72+
o.push(
7673
`It will show you the shallow score for just the package itself and a deep score for all the transitives combined. Additionally you can see which capabilities were found and the top alerts as well as a package that was responsible for it.`,
7774
)
7875
} else {
79-
arr.push(
76+
o.push(
8077
`It will show you the shallow score for the package itself, which capabilities were found, and its top alerts.`,
8178
)
82-
arr.push('')
83-
arr.push(
79+
o.push('')
80+
o.push(
8481
'Since it has no dependencies, the shallow score is also the deep score.',
8582
)
8683
}
87-
arr.push('')
84+
o.push('')
8885
if (dependencyCount) {
8986
// This doesn't make much sense if there are no dependencies. Better to omit it.
90-
arr.push(
87+
o.push(
9188
'The report should give you a good insight into the status of this package.',
9289
)
93-
arr.push('')
94-
arr.push('## Package itself')
95-
arr.push('')
96-
arr.push(
90+
o.push('')
91+
o.push('## Package itself')
92+
o.push('')
93+
o.push(
9794
'Here are results for the package itself (excluding data from dependencies).',
9895
)
9996
} else {
100-
arr.push('## Report')
101-
arr.push('')
102-
arr.push(
97+
o.push('## Report')
98+
o.push('')
99+
o.push(
103100
'The report should give you a good insight into the status of this package.',
104101
)
105102
}
106-
arr.push('')
107-
arr.push('### Shallow Score')
108-
arr.push('')
109-
arr.push('This score is just for the package itself:')
110-
arr.push('')
111-
arr.push('- Overall: ' + selfScore.overall)
112-
arr.push('- Maintenance: ' + selfScore.maintenance)
113-
arr.push('- Quality: ' + selfScore.quality)
114-
arr.push('- Supply Chain: ' + selfScore.supplyChain)
115-
arr.push('- Vulnerability: ' + selfScore.vulnerability)
116-
arr.push('- License: ' + selfScore.license)
117-
arr.push('')
118-
arr.push('### Capabilities')
119-
arr.push('')
103+
o.push('')
104+
o.push('### Shallow Score')
105+
o.push('')
106+
o.push('This score is just for the package itself:')
107+
o.push('')
108+
o.push(`- Overall: ${selfScore.overall}`)
109+
o.push(`- Maintenance: ${selfScore.maintenance}`)
110+
o.push(`- Quality: ${selfScore.quality}`)
111+
o.push(`- Supply Chain: ${selfScore.supplyChain}`)
112+
o.push(`- Vulnerability: ${selfScore.vulnerability}`)
113+
o.push(`- License: ${selfScore.license}`)
114+
o.push('')
115+
o.push('### Capabilities')
116+
o.push('')
120117
if (selfCaps.length) {
121-
arr.push('These are the capabilities detected in the package itself:')
122-
arr.push('')
123-
selfCaps.forEach(cap => {
124-
arr.push(`- ${cap}`)
125-
})
118+
o.push('These are the capabilities detected in the package itself:')
119+
o.push('')
120+
for (const cap of selfCaps) {
121+
o.push(`- ${cap}`)
122+
}
126123
} else {
127-
arr.push('No capabilities were found in the package.')
124+
o.push('No capabilities were found in the package.')
128125
}
129-
arr.push('')
130-
arr.push('### Alerts for this package')
131-
arr.push('')
126+
o.push('')
127+
o.push('### Alerts for this package')
128+
o.push('')
132129
if (selfAlerts.length) {
133130
if (dependencyCount) {
134-
arr.push('These are the alerts found for the package itself:')
131+
o.push('These are the alerts found for the package itself:')
135132
} else {
136-
arr.push('These are the alerts found for this package:')
133+
o.push('These are the alerts found for this package:')
137134
}
138-
arr.push('')
139-
arr.push(
135+
o.push('')
136+
o.push(
140137
mdTable(selfAlerts, ['severity', 'name'], ['Severity', 'Alert Name']),
141138
)
142139
} else {
143-
arr.push('There are currently no alerts for this package.')
140+
o.push('There are currently no alerts for this package.')
144141
}
145-
arr.push('')
142+
o.push('')
146143
if (dependencyCount) {
147-
arr.push('## Transitive Package Results')
148-
arr.push('')
149-
arr.push(
144+
o.push('## Transitive Package Results')
145+
o.push('')
146+
o.push(
150147
'Here are results for the package and its direct/transitive dependencies.',
151148
)
152-
arr.push('')
153-
arr.push('### Deep Score')
154-
arr.push('')
155-
arr.push(
149+
o.push('')
150+
o.push('### Deep Score')
151+
o.push('')
152+
o.push(
156153
'This score represents the package and and its direct/transitive dependencies:',
157154
)
158-
arr.push(
155+
o.push(
159156
`The function used to calculate the values in aggregate is: *"${func}"*`,
160157
)
161-
arr.push('')
162-
arr.push('- Overall: ' + score.overall)
163-
arr.push('- Maintenance: ' + score.maintenance)
164-
arr.push('- Quality: ' + score.quality)
165-
arr.push('- Supply Chain: ' + score.supplyChain)
166-
arr.push('- Vulnerability: ' + score.vulnerability)
167-
arr.push('- License: ' + score.license)
168-
arr.push('')
169-
arr.push('### Capabilities')
170-
arr.push('')
171-
arr.push(
158+
o.push('')
159+
o.push(`- Overall: ${score.overall}`)
160+
o.push(`- Maintenance: ${score.maintenance}`)
161+
o.push(`- Quality: ${score.quality}`)
162+
o.push(`- Supply Chain: ${score.supplyChain}`)
163+
o.push(`- Vulnerability: ${score.vulnerability}`)
164+
o.push(`- License: ${score.license}`)
165+
o.push('')
166+
o.push('### Capabilities')
167+
o.push('')
168+
o.push(
172169
'These are the packages with the lowest recorded score. If there is more than one with the lowest score, just one is shown here. This may help you figure out the source of low scores.',
173170
)
174-
arr.push('')
175-
arr.push('- Overall: ' + lowest.overall)
176-
arr.push('- Maintenance: ' + lowest.maintenance)
177-
arr.push('- Quality: ' + lowest.quality)
178-
arr.push('- Supply Chain: ' + lowest.supplyChain)
179-
arr.push('- Vulnerability: ' + lowest.vulnerability)
180-
arr.push('- License: ' + lowest.license)
181-
arr.push('')
182-
arr.push('### Capabilities')
183-
arr.push('')
171+
o.push('')
172+
o.push(`- Overall: ${lowest.overall}`)
173+
o.push(`- Maintenance: ${lowest.maintenance}`)
174+
o.push(`- Quality: ${lowest.quality}`)
175+
o.push(`- Supply Chain: ${lowest.supplyChain}`)
176+
o.push(`- Vulnerability: ${lowest.vulnerability}`)
177+
o.push(`- License: ${lowest.license}`)
178+
o.push('')
179+
o.push('### Capabilities')
180+
o.push('')
184181
if (capabilities.length) {
185-
arr.push('These are the capabilities detected in at least one package:')
186-
arr.push('')
187-
capabilities.forEach(cap => {
188-
arr.push(`- ${cap}`)
189-
})
182+
o.push('These are the capabilities detected in at least one package:')
183+
o.push('')
184+
for (const cap of capabilities) {
185+
o.push(`- ${cap}`)
186+
}
190187
} else {
191-
arr.push(
188+
o.push(
192189
'This package had no capabilities and neither did any of its direct/transitive dependencies.',
193190
)
194191
}
195-
arr.push('')
196-
arr.push('### Alerts')
197-
arr.push('')
192+
o.push('')
193+
o.push('### Alerts')
194+
o.push('')
198195
if (alerts.length) {
199-
arr.push('These are the alerts found:')
200-
arr.push('')
196+
o.push('These are the alerts found:')
197+
o.push('')
201198

202-
arr.push(
199+
o.push(
203200
mdTable(
204201
alerts,
205202
['severity', 'name', 'example'],
206203
['Severity', 'Alert Name', 'Example package reporting it'],
207204
),
208205
)
209206
} else {
210-
arr.push(
207+
o.push(
211208
'This package had no alerts and neither did any of its direct/transitive dependencies',
212209
)
213210
}
214-
arr.push('')
215-
216-
return arr.join('\n')
211+
o.push('')
217212
}
213+
return o.join('\n')
218214
}

0 commit comments

Comments
 (0)