Skip to content

Commit

Permalink
Merge #5054 lint
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmk3 committed May 24, 2024
2 parents 04bbdd2 + a7c4b9d commit 020f6f7
Show file tree
Hide file tree
Showing 41 changed files with 227 additions and 276 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ types/*.d.ts

# Duplicate entries because prettier can be ran from root or within the workspace/subpackage.
# TODO: Avoid this.
resources/js/graphStateMachine.js
src/shared/telemetry/clienttelemetry.d.ts
src/codewhisperer/client/codewhispererclient.d.ts
src/codewhisperer/client/codewhispereruserclient.d.ts
src/amazonqFeatureDev/client/featuredevproxyclient.d.ts
src/auth/sso/oidcclientpkce.d.ts
src/testFixtures/**

packages/core/resources/js/graphStateMachine.js
packages/core/src/shared/telemetry/clienttelemetry.d.ts
packages/core/src/codewhisperer/client/codewhispererclient.d.ts
packages/core/src/codewhisperer/client/codewhispereruserclient.d.ts
Expand Down
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ module.exports = {
// This is off because prettier takes care of it
'no-extra-semi': 'off',
'@typescript-eslint/no-empty-function': 'off',
// Disallows returning e.g. Promise<…|never> which signals that an exception may be thrown.
// https://stackoverflow.com/q/64230626/152142
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-floating-promises': 'error', // Promises must catch errors or be awaited.
'@typescript-eslint/no-var-requires': 'off', // Should be able to remove with the full migration of SDK v3
Expand Down
299 changes: 112 additions & 187 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"@types/vscode": "^1.68.0",
"@types/vscode-webview": "^1.57.1",
"@types/webpack-env": "^1.18.1",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.1",
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"@vscode/codicons": "^0.0.33",
"@vscode/test-electron": "^2.3.8",
"@vscode/test-web": "^0.0.54",
Expand Down
4 changes: 3 additions & 1 deletion packages/amazonq/src/extensionShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export async function activateShared(context: vscode.ExtensionContext, isWeb: bo
() =>
vscode.window
.showInformationMessage(
`The Amazon Q extension is incompatible with AWS Toolkit ${toolkitVersion} and older. Your AWS Toolkit was updated to version 3.0 or later.`,
`The Amazon Q extension is incompatible with AWS Toolkit ${
toolkitVersion as any
} and older. Your AWS Toolkit was updated to version 3.0 or later.`,
'Reload Now'
)
.then(async resp => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4015,8 +4015,8 @@
"@types/uuid": "^9.0.1",
"@types/whatwg-url": "^11.0.4",
"@types/xml2js": "^0.4.11",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.1",
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"@vue/compiler-sfc": "^3.3.2",
"c8": "^9.0.0",
"circular-dependency-plugin": "^5.2.2",
Expand Down
10 changes: 5 additions & 5 deletions packages/core/scripts/build/generateServiceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as child_process from 'child_process'
import * as proc from 'child_process'
import * as fs from 'fs-extra'
import * as path from 'path'

Expand Down Expand Up @@ -48,7 +48,7 @@ async function cloneJsSdk(dir: string): Promise<void> {
}
const tag = `v${sdkversion}`

const gitHead = child_process.spawnSync('git', ['-C', dir, 'rev-parse', 'HEAD'])
const gitHead = proc.spawnSync('git', ['-C', dir, 'rev-parse', 'HEAD'])

const alreadyCloned = gitHead.status !== undefined && gitHead.status === 0
const msg = `${alreadyCloned ? 'Updating' : 'Cloning'} AWS JS SDK...
Expand All @@ -75,7 +75,7 @@ async function cloneJsSdk(dir: string): Promise<void> {
dir,
]

const gitCmd = child_process.execFile('git', gitArgs, { encoding: 'utf8' })
const gitCmd = proc.execFile('git', gitArgs, { encoding: 'utf8' })

gitCmd.stderr?.on('data', (data: any) => {
console.log(data)
Expand All @@ -84,7 +84,7 @@ async function cloneJsSdk(dir: string): Promise<void> {
gitCmd.stdout?.removeAllListeners()

// Only needed for the "update" case, but harmless for "clone".
const gitCheckout = child_process.spawnSync('git', [
const gitCheckout = proc.spawnSync('git', [
'-c',
'advice.detachedHead=false',
'-C',
Expand Down Expand Up @@ -164,7 +164,7 @@ async function patchServicesIntoApiMetadata(apiMetadataPath: string, serviceName
async function runTypingsGenerator(repoPath: string): Promise<void> {
console.log('Generating service client typings...')

const stdout = child_process.execFileSync('node', ['scripts/typings-generator.js'], {
const stdout = proc.execFileSync('node', ['scripts/typings-generator.js'], {
encoding: 'utf8',
cwd: repoPath,
})
Expand Down
4 changes: 2 additions & 2 deletions packages/core/scripts/test/launchTestUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as child_process from 'child_process'
import * as proc from 'child_process'
import packageJson from '../../package.json'
import { downloadAndUnzipVSCode, resolveCliArgsFromVSCodeExecutablePath } from '@vscode/test-electron'
import { join, resolve } from 'path'
Expand Down Expand Up @@ -168,7 +168,7 @@ async function invokeVSCodeCli(vsCodeExecutablePath: string, args: string[]): Pr
}

console.log(`Invoking vscode CLI command:\n "${cli}" ${JSON.stringify(cmdArgs)}`)
const spawnResult = child_process.spawnSync(cli, cmdArgs, {
const spawnResult = proc.spawnSync(cli, cmdArgs, {
encoding: 'utf-8',
stdio: 'pipe',
})
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/accessanalyzer/vue/iamPolicyChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ async function _readCustomChecksFile(input: string): Promise<string> {
const [region, bucket, key] = parseS3Uri(input)
const s3Client = new DefaultS3Client(region)
const resp = await s3Client.getObject({ bucketName: bucket, key })
// Lint warning: this may evaluate to '[object Object]'. @typescript-eslint/no-base-to-string
// eslint-disable-next-line @typescript-eslint/no-base-to-string
return resp.objectBody.toString()
} catch (e: any) {
if (e.message.includes('Invalid S3 URI')) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/apigateway/vue/invokeRemoteRestApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export async function invokeRemoteRestApi(
[curr.id!]: curr,
}
}, {})
logger.debug(`Loaded: ${resources}`)
logger.debug(`Loaded: %O`, resources)

// something is wrong if the paths aren't defined...
// const sortResources = (a: [string, Resource], b: [string, Resource]) => a[1].path!.localeCompare(b[1].path!)
Expand Down
29 changes: 14 additions & 15 deletions packages/core/src/applicationcomposer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,20 @@ export enum MessageType {
BROADCAST = 'BROADCAST',
}

enum TelemetryType {
GENERATE_CLICKED = 'GENERATE_CLICKED',
REGENERATE_CLICKED = 'REGENERATE_CLICKED',
GENERATE_ACCEPTED = 'GENERATE_ACCEPTED',
GENERATE_REJECTED = 'GENERATE_REJECTED',
INVALID_GENERATION = 'INVALID_GENERATION',
POST_PROCESS = 'POST_PROCESS',
CUSTOMER_READY = 'CUSTOMER_READY',
FPS = 'FPS',
ADD_RESOURCE = 'ADD_RESOURCE',
ADD_CONNECTION = 'ADD_CONNECTION',
OPEN_WFS = 'OPEN_WFS',
CLOSE_WFS = 'CLOSE_WFS',
TEMPLATE_OPENED = 'TEMPLATE_OPENED',
}
type TelemetryType =
| 'GENERATE_CLICKED'
| 'REGENERATE_CLICKED'
| 'GENERATE_ACCEPTED'
| 'GENERATE_REJECTED'
| 'INVALID_GENERATION'
| 'POST_PROCESS'
| 'CUSTOMER_READY'
| 'FPS'
| 'ADD_RESOURCE'
| 'ADD_CONNECTION'
| 'OPEN_WFS'
| 'CLOSE_WFS'
| 'TEMPLATE_OPENED'

export interface InitResponseMessage extends Message {
templateFileName: string
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/auth/credentials/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export async function throwOnInvalidCredentials(profileName: SectionName, data:

const credentialsDataErrors = getCredentialsErrors(data)
if (credentialsDataErrors !== undefined) {
throw new ToolkitError(`Errors in credentials data: ${credentialsDataErrors}`, {
throw new ToolkitError(`Errors in credentials data: ${String(credentialsDataErrors)}`, {
code: 'InvalidCredentialsData',
details: credentialsDataErrors,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/awsexplorer/awsExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class AwsExplorer implements vscode.TreeDataProvider<AWSTreeNodeBase>, Re
}
} catch (err) {
const error = err as Error
this.logger.error(`Error getting children for node ${element?.label ?? 'Root Node'}: %s`, error)
this.logger.error(`Error getting children for node %O: %s`, element?.label ?? 'Root Node', error)

childNodes.splice(
0,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/codewhisperer/client/codewhisperer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type ListCodeScanFindingsRequest = Readonly<
export type SupplementalContext = Readonly<
CodeWhispererClient.SupplementalContext | CodeWhispererUserClient.SupplementalContext
>
// eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents
export type ArtifactType = Readonly<CodeWhispererClient.ArtifactType | CodeWhispererUserClient.ArtifactType>
export type ArtifactMap = Readonly<CodeWhispererClient.ArtifactMap | CodeWhispererUserClient.ArtifactMap>
export type ListCodeScanFindingsResponse =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
FolderInfo,
TransformationCandidateProject,
ZipManifest,
TransformByQStatus,
} from '../models/model'
import { convertDateToTimestamp, getStringHash } from '../../shared/utilities/textUtilities'
import {
Expand Down Expand Up @@ -650,7 +651,7 @@ export async function postTransformationJob() {
codeTransformRunTimeLatency: durationInMs,
codeTransformLocalMavenVersion: mavenVersionInfoMessage,
codeTransformLocalJavaVersion: javaVersionInfoMessage,
result: resultStatusMessage === 'Succeeded' ? MetadataResult.Pass : MetadataResult.Fail,
result: resultStatusMessage === TransformByQStatus.Succeeded ? MetadataResult.Pass : MetadataResult.Fail,
reason: resultStatusMessage,
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ export class CWInlineCompletionItemProvider implements vscode.InlineCompletionIt
if (matchedCount >= 2 || this.nextToken !== '') {
const result = [item]
for (let j = 0; j < matchedCount - 1; j++) {
result.push({ insertText: `${item.insertText}${j}`, range: item.range })
result.push({
insertText: `${
typeof item.insertText === 'string' ? item.insertText : item.insertText.value
}${j}`,
range: item.range,
})
}
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,12 +633,14 @@ export class RecommendationHandler {
}

async onCursorChange(e: vscode.TextEditorSelectionChangeEvent) {
// e.kind will be 1 for keyboard cursor change events
// we do not want to reset the states for keyboard events because they can be typeahead
if (e.kind !== 1 && vscode.window.activeTextEditor === e.textEditor) {
if (
e.kind !== vscode.TextEditorSelectionChangeKind.Keyboard &&
vscode.window.activeTextEditor === e.textEditor
) {
application()._clearCodeWhispererUIListener.fire()
// when cursor change due to mouse movement we need to reset the active item index for inline
if (e.kind === 2) {
if (e.kind === vscode.TextEditorSelectionChangeKind.Mouse) {
this.inlineCompletionProvider?.clearActiveItemIndex()
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/dev/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export type DevFunction =
| 'openTerminal'
| 'deleteDevEnv'
| 'editStorage'
| 'editStorage'
| 'showEnvVars'
| 'deleteSsoConnections'
| 'expireSsoConnections'
Expand Down
8 changes: 1 addition & 7 deletions packages/core/src/dev/codecatalyst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,7 @@ async function promptVsix(
): Promise<vscode.Uri | undefined> {
const folders = (vscode.workspace.workspaceFolders ?? []).map(f => f.uri).concat(vscode.Uri.file(ctx.extensionPath))

enum ExtensionMode {
Production = 1,
Development = 2,
Test = 3,
}

const isDevelopmentWindow = ctx.extensionMode === ExtensionMode.Development
const isDevelopmentWindow = ctx.extensionMode === vscode.ExtensionMode.Development
const extPath = isDevelopmentWindow ? ctx.extensionPath : folders[0].fsPath

const packageNew = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export default defineComponent({
}
this.containerBuild = config.sam?.containerBuild ?? false
this.skipNewImageCheck = config.sam?.skipNewImageCheck ?? false
this.msg = `Loaded config ${config}`
this.msg = `Loaded config: ${config.name}`
this.company = company
},
loadPayload() {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lambda/vue/remoteInvoke/invokeLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class RemoteInvokeWebview extends VueWebview {
this.channel.appendLine(logs)
this.channel.appendLine('')
this.channel.appendLine('Payload:')
this.channel.appendLine(payload.toString())
this.channel.appendLine(String(payload))
this.channel.appendLine('')
} catch (e) {
const error = e as Error
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/shared/cloudformation/cloudformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ export async function tryLoad(
// https://github.com/aws-cloudformation/aws-cfn-lint-visual-studio-code/blob/629de0bac4f36cfc6534e409a6f6766a2240992f/client/src/yaml-support/yaml-schema.ts#L39-L51
if (rv.template?.AWSTemplateFormatVersion || rv.template?.Resources) {
rv.kind =
rv.template.Transform && rv.template.Transform.toString().startsWith('AWS::Serverless') ? 'sam' : 'cfn'
typeof rv.template.Transform === 'string' && rv.template.Transform.startsWith('AWS::Serverless')
? 'sam'
: 'cfn'

return rv
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/shared/extensions/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ export class GitExtension {

if (version === undefined || version.compare(minGitFilterVersion) === -1) {
throw new Error(
`Git version is too low or could not be determined (min=${minGitFilterVersion}): ${
version ?? 'unknown'
`Git version is too low or could not be determined (min=${minGitFilterVersion.version}): ${
version?.version ?? 'unknown'
}`
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/fs/watchedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export abstract class WatchedFiles<T> implements vscode.Disposable {
}

private outputPatterns(): string {
const watch = this.globs.map(cur => cur.toString())
const watch = this.globs.map(cur => (typeof cur === 'string' ? cur.toString() : cur.pattern))
if (this.watchingUntitledFiles) {
watch.push('Untitled Files')
}
Expand Down
14 changes: 9 additions & 5 deletions packages/core/src/shared/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getLogger } from './logger/logger'
// https://code.visualstudio.com/api/references/icons-in-labels#animation

type ContributedIcon = keyof typeof packageJson.contributes.icons
type IconPath = { light: Uri; dark: Uri } | Icon
type IconPath = { light: Uri; dark: Uri; toString: () => string } | Icon
type IconId = `vscode-${string}` | ContributedIcon

/**
Expand Down Expand Up @@ -117,13 +117,17 @@ function resolveIconId(
return new Icon(namespace === 'vscode' ? name : id, source)
}

function resolvePathsSync(rootDir: string, target: string): { light: Uri; dark: Uri } | undefined {
const darkPath = path.join(rootDir, 'dark', `${target}.svg`)
const lightPath = path.join(rootDir, 'light', `${target}.svg`)
function resolvePathsSync(
rootDir: string,
target: string
): { light: Uri; dark: Uri; toString: () => string } | undefined {
const filename = `${target}.svg`
const darkPath = path.join(rootDir, 'dark', filename)
const lightPath = path.join(rootDir, 'light', filename)

try {
if (!isWeb() && fs.existsSync(darkPath) && fs.existsSync(lightPath)) {
return { dark: Uri.file(darkPath), light: Uri.file(lightPath) }
return { dark: Uri.file(darkPath), light: Uri.file(lightPath), toString: () => filename }
}
} catch (error) {
getLogger().warn(`icons: path resolution failed for "${target}": %s`, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ export class HttpResourceFetcher implements ResourceFetcher {
promise.cancel(new CancellationError(event.agent).message)
})

promise.finally(() => cancelListener?.dispose())

return promise
return promise.finally(() => cancelListener?.dispose())
}

private buildRequestHeaders(requestHeaders?: RequestHeaders): Headers {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/shared/sam/cli/samCliLocalInvoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as child_process from 'child_process'
import * as proc from 'child_process'
import { pushIf } from '../../utilities/collectionUtils'
import * as nls from 'vscode-nls'
import { fileExists } from '../../filesystemUtilities'
Expand All @@ -30,7 +30,7 @@ export const waitForDebuggerMessages = {
export interface SamLocalInvokeCommandArgs {
command: string
args: string[]
options?: child_process.SpawnOptions
options?: proc.SpawnOptions
/** Wait until strings specified in `debuggerAttachCues` appear in the process output. */
waitForCues: boolean
timeout?: Timeout
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/sam/debugger/csharpSamDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export async function makeDotnetDebugConfiguration(
codeUri: string
): Promise<DotNetDebugConfiguration> {
if (config.noDebug) {
throw Error(`SAM debug: invalid config ${config}`)
throw Error(`SAM debug: invalid config: ${config.name}`)
}
const pipeArgs = ['-c', `docker exec -i $(docker ps -q -f publish=${config.debugPort}) \${debuggerCommand}`]
config.debuggerPath = pathutil.normalize(getDebuggerPath(codeUri))
Expand Down

0 comments on commit 020f6f7

Please sign in to comment.