Skip to content

Commit 0d7ea7d

Browse files
authored
build(lint): add rule to prefer direct imports over index.ts #6372
## Problem Importing from `..` or an `index.ts` file can lead to circular dependencies. ## Solution - add a lint rule to discourage importing from `..`. - migrate existing cases to import directly from the target module.
1 parent dd1d8e1 commit 0d7ea7d

File tree

6 files changed

+12
-7
lines changed

6 files changed

+12
-7
lines changed

.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ module.exports = {
206206
message:
207207
'Avoid child_process, use ChildProcess from `shared/utilities/processUtils.ts` instead.',
208208
},
209+
{
210+
name: '..',
211+
message:
212+
'Avoid importing from index.ts files as it can lead to circular dependencies. Import from the module directly instead.',
213+
},
209214
],
210215
},
211216
],

packages/core/src/codewhisperer/commands/startTestGeneration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
throwIfCancelled,
1616
} from '../service/testGenHandler'
1717
import path from 'path'
18-
import { testGenState } from '..'
18+
import { testGenState } from '../models/model'
1919
import { ChatSessionManager } from '../../amazonqTest/chat/storages/chatSession'
2020
import { ChildProcess, spawn } from 'child_process' // eslint-disable-line no-restricted-imports
2121
import { BuildStatus } from '../../amazonqTest/chat/session/session'

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import CodeWhispererUserClient, {
1616
import { CreateUploadUrlError, InvalidSourceZipError, TestGenFailedError, TestGenTimedOutError } from '../models/errors'
1717
import { getMd5, uploadArtifactToS3 } from './securityScanHandler'
1818
import { fs, randomUUID, sleep, tempDirPath } from '../../shared'
19-
import { ShortAnswer, TestGenerationJobStatus, testGenState } from '..'
19+
import { ShortAnswer, testGenState } from '../models/model'
2020
import { ChatSessionManager } from '../../amazonqTest/chat/storages/chatSession'
2121
import { createCodeWhispererChatStreamingClient } from '../../shared/clients/codewhispererChatClient'
2222
import { downloadExportResultArchive } from '../../shared/utilities/download'
@@ -182,9 +182,9 @@ export async function pollTestJobStatus(
182182
}
183183
ChatSessionManager.Instance.getSession().shortAnswer = shortAnswer
184184
}
185-
if (resp.testGenerationJob?.status !== TestGenerationJobStatus.IN_PROGRESS) {
185+
if (resp.testGenerationJob?.status !== CodeWhispererConstants.TestGenerationJobStatus.IN_PROGRESS) {
186186
// This can be FAILED or COMPLETED
187-
status = resp.testGenerationJob?.status as TestGenerationJobStatus
187+
status = resp.testGenerationJob?.status as CodeWhispererConstants.TestGenerationJobStatus
188188
logger.verbose(`testgen job status: ${status}`)
189189
logger.verbose(`Complete polling test job status.`)
190190
break

packages/core/src/shared/env/resolveEnv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import * as crypto from 'crypto'
1212
import { DevSettings } from '../settings'
13-
import { getLogger } from '..'
13+
import { getLogger } from '../logger/logger'
1414
import { ToolkitError } from '../errors'
1515
import { userInfo } from 'os'
1616
import path from 'path'

packages/core/src/shared/utilities/downloadPatterns.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import AdmZip from 'adm-zip'
88
import { getLogger } from '../logger/logger'
99
import * as vscode from 'vscode'
1010
import * as path from 'path'
11-
import { ToolkitError } from '..'
11+
import { ToolkitError } from '../errors'
1212

1313
// Get pattern code and save it in temporary folder
1414
async function fetchUrl(owner: string, repoName: string, assetName: string): Promise<Buffer> {

packages/core/src/shared/utilities/pollingSet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { globals } from '..'
6+
import globals from '../../shared/extensionGlobals'
77

88
/**
99
* A useful abstraction that does the following:

0 commit comments

Comments
 (0)