Skip to content

Commit e0447db

Browse files
committed
continued migration efforts
1 parent 264354a commit e0447db

File tree

11 files changed

+60
-58
lines changed

11 files changed

+60
-58
lines changed

packages/core/src/codewhisperer/service/recommendationHandler.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,7 @@ export class RecommendationHandler {
527527
// do not show recommendation if cursor is before invocation position
528528
// also mark as Discard
529529
if (editor.selection.active.isBefore(session.startPos)) {
530-
session.recommendations.forEach((r, i) => {
531-
session.setSuggestionState(i, 'Discard')
532-
})
530+
this.discardSuggestions()
533531
reject()
534532
return false
535533
}
@@ -545,9 +543,7 @@ export class RecommendationHandler {
545543
)
546544
)
547545
if (!session.recommendations[0].content.startsWith(typedPrefix.trimStart())) {
548-
session.recommendations.forEach((r, i) => {
549-
session.setSuggestionState(i, 'Discard')
550-
})
546+
this.discardSuggestions()
551547
reject()
552548
return false
553549
}
@@ -577,6 +573,12 @@ export class RecommendationHandler {
577573
this.next.dispose()
578574
}
579575

576+
private discardSuggestions() {
577+
for (const [i, _] of session.suggestionStates.entries()) {
578+
session.setSuggestionState(i, 'Discard')
579+
}
580+
}
581+
580582
// These commands override the vs code inline completion commands
581583
// They are subscribed when suggestion starts and disposed when suggestion is accepted/rejected
582584
// to avoid impacting other plugins or user who uses this API
@@ -669,9 +671,7 @@ export class RecommendationHandler {
669671
editor.selection.active.isBefore(session.startPos) ||
670672
editor.document.uri.fsPath !== this.documentUri?.fsPath
671673
) {
672-
session.recommendations.forEach((r, i) => {
673-
session.setSuggestionState(i, 'Discard')
674-
})
674+
this.discardSuggestions()
675675
this.reportUserDecisions(-1)
676676
} else if (session.recommendations.length > 0) {
677677
await this.showRecommendation(0, true)

packages/core/src/codewhisperer/service/securityScanHandler.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ export async function listScanResults(
6868
return resp.codeAnalysisFindings
6969
})
7070
.promise()
71-
issues.forEach((issue) => {
71+
for (const issue of issues) {
7272
mapToAggregatedList(codeScanIssueMap, issue, editor, scope)
73-
})
74-
codeScanIssueMap.forEach((issues, key) => {
73+
}
74+
for (const [key, issues] of codeScanIssueMap.entries()) {
7575
// Project path example: /Users/username/project
7676
// Key example: project/src/main/java/com/example/App.java
77-
projectPaths.forEach((projectPath) => {
77+
for (const projectPath of projectPaths) {
7878
// We need to remove the project path from the key to get the absolute path to the file
7979
// Do not use .. in between because there could be multiple project paths in the same parent dir.
8080
const filePath = path.join(projectPath, key.split('/').slice(1).join('/'))
@@ -85,7 +85,7 @@ export async function listScanResults(
8585
}
8686
aggregatedCodeScanIssueList.push(aggregatedCodeScanIssue)
8787
}
88-
})
88+
}
8989
const maybeAbsolutePath = `/${key}`
9090
if (existsSync(maybeAbsolutePath) && statSync(maybeAbsolutePath).isFile()) {
9191
const aggregatedCodeScanIssue: AggregatedCodeScanIssue = {
@@ -94,7 +94,7 @@ export async function listScanResults(
9494
}
9595
aggregatedCodeScanIssueList.push(aggregatedCodeScanIssue)
9696
}
97-
})
97+
}
9898
return aggregatedCodeScanIssueList
9999
}
100100

@@ -157,8 +157,7 @@ export function mapToAggregatedList(
157157
}
158158
return true
159159
})
160-
161-
filteredIssues.forEach((issue) => {
160+
for (const issue of filteredIssues) {
162161
const filePath = issue.filePath
163162
if (codeScanIssueMap.has(filePath)) {
164163
if (!isExistingIssue(issue, codeScanIssueMap)) {
@@ -169,7 +168,7 @@ export function mapToAggregatedList(
169168
} else {
170169
codeScanIssueMap.set(filePath, [issue])
171170
}
172-
})
171+
}
173172
}
174173

175174
function isDuplicateIssue(issueA: RawCodeScanIssue, issueB: RawCodeScanIssue) {

packages/core/src/codewhisperer/service/transformByQ/transformApiHandler.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ export async function zipCode(
332332
},
333333
}
334334
// TO-DO: later consider making this add to path.join(zipManifest.dependenciesRoot, 'qct-sct-metadata', entry.entryName) so that it's more organized
335+
// eslint-disable-next-line aws-toolkits/no-foreach
335336
metadataZip
336337
.getEntries()
337338
.forEach((entry) => zip.addFile(path.join(zipManifest.dependenciesRoot, entry.name), entry.getData()))
@@ -487,34 +488,34 @@ export function addTableMarkdown(plan: string, stepId: string, tableMapping: { [
487488
const table = JSON.parse(tableObj)
488489
plan += `\n\n\n${table.name}\n|`
489490
const columns = table.columnNames
490-
columns.forEach((columnName: string) => {
491+
for (const columnName of columns) {
491492
plan += ` ${getFormattedString(columnName)} |`
492-
})
493+
}
493494
plan += '\n|'
494-
columns.forEach((_: any) => {
495+
for (const _ of columns) {
495496
plan += '-----|'
496-
})
497-
table.rows.forEach((row: any) => {
497+
}
498+
for (const row of table.rows) {
498499
plan += '\n|'
499-
columns.forEach((columnName: string) => {
500+
for (const columnName of columns) {
500501
if (columnName === 'relativePath') {
501502
plan += ` [${row[columnName]}](${row[columnName]}) |` // add MD link only for files
502503
} else {
503504
plan += ` ${row[columnName]} |`
504505
}
505-
})
506-
})
506+
}
507+
}
507508
plan += '\n\n'
508509
return plan
509510
}
510511

511512
export function getTableMapping(stepZeroProgressUpdates: ProgressUpdates) {
512513
const map: { [key: string]: string } = {}
513-
stepZeroProgressUpdates.forEach((update) => {
514+
for (const update of stepZeroProgressUpdates) {
514515
// description should never be undefined since even if no data we show an empty table
515516
// but just in case, empty string allows us to skip this table without errors when rendering
516517
map[update.name] = update.description ?? ''
517-
})
518+
}
518519
return map
519520
}
520521

@@ -524,11 +525,11 @@ export function getJobStatisticsHtml(jobStatistics: any) {
524525
return htmlString
525526
}
526527
htmlString += `<div style="flex: 1; margin-left: 20px; border: 1px solid #424750; border-radius: 8px; padding: 10px;">`
527-
jobStatistics.forEach((stat: { name: string; value: string }) => {
528+
for (const stat of jobStatistics) {
528529
htmlString += `<p style="margin-bottom: 4px"><img src="${getTransformationIcon(
529530
stat.name
530531
)}" style="vertical-align: middle;"> ${getFormattedString(stat.name)}: ${stat.value}</p>`
531-
})
532+
}
532533
htmlString += `</div>`
533534
return htmlString
534535
}
@@ -573,11 +574,11 @@ export async function getTransformationPlan(jobId: string) {
573574
CodeWhispererConstants.planIntroductionMessage
574575
}</p></div>${getJobStatisticsHtml(jobStatistics)}</div>`
575576
plan += `<div style="margin-top: 32px; border: 1px solid #424750; border-radius: 8px; padding: 10px;"><p style="font-size: 18px; margin-bottom: 4px;"><b>${CodeWhispererConstants.planHeaderMessage}</b></p><i>${CodeWhispererConstants.planDisclaimerMessage} <a href="https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/code-transformation.html">Read more.</a></i><br><br>`
576-
response.transformationPlan.transformationSteps.slice(1).forEach((step) => {
577+
for (const step of response.transformationPlan.transformationSteps.slice(1)) {
577578
plan += `<div style="border: 1px solid #424750; border-radius: 8px; padding: 20px;"><div style="display:flex; justify-content:space-between; align-items:center;"><p style="font-size: 16px; margin-bottom: 4px;">${step.name}</p><a href="#top">Scroll to top <img src="${arrowIcon}" style="vertical-align: middle"></a></div><p>${step.description}</p>`
578579
plan = addTableMarkdown(plan, step.id, tableMapping)
579580
plan += `</div><br>`
580-
})
581+
}
581582
plan += `</div><br>`
582583
plan += `<p style="font-size: 18px; margin-bottom: 4px;"><b>Appendix</b><br><a href="#top" style="float: right; font-size: 14px;">Scroll to top <img src="${arrowIcon}" style="vertical-align: middle;"></a></p><br>`
583584
plan = addTableMarkdown(plan, '-1', tableMapping) // ID of '-1' reserved for appendix table

packages/core/src/codewhisperer/service/transformByQ/transformFileHandler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ export async function validateSQLMetadataFile(fileContents: string, message: any
9797
const serverNodeLocations =
9898
sctData['tree']['instances'][0]['ProjectModel'][0]['relations'][0]['server-node-location']
9999
const schemaNames = new Set<string>()
100-
serverNodeLocations.forEach((serverNodeLocation: any) => {
100+
for (const serverNodeLocation of serverNodeLocations) {
101101
const schemaNodes = serverNodeLocation['FullNameNodeInfoList'][0]['nameParts'][0][
102102
'FullNameNodeInfo'
103103
].filter((node: any) => node['$']['typeNode'].toLowerCase() === 'schema')
104-
schemaNodes.forEach((node: any) => {
104+
for (const node of schemaNodes) {
105105
schemaNames.add(node['$']['nameNode'].toUpperCase())
106-
})
107-
})
106+
}
107+
}
108108
transformByQState.setSchemaOptions(schemaNames) // user will choose one of these
109109
getLogger().info(
110110
`CodeTransformation: Parsed .sct file with source DB: ${sourceDB}, target DB: ${targetDB}, source host name: ${sourceServerName}, and schema names: ${Array.from(schemaNames)}`

packages/core/src/codewhisperer/service/transformByQ/transformationResultsViewProvider.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export class DiffModel {
145145
public copyProject(pathToWorkspace: string, changedFiles: ParsedDiff[]) {
146146
const pathToTmpSrcDir = path.join(os.tmpdir(), `project-copy-${Date.now()}`)
147147
fs.mkdirSync(pathToTmpSrcDir)
148-
changedFiles.forEach((file) => {
148+
for (const file of changedFiles) {
149149
const pathToTmpFile = path.join(pathToTmpSrcDir, file.oldFileName!.substring(2))
150150
// use mkdirsSync to create parent directories in pathToTmpFile too
151151
fs.mkdirSync(path.dirname(pathToTmpFile), { recursive: true })
@@ -154,7 +154,7 @@ export class DiffModel {
154154
if (fs.existsSync(pathToOldFile)) {
155155
fs.copyFileSync(pathToOldFile, pathToTmpFile)
156156
}
157-
})
157+
}
158158
return pathToTmpSrcDir
159159
}
160160

@@ -243,11 +243,11 @@ export class DiffModel {
243243
}
244244

245245
public saveChanges() {
246-
this.patchFileNodes.forEach((patchFileNode) => {
247-
patchFileNode.children.forEach((changeNode) => {
246+
for (const parentFileNode of this.patchFileNodes) {
247+
for (const changeNode of parentFileNode.children) {
248248
changeNode.saveChange()
249-
})
250-
})
249+
}
250+
}
251251
}
252252

253253
public rejectChanges() {

packages/core/src/codewhisperer/tracker/codewhispererCodeCoverageTracker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ export class CodeWhispererCodeCoverageTracker {
104104
// the accepted characters after calculating user modification
105105
let unmodifiedAcceptedTokens = 0
106106
for (const filename in this._acceptedTokens) {
107-
this._acceptedTokens[filename].forEach((v) => {
107+
for (const v of this._acceptedTokens[filename]) {
108108
if (filename in this._totalTokens && this._totalTokens[filename] >= v.accepted) {
109109
unmodifiedAcceptedTokens += v.accepted
110110
acceptedTokens += v.text.length
111111
}
112-
})
112+
}
113113
}
114114
const percentCount = ((acceptedTokens / totalTokens) * 100).toFixed(2)
115115
const percentage = Math.round(parseInt(percentCount))

packages/core/src/codewhisperer/util/authUtil.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ export class AuthUtil {
457457
state[Features.codewhispererCore] = AuthStates.connected
458458
}
459459
if (isValidAmazonQConnection(conn)) {
460-
Object.values(Features).forEach((v) => (state[v as Feature] = AuthStates.connected))
460+
for (const v of Object.values(Features)) {
461+
state[v as Feature] = AuthStates.connected
462+
}
461463
}
462464
}
463465

packages/core/src/codewhisperer/util/closingBracketUtil.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,14 @@ const removeBracketsFromRightContext = async (
111111
} else {
112112
await editor.edit(
113113
(editBuilder) => {
114-
idxToRemove.forEach((idx) => {
115-
const range = new vscode.Range(
116-
editor.document.positionAt(offset + idx),
117-
editor.document.positionAt(offset + idx + 1)
114+
for (const idx of idxToRemove) {
115+
editBuilder.delete(
116+
new vscode.Range(
117+
editor.document.positionAt(offset + idx),
118+
editor.document.positionAt(offset + idx + 1)
119+
)
118120
)
119-
editBuilder.delete(range)
120-
})
121+
}
121122
},
122123
{ undoStopAfter: false, undoStopBefore: false }
123124
)

packages/core/src/codewhisperer/util/customizationUtil.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ export const selectCustomization = async (customization: Customization) => {
328328
export const getAvailableCustomizationsList = async () => {
329329
const items: Customization[] = []
330330
const response = await codeWhispererClient.listAvailableCustomizations()
331+
// eslint-disable-next-line aws-toolkits/no-foreach
331332
response
332333
.map((listAvailableCustomizationsResponse) => listAvailableCustomizationsResponse.customizations)
333334
.forEach((customizations) => {

packages/core/src/codewhisperer/util/editorContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function logSupplementalContext(supplementalContext: CodeWhispererSupplementalCo
216216
true
217217
).trimStart()
218218

219-
supplementalContext.supplementalContextItems.forEach((context, index) => {
219+
for (const [index, context] of supplementalContext.supplementalContextItems.entries()) {
220220
logString += indent(`\nChunk ${index}:\n`, 4, true)
221221
logString += indent(
222222
`Path: ${context.filePath}
@@ -225,7 +225,7 @@ function logSupplementalContext(supplementalContext: CodeWhispererSupplementalCo
225225
8,
226226
true
227227
)
228-
})
228+
}
229229

230230
getLogger().debug(logString)
231231
}

0 commit comments

Comments
 (0)