Skip to content

Commit 6bc02a1

Browse files
authored
build: eslint "curly" rule #2977
Problem: Control flow statements are inconsistently formatted, e.g. there is some code like this: if (this._timer !== undefined) return Solution: Configure eslint to enforce braces: if (this._timer !== undefined) { return }
1 parent 5adfed8 commit 6bc02a1

21 files changed

+201
-69
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ src/codewhisperer/client/codewhispererclient.d.ts
55
**/*.gen.ts
66
src/testFixtures/workspaceFolder/ts-plain-sam-app/
77
dist/**
8+
types/*.d.ts

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = {
1818
'prettier',
1919
],
2020
rules: {
21+
curly: 2, // Enforce braces on "if"/"for"/etc.
2122
// TODO reenable this rule (by removing this off)
2223
'no-async-promise-executor': 'off',
2324
// TODO reenable this rule (by removing this off)

src/codewhisperer/activation.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ export async function activate(context: ExtContext): Promise<void> {
175175
acceptSuggestion.register(context),
176176
// on text document close.
177177
vscode.workspace.onDidCloseTextDocument(e => {
178-
if (isInlineCompletionEnabled() && e.uri.fsPath !== InlineCompletionService.instance.filePath()) return
178+
if (isInlineCompletionEnabled() && e.uri.fsPath !== InlineCompletionService.instance.filePath()) {
179+
return
180+
}
179181
RecommendationHandler.instance.reportUserDecisionOfCurrentRecommendation(vscode.window.activeTextEditor, -1)
180182
RecommendationHandler.instance.clearRecommendations()
181183
}),
@@ -413,19 +415,22 @@ export async function activate(context: ExtContext): Promise<void> {
413415
* Recommendation navigation
414416
*/
415417
Commands.register('aws.codeWhisperer.nextCodeSuggestion', async () => {
416-
if (vscode.window.activeTextEditor)
418+
if (vscode.window.activeTextEditor) {
417419
InlineCompletion.instance.navigateRecommendation(vscode.window.activeTextEditor, true)
420+
}
418421
}),
419422
Commands.register('aws.codeWhisperer.previousCodeSuggestion', async () => {
420-
if (vscode.window.activeTextEditor)
423+
if (vscode.window.activeTextEditor) {
421424
InlineCompletion.instance.navigateRecommendation(vscode.window.activeTextEditor, false)
425+
}
422426
}),
423427
/**
424428
* Recommendation acceptance
425429
*/
426430
Commands.register('aws.codeWhisperer.acceptCodeSuggestion', async () => {
427-
if (vscode.window.activeTextEditor)
431+
if (vscode.window.activeTextEditor) {
428432
await InlineCompletion.instance.acceptRecommendation(vscode.window.activeTextEditor)
433+
}
429434
})
430435
)
431436
// If the vscode is refreshed we need to maintain the status bar
@@ -540,8 +545,9 @@ export async function shutdown() {
540545
await InlineCompletionService.instance.clearInlineCompletionStates(vscode.window.activeTextEditor)
541546
await HoverConfigUtil.instance.restoreHoverConfig()
542547
} else {
543-
if (vscode.window.activeTextEditor)
548+
if (vscode.window.activeTextEditor) {
544549
await InlineCompletion.instance.resetInlineStates(vscode.window.activeTextEditor)
550+
}
545551
}
546552
CodeWhispererTracker.getTracker().shutdown()
547553
}

src/codewhisperer/commands/invokeRecommendation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export async function invokeRecommendation(
5252
}
5353
KeyStrokeHandler.instance.keyStrokeCount = 0
5454
if (isCloud9()) {
55-
if (RecommendationHandler.instance.isGenerateRecommendationInProgress) return
55+
if (RecommendationHandler.instance.isGenerateRecommendationInProgress) {
56+
return
57+
}
5658
vsCodeState.isIntelliSenseActive = false
5759
RecommendationHandler.instance.isGenerateRecommendationInProgress = true
5860
try {

src/codewhisperer/commands/startSecurityScan.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ export async function startSecurityScan(
131131
* Step 4: Polling mechanism on scan job status
132132
*/
133133
const jobStatus = await pollScanJobStatus(client, scanJob.jobId)
134-
if (jobStatus === 'Failed') throw new Error('Security scan job failed.')
134+
if (jobStatus === 'Failed') {
135+
throw new Error('Security scan job failed.')
136+
}
135137

136138
/**
137139
* Step 5: Process and render scan results

src/codewhisperer/service/diagnosticsProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export function createSecurityDiagnosticCollection() {
6060

6161
export function disposeSecurityDiagnostic(event: vscode.TextDocumentChangeEvent) {
6262
const uri = event.document.uri
63-
if (!securityScanRender.initialized || !securityScanRender.securityDiagnosticCollection?.has(uri)) return
63+
if (!securityScanRender.initialized || !securityScanRender.securityDiagnosticCollection?.has(uri)) {
64+
return
65+
}
6466
const currentSecurityDiagnostics = securityScanRender.securityDiagnosticCollection?.get(uri)
6567
const newSecurityDiagnostics: vscode.Diagnostic[] = []
6668
const changedRange = event.contentChanges[0].range

src/codewhisperer/service/inlineCompletion.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ export class InlineCompletion {
9999
}
100100

101101
async acceptRecommendation(editor: vscode.TextEditor) {
102-
if (vsCodeState.isCodeWhispererEditing) return
102+
if (vsCodeState.isCodeWhispererEditing) {
103+
return
104+
}
103105
vsCodeState.isCodeWhispererEditing = true
104106
await editor
105107
?.edit(
@@ -142,8 +144,12 @@ export class InlineCompletion {
142144
isTypeAheadRejection: boolean = false,
143145
onDidChangeVisibleTextEditors: boolean = false
144146
) {
145-
if (!editor || vsCodeState.isCodeWhispererEditing) return
146-
if (!isTypeAheadRejection && this.items.length === 0) return
147+
if (!editor || vsCodeState.isCodeWhispererEditing) {
148+
return
149+
}
150+
if (!isTypeAheadRejection && this.items.length === 0) {
151+
return
152+
}
147153
vsCodeState.isCodeWhispererEditing = true
148154
ReferenceInlineProvider.instance.removeInlineReference()
149155
if (onDidChangeVisibleTextEditors && this.documentUri && this.documentUri.fsPath.length > 0) {
@@ -261,8 +267,11 @@ export class InlineCompletion {
261267
* When typeAhead is involved we set the position of character with one more character to net let
262268
* last bracket of recommendation to be removed
263269
*/
264-
if (this.isTypeaheadInProgress) this.setRange(new vscode.Range(this._range.start, pos))
265-
else this.setRange(new vscode.Range(this._range.start, editor.selection.active))
270+
if (this.isTypeaheadInProgress) {
271+
this.setRange(new vscode.Range(this._range.start, pos))
272+
} else {
273+
this.setRange(new vscode.Range(this._range.start, editor.selection.active))
274+
}
266275
editor.setDecorations(this.dimDecoration, [this._range])
267276
// cursor position
268277
const position = editor.selection.active
@@ -291,7 +300,9 @@ export class InlineCompletion {
291300
}
292301

293302
async navigateRecommendation(editor: vscode.TextEditor, next: boolean) {
294-
if (!this.items?.length || this.items.length === 1 || vsCodeState.isCodeWhispererEditing || !editor) return
303+
if (!this.items?.length || this.items.length === 1 || vsCodeState.isCodeWhispererEditing || !editor) {
304+
return
305+
}
295306
vsCodeState.isCodeWhispererEditing = true
296307
if (next) {
297308
if (this.position === this.items.length - 1) {
@@ -348,7 +359,9 @@ export class InlineCompletion {
348359
RecommendationHandler.instance.clearRecommendations()
349360
break
350361
}
351-
if (!RecommendationHandler.instance.hasNextToken()) break
362+
if (!RecommendationHandler.instance.hasNextToken()) {
363+
break
364+
}
352365
page++
353366
}
354367
} catch (error) {

src/codewhisperer/service/inlineCompletionService.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ class CodeWhispererInlineCompletionItemProvider implements vscode.InlineCompleti
4040
private getGhostText(prefix: string, suggestion: string): string {
4141
const prefixLines = prefix.split(/\r\n|\r|\n/)
4242
const n = prefixLines.length
43-
if (n <= 1) return suggestion
43+
if (n <= 1) {
44+
return suggestion
45+
}
4446
let count = 1
4547
for (let i = 0; i < suggestion.length; i++) {
4648
if (suggestion[i] === '\n') {
@@ -257,7 +259,9 @@ export class InlineCompletionService {
257259

258260
async tryShowRecommendation() {
259261
const editor = vscode.window.activeTextEditor
260-
if (this.isSuggestionVisible() || editor === undefined) return
262+
if (this.isSuggestionVisible() || editor === undefined) {
263+
return
264+
}
261265
if (
262266
editor.selection.active.isBefore(RecommendationHandler.instance.startPos) ||
263267
editor.document.uri.fsPath !== this.documentUri?.fsPath
@@ -283,7 +287,9 @@ export class InlineCompletionService {
283287
config: ConfigurationEntry,
284288
autoTriggerType?: CodewhispererAutomatedTriggerType
285289
) {
286-
if (vsCodeState.isCodeWhispererEditing || this._isPaginationRunning) return
290+
if (vsCodeState.isCodeWhispererEditing || this._isPaginationRunning) {
291+
return
292+
}
287293
await this.clearInlineCompletionStates(editor)
288294
this.setCodeWhispererStatusBarLoading()
289295
RecommendationHandler.instance.checkAndResetCancellationTokens()
@@ -306,7 +312,9 @@ export class InlineCompletionService {
306312
this.setCodeWhispererStatusBarOk()
307313
return
308314
}
309-
if (!RecommendationHandler.instance.hasNextToken()) break
315+
if (!RecommendationHandler.instance.hasNextToken()) {
316+
break
317+
}
310318
page++
311319
}
312320
} catch (error) {

src/codewhisperer/service/keyStrokeHandler.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,19 @@ export class KeyStrokeHandler {
4949
config: ConfigurationEntry
5050
): Promise<void> {
5151
try {
52-
if (!config.isAutomatedTriggerEnabled) return
52+
if (!config.isAutomatedTriggerEnabled) {
53+
return
54+
}
5355

5456
// Skip when output channel gains focus and invoke
55-
if (editor.document.languageId === 'Log') return
57+
if (editor.document.languageId === 'Log') {
58+
return
59+
}
5660

5761
// Pause automated trigger when typed input matches recommendation prefix for inline suggestion
58-
if (InlineCompletion.instance.isTypeaheadInProgress) return
62+
if (InlineCompletion.instance.isTypeaheadInProgress) {
63+
return
64+
}
5965

6066
// Skip Cloud9 IntelliSense acceptance event
6167
if (
@@ -124,7 +130,9 @@ export class KeyStrokeHandler {
124130
if (editor) {
125131
this.keyStrokeCount = 0
126132
if (isCloud9()) {
127-
if (RecommendationHandler.instance.isGenerateRecommendationInProgress) return
133+
if (RecommendationHandler.instance.isGenerateRecommendationInProgress) {
134+
return
135+
}
128136
vsCodeState.isIntelliSenseActive = false
129137
RecommendationHandler.instance.isGenerateRecommendationInProgress = true
130138
try {
@@ -179,7 +187,9 @@ export abstract class DocumentChangedType {
179187

180188
// Enter key should always start with ONE '\n' or '\r\n' and potentially following spaces due to IDE reformat
181189
protected isEnterKey(str: string): boolean {
182-
if (str.length === 0) return false
190+
if (str.length === 0) {
191+
return false
192+
}
183193
return (
184194
(str.startsWith('\r\n') && str.substring(2).trim() === '') ||
185195
(str[0] === '\n' && str.substring(1).trim() === '')
@@ -202,12 +212,18 @@ export abstract class DocumentChangedType {
202212
protected isSingleLine(str: string): boolean {
203213
let newLineCounts = 0
204214
for (const ch of str) {
205-
if (ch === '\n') newLineCounts += 1
215+
if (ch === '\n') {
216+
newLineCounts += 1
217+
}
206218
}
207219

208220
// since pressing Enter key possibly will generate string like '\n ' due to indention
209-
if (this.isEnterKey(str)) return true
210-
if (newLineCounts >= 1) return false
221+
if (this.isEnterKey(str)) {
222+
return true
223+
}
224+
if (newLineCounts >= 1) {
225+
return false
226+
}
211227
return true
212228
}
213229
}

src/codewhisperer/service/recommendationHandler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ export class RecommendationHandler {
155155
startTime = performance.now()
156156
this.lastInvocationTime = startTime
157157
// set start pos for non pagination call or first pagination call
158-
if (!pagination || (pagination && page === 0)) this.startPos = editor.selection.active
158+
if (!pagination || (pagination && page === 0)) {
159+
this.startPos = editor.selection.active
160+
}
159161

160162
/**
161163
* Validate request

0 commit comments

Comments
 (0)