Skip to content

Commit 14aab45

Browse files
authored
refactor: eliminate use of "namespace" #3968
Problem: namespace is deprecated and unnecessary. Solution: remove use of `namespace`. add a lint rule to prevent it. clean up old dead code.
1 parent 2324ff9 commit 14aab45

File tree

72 files changed

+1016
-1314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1016
-1314
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ src/shared/telemetry/clienttelemetry.d.ts
44
src/codewhisperer/client/codewhispererclient.d.ts
55
src/codewhisperer/client/codewhispereruserclient.d.ts
66
**/*.gen.ts
7-
src/testFixtures/workspaceFolder/ts-plain-sam-app/
7+
src/testFixtures/**
88
dist/**
99
types/*.d.ts

.eslintrc.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ module.exports = {
8585
// TODO reenable this rule, tests mostly break this one (by changing off to error)
8686
// This currently produces 700 non fixable by --fix errors
8787
'sort-imports': 'off',
88-
// TODO rennable this rule (by removing this off)
89-
// namespaces are not great and we should stop using them
90-
'@typescript-eslint/no-namespace': 'off',
88+
'@typescript-eslint/no-namespace': 'error',
9189
// Turn this on by removing off when we fix namespaces
9290
'no-inner-declarations': 'off',
9391
// This is off because prettier takes care of it

src/awsexplorer/commands/copyText.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { Env } from '../../shared/vscode/env'
76
import { copyToClipboard } from '../../shared/utilities/messages'
87
import { AWSResourceNode } from '../../shared/treeview/nodes/awsResourceNode'
98
import { TreeShim } from '../../shared/treeview/utils'
@@ -12,19 +11,18 @@ export type copyableText = 'ARN' | 'name' | 'id'
1211

1312
export async function copyTextCommand(
1413
node: AWSResourceNode | TreeShim<AWSResourceNode>,
15-
text: copyableText,
16-
env = Env.vscode()
14+
text: copyableText
1715
): Promise<void> {
1816
node = node instanceof TreeShim ? node.node.resource : node
1917
switch (text) {
2018
case 'ARN':
21-
await copyToClipboard(node.arn, text, env)
19+
await copyToClipboard(node.arn, text)
2220
break
2321
case 'name':
24-
await copyToClipboard(node.name, text, env)
22+
await copyToClipboard(node.name, text)
2523
break
2624
case 'id':
27-
await copyToClipboard(node.id!, text, env)
25+
await copyToClipboard(node.id!, text)
2826
break
2927
}
3028
}

src/dynamicResources/commands/copyIdentifier.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { Env } from '../../shared/vscode/env'
7-
import { copyToClipboard } from '../../shared/utilities/messages'
86
import { telemetry } from '../../shared/telemetry/telemetry'
7+
import { copyToClipboard } from '../../shared/utilities/messages'
98

10-
export async function copyIdentifier(typeName: string, identifier: string, env = Env.vscode()) {
11-
copyToClipboard(identifier, 'identifier', env)
9+
export async function copyIdentifier(typeName: string, identifier: string) {
10+
copyToClipboard(identifier, 'identifier')
1211
telemetry.dynamicresource_copyIdentifier.emit({ resourceType: typeName })
1312
}

src/ecr/commands/copyRepositoryUri.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { Env } from '../../shared/vscode/env'
76
import { copyToClipboard } from '../../shared/utilities/messages'
87
import { EcrRepositoryNode } from '../explorer/ecrRepositoryNode'
98
import { telemetry } from '../../shared/telemetry/telemetry'
109

11-
export async function copyRepositoryUri(node: EcrRepositoryNode, env = Env.vscode()): Promise<void> {
10+
export async function copyRepositoryUri(node: EcrRepositoryNode): Promise<void> {
1211
const uri = node.repository.repositoryUri
13-
await copyToClipboard(uri, 'URI', env)
12+
await copyToClipboard(uri, 'URI')
1413
telemetry.ecr_copyRepositoryUri.emit()
1514
}

src/ecr/commands/copyTagUri.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
*/
55

66
import { EcrTagNode } from '../explorer/ecrTagNode'
7-
import { Env } from '../../shared/vscode/env'
87
import { copyToClipboard } from '../../shared/utilities/messages'
98
import { telemetry } from '../../shared/telemetry/telemetry'
109

11-
export async function copyTagUri(node: EcrTagNode, env = Env.vscode()): Promise<void> {
10+
export async function copyTagUri(node: EcrTagNode): Promise<void> {
1211
const uri = `${node.repository.repositoryUri}:${node.tag}`
13-
await copyToClipboard(uri, 'URI', env)
12+
await copyToClipboard(uri, 'URI')
1413
telemetry.ecr_copyTagUri.emit()
1514
}

src/eventSchemas/models/schemaCodeGenUtils.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,20 @@ class CodeGenPackageBuilder {
6565

6666
public append(segment: string): CodeGenPackageBuilder {
6767
if (this.builder.length > 0) {
68-
this.builder = this.builder.concat(IdentifierFormatter.packageSeparator)
68+
this.builder = this.builder.concat(packageSeparator)
6969
}
70-
this.builder = this.builder.concat(IdentifierFormatter.toValidIdentifier(segment.toLowerCase()))
70+
this.builder = this.builder.concat(toValidIdentifier(segment.toLowerCase()))
7171

7272
return this
7373
}
7474
}
7575

76-
export namespace IdentifierFormatter {
77-
export const packageSeparator = '.'
78-
const potentialPackageSeparator = '@'
79-
const notValidIdentifierRegex = new RegExp(`[^a-zA-Z0-9_${potentialPackageSeparator}]`, 'g')
80-
const potentialPackageSeparatorRegex = new RegExp(potentialPackageSeparator, 'g')
81-
const underscore = '_'
76+
export const packageSeparator = '.'
77+
const potentialPackageSeparator = '@'
78+
const notValidIdentifierRegex = new RegExp(`[^a-zA-Z0-9_${potentialPackageSeparator}]`, 'g')
79+
const potentialPackageSeparatorRegex = new RegExp(potentialPackageSeparator, 'g')
80+
const underscore = '_'
8281

83-
export function toValidIdentifier(name: string): string {
84-
return name
85-
.replace(notValidIdentifierRegex, underscore)
86-
.replace(potentialPackageSeparatorRegex, packageSeparator)
87-
}
82+
export function toValidIdentifier(name: string): string {
83+
return name.replace(notValidIdentifierRegex, underscore).replace(potentialPackageSeparatorRegex, packageSeparator)
8884
}

src/eventSchemas/templates/schemasAppTemplateUtils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import _ = require('lodash')
7-
import { IdentifierFormatter, SchemaCodeGenUtils } from '../../eventSchemas/models/schemaCodeGenUtils'
7+
import { SchemaCodeGenUtils, toValidIdentifier } from '../../eventSchemas/models/schemaCodeGenUtils'
88
import { SchemaClient } from '../../shared/clients/schemaClient'
99

1010
const xAmazonEventSource = 'x-amazon-events-source'
@@ -92,13 +92,13 @@ function buildRootSchemaEventName(schemaNode: any, awsEventNode: any) {
9292
if (_.isString(refValue) && refValue.includes(componentsSchemasPath)) {
9393
const awsEventDetailRef = refValue.split(componentsSchemasPath).pop()
9494
if (!_.isEmpty(awsEventDetailRef)) {
95-
return IdentifierFormatter.toValidIdentifier(awsEventDetailRef!)
95+
return toValidIdentifier(awsEventDetailRef!)
9696
}
9797
}
9898

9999
const schemaRoots = _.keysIn(_.get(schemaNode, components.concat('.', schemas)))
100100
if (!_.isEmpty(schemaRoots)) {
101-
return IdentifierFormatter.toValidIdentifier(schemaRoots[0])
101+
return toValidIdentifier(schemaRoots[0])
102102
}
103103

104104
return undefined

src/iot/commands/copyEndpoint.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import { localize } from '../../shared/utilities/vsCodeUtils'
77
import { IotNode } from '../explorer/iotNodes'
88
import { showViewLogsMessage } from '../../shared/utilities/messages'
9-
import { Env } from '../../shared/vscode/env'
109
import { copyToClipboard } from '../../shared/utilities/messages'
1110
import { getLogger } from '../../shared/logger'
1211

@@ -15,7 +14,7 @@ import { getLogger } from '../../shared/logger'
1514
*
1615
* Note that the path does not contain the bucket name or a leading slash.
1716
*/
18-
export async function copyEndpointCommand(node: IotNode, env = Env.vscode()): Promise<void> {
17+
export async function copyEndpointCommand(node: IotNode): Promise<void> {
1918
getLogger().debug('CopyPath called for %O', node)
2019

2120
let endpoint: string
@@ -27,5 +26,5 @@ export async function copyEndpointCommand(node: IotNode, env = Env.vscode()): Pr
2726
return
2827
}
2928

30-
copyToClipboard(endpoint, 'URL', env)
29+
copyToClipboard(endpoint, 'URL')
3130
}

src/iot/explorer/iotCertFolderNode.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import { localize } from '../../shared/utilities/vsCodeUtils'
1313
import { ChildNodeLoader } from '../../awsexplorer/childNodeLoader'
1414
import { ChildNodePage } from '../../awsexplorer/childNodeLoader'
1515
import { inspect } from 'util'
16-
import { Workspace } from '../../shared/vscode/workspace'
1716
import { getLogger } from '../../shared/logger'
1817
import { IotCertWithPoliciesNode } from './iotCertificateNode'
1918
import { IotNode } from './iotNodes'
2019
import { Commands } from '../../shared/vscode/commands'
20+
import { Settings } from '../../shared/settings'
21+
import { ClassToInterfaceType } from '../../shared/utilities/tsUtils'
2122

2223
/**
2324
* Represents the group of all IoT Certificates.
@@ -28,7 +29,7 @@ export class IotCertsFolderNode extends AWSTreeNodeBase implements LoadMoreNode
2829
public constructor(
2930
public readonly iot: IotClient,
3031
public readonly parent: IotNode,
31-
private readonly workspace = Workspace.vscode()
32+
protected readonly settings: ClassToInterfaceType<Settings> = Settings.instance
3233
) {
3334
super('Certificates', vscode.TreeItemCollapsibleState.Collapsed)
3435
this.tooltip = 'IoT Certificates'
@@ -99,6 +100,6 @@ export class IotCertsFolderNode extends AWSTreeNodeBase implements LoadMoreNode
99100
}
100101

101102
private getMaxItemsPerPage(): number | undefined {
102-
return this.workspace.getConfiguration('aws').get<number>('iot.maxItemsPerPage')
103+
return this.settings.getSection('aws').get<number>('iot.maxItemsPerPage')
103104
}
104105
}

0 commit comments

Comments
 (0)