Skip to content

Commit b74af4d

Browse files
authored
Support for JSON with comments for security scans (#4090)
* Support for JSON with comments for security scans * Update Telemetry version * CW: Test case to validate getDependencyGraph for JSON * CW: Added Test Cases for sendTelemetryEvent for codeScan * Removing test case: Redundant --------- Co-authored-by: Laxman Reddy <[email protected]>
1 parent fba0246 commit b74af4d

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

src/codewhisperer/models/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export const platformLanguageIds = [
9898
'terragrunt',
9999
'packer',
100100
'plaintext',
101+
'jsonc',
101102
] as const
102103

103104
export type PlatformLanguageId = (typeof platformLanguageIds)[number]

src/codewhisperer/util/dependencyGraph/dependencyGraphFactory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export class DependencyGraphFactory {
3232
static getDependencyGraphFromFileExtensions<K extends Keys>(fileName: string): ClassType<K> {
3333
if (fileName.endsWith(DependencyGraphConstants.tfExt) || fileName.endsWith(DependencyGraphConstants.hclExt)) {
3434
return new languageMap['terraform']('tf' satisfies CodeWhispererConstants.PlatformLanguageId)
35+
} else if (fileName.endsWith(DependencyGraphConstants.jsonExt)) {
36+
return new languageMap['cloudformation']('json' satisfies CodeWhispererConstants.PlatformLanguageId)
3537
} else {
3638
return undefined
3739
}
@@ -51,8 +53,6 @@ export class DependencyGraphFactory {
5153
return new languageMap['csharp']('csharp' satisfies CodeWhispererConstants.PlatformLanguageId)
5254
case 'yaml' satisfies CodeWhispererConstants.PlatformLanguageId:
5355
return new languageMap['cloudformation']('yaml' satisfies CodeWhispererConstants.PlatformLanguageId)
54-
case 'json' satisfies CodeWhispererConstants.PlatformLanguageId:
55-
return new languageMap['cloudformation']('json' satisfies CodeWhispererConstants.PlatformLanguageId)
5656
default:
5757
return this.getDependencyGraphFromFileExtensions(editor.document.fileName)
5858
}

src/codewhisperer/util/runtimeLanguageContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class RuntimeLanguageContext {
6565
javascript: 'javascript',
6666
javascriptreact: 'jsx',
6767
json: 'json',
68-
jsonc: 'jsonc',
68+
jsonc: 'json',
6969
jsx: 'jsx',
7070
kotlin: 'kotlin',
7171
packer: 'tf',
@@ -97,7 +97,7 @@ export class RuntimeLanguageContext {
9797
java: 'java',
9898
javascript: 'js',
9999
json: 'json',
100-
jsonc: 'jsonc',
100+
jsonc: 'json',
101101
jsx: 'jsx',
102102
kotlin: 'kt',
103103
plaintext: 'txt',

src/test/codewhisperer/util/dependencyGraphFactory.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { join } from 'path'
99
import { getTestWorkspaceFolder } from '../../../testInteg/integrationTestsUtilities'
1010
import { DependencyGraphFactory } from '../../../codewhisperer/util/dependencyGraph/dependencyGraphFactory'
1111
import { terraformDependencyGraph } from './../../../codewhisperer/util/dependencyGraph/terraformDependencyGraph'
12+
import { cloudformationDependencyGraph } from '../../../codewhisperer/util/dependencyGraph/cloudformationDependencyGraph'
1213

1314
describe('DependencyGraphFactory', function () {
1415
const workspaceFolder = getTestWorkspaceFolder()
@@ -27,4 +28,13 @@ describe('DependencyGraphFactory', function () {
2728
const isTerraformDependencyGraph = dependencyGraph instanceof terraformDependencyGraph
2829
assert.ok(isTerraformDependencyGraph)
2930
})
31+
32+
it('codescan request for file in supported json language find generate dependency graph using file extension', async function () {
33+
const appRoot = join(workspaceFolder, 'cloudformation-plain-sam-app')
34+
const appCodePath = join(appRoot, 'src', 'app.json')
35+
const editor = await openTestFile(appCodePath)
36+
const dependencyGraph = DependencyGraphFactory.getDependencyGraph(editor)
37+
const isCloudFormationDependencyGraph = dependencyGraph instanceof cloudformationDependencyGraph
38+
assert.ok(isCloudFormationDependencyGraph)
39+
})
3040
})

0 commit comments

Comments
 (0)