Skip to content

Commit

Permalink
build(lint): add rule to prefer direct imports over index.ts #6372
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
Hweinstock authored Jan 15, 2025
1 parent dd1d8e1 commit 0d7ea7d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ module.exports = {
message:
'Avoid child_process, use ChildProcess from `shared/utilities/processUtils.ts` instead.',
},
{
name: '..',
message:
'Avoid importing from index.ts files as it can lead to circular dependencies. Import from the module directly instead.',
},
],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
throwIfCancelled,
} from '../service/testGenHandler'
import path from 'path'
import { testGenState } from '..'
import { testGenState } from '../models/model'
import { ChatSessionManager } from '../../amazonqTest/chat/storages/chatSession'
import { ChildProcess, spawn } from 'child_process' // eslint-disable-line no-restricted-imports
import { BuildStatus } from '../../amazonqTest/chat/session/session'
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/codewhisperer/service/testGenHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import CodeWhispererUserClient, {
import { CreateUploadUrlError, InvalidSourceZipError, TestGenFailedError, TestGenTimedOutError } from '../models/errors'
import { getMd5, uploadArtifactToS3 } from './securityScanHandler'
import { fs, randomUUID, sleep, tempDirPath } from '../../shared'
import { ShortAnswer, TestGenerationJobStatus, testGenState } from '..'
import { ShortAnswer, testGenState } from '../models/model'
import { ChatSessionManager } from '../../amazonqTest/chat/storages/chatSession'
import { createCodeWhispererChatStreamingClient } from '../../shared/clients/codewhispererChatClient'
import { downloadExportResultArchive } from '../../shared/utilities/download'
Expand Down Expand Up @@ -182,9 +182,9 @@ export async function pollTestJobStatus(
}
ChatSessionManager.Instance.getSession().shortAnswer = shortAnswer
}
if (resp.testGenerationJob?.status !== TestGenerationJobStatus.IN_PROGRESS) {
if (resp.testGenerationJob?.status !== CodeWhispererConstants.TestGenerationJobStatus.IN_PROGRESS) {
// This can be FAILED or COMPLETED
status = resp.testGenerationJob?.status as TestGenerationJobStatus
status = resp.testGenerationJob?.status as CodeWhispererConstants.TestGenerationJobStatus
logger.verbose(`testgen job status: ${status}`)
logger.verbose(`Complete polling test job status.`)
break
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/env/resolveEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import * as crypto from 'crypto'
import { DevSettings } from '../settings'
import { getLogger } from '..'
import { getLogger } from '../logger/logger'
import { ToolkitError } from '../errors'
import { userInfo } from 'os'
import path from 'path'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/utilities/downloadPatterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import AdmZip from 'adm-zip'
import { getLogger } from '../logger/logger'
import * as vscode from 'vscode'
import * as path from 'path'
import { ToolkitError } from '..'
import { ToolkitError } from '../errors'

// Get pattern code and save it in temporary folder
async function fetchUrl(owner: string, repoName: string, assetName: string): Promise<Buffer> {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/utilities/pollingSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { globals } from '..'
import globals from '../../shared/extensionGlobals'

/**
* A useful abstraction that does the following:
Expand Down

0 comments on commit 0d7ea7d

Please sign in to comment.