Skip to content

Commit 5aef4a6

Browse files
committed
fix: use === in the comparisons + remove excess null checks (wip)
1 parent 5c30200 commit 5aef4a6

11 files changed

+42
-44
lines changed

lib/adapters/autocomplete-adapter.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ class PossiblyResolvedCompletionItem {
5959
/** Public: Adapts the language server protocol "textDocument/completion" to the Atom AutoComplete+ package. */
6060
export default class AutocompleteAdapter {
6161
public static canAdapt(serverCapabilities: ServerCapabilities): boolean {
62-
return serverCapabilities.completionProvider != null
62+
return serverCapabilities.completionProvider !== undefined
6363
}
6464

6565
public static canResolve(serverCapabilities: ServerCapabilities): boolean {
6666
return (
67-
serverCapabilities.completionProvider != null && serverCapabilities.completionProvider.resolveProvider === true
67+
serverCapabilities.completionProvider !== undefined && serverCapabilities.completionProvider.resolveProvider === true
6868
)
6969
}
7070

@@ -89,7 +89,7 @@ export default class AutocompleteAdapter {
8989
shouldReplace: ShouldReplace = false
9090
): Promise<ac.AnySuggestion[]> {
9191
const triggerChars =
92-
server.capabilities.completionProvider != null
92+
server.capabilities.completionProvider !== undefined
9393
? server.capabilities.completionProvider.triggerCharacters || []
9494
: []
9595

@@ -233,11 +233,11 @@ export default class AutocompleteAdapter {
233233
const cache = this._suggestionCache.get(server)
234234
if (cache) {
235235
const possiblyResolvedCompletionItem = cache.suggestionMap.get(suggestion)
236-
if (possiblyResolvedCompletionItem != null && possiblyResolvedCompletionItem.isResolved === false) {
236+
if (possiblyResolvedCompletionItem !== undefined && possiblyResolvedCompletionItem.isResolved === false) {
237237
const resolvedCompletionItem = await server.connection.completionItemResolve(
238238
possiblyResolvedCompletionItem.completionItem
239239
)
240-
if (resolvedCompletionItem != null) {
240+
if (resolvedCompletionItem !== null) {
241241
AutocompleteAdapter.resolveSuggestion(resolvedCompletionItem, suggestion, request, onDidConvertCompletionItem)
242242
possiblyResolvedCompletionItem.isResolved = true
243243
}
@@ -254,7 +254,7 @@ export default class AutocompleteAdapter {
254254
): void {
255255
// only the `documentation` and `detail` properties may change when resolving
256256
AutocompleteAdapter.applyDetailsToSuggestion(resolvedCompletionItem, suggestion)
257-
if (onDidConvertCompletionItem != null) {
257+
if (onDidConvertCompletionItem !== undefined) {
258258
onDidConvertCompletionItem(resolvedCompletionItem, suggestion as ac.AnySuggestion, request)
259259
}
260260
}
@@ -417,7 +417,7 @@ export default class AutocompleteAdapter {
417417
shouldReplace
418418
)
419419
AutocompleteAdapter.applySnippetToSuggestion(item, suggestion as SnippetSuggestion)
420-
if (onDidConvertCompletionItem != null) {
420+
if (onDidConvertCompletionItem !== undefined) {
421421
onDidConvertCompletionItem(item, suggestion as ac.AnySuggestion, request)
422422
}
423423

@@ -448,7 +448,7 @@ export default class AutocompleteAdapter {
448448
suggestion.description = item.documentation
449449
}
450450

451-
if (item.documentation != null && typeof item.documentation === "object") {
451+
if (item.documentation !== undefined && typeof item.documentation === "object") {
452452
// Newer format specifies the kind of documentation, assign appropriately
453453
if (item.documentation.kind === "markdown") {
454454
suggestion.descriptionMarkdown = item.documentation.value

lib/adapters/code-action-adapter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class CodeActionAdapter {
4040
range: Range,
4141
diagnostics: atomIde.Diagnostic[]
4242
): Promise<atomIde.CodeAction[]> {
43-
if (linterAdapter == null) {
43+
if (linterAdapter === undefined) {
4444
return []
4545
}
4646
assert(serverCapabilities.codeActionProvider, "Must have the textDocument/codeAction capability")
@@ -100,9 +100,9 @@ export default class CodeActionAdapter {
100100
// Until the Linter API provides a place to store the code,
101101
// there's no real way for the code actions API to give it back to us.
102102
const converted = Convert.atomIdeDiagnosticToLSDiagnostic(diagnostic)
103-
if (diagnostic.range != null && diagnostic.text != null) {
103+
if (diagnostic.text !== undefined) {
104104
const code = linterAdapter.getDiagnosticCode(editor, diagnostic.range, diagnostic.text)
105-
if (code != null) {
105+
if (code !== null) {
106106
converted.code = code
107107
}
108108
}

lib/adapters/command-execution-adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default class CommandExecutionAdapter {
77
private static commandsCustomCallbacks = new Map<string, CommandCustomCallbackFunction>()
88

99
public static canAdapt(serverCapabilities: ServerCapabilities): boolean {
10-
return serverCapabilities.executeCommandProvider != null
10+
return serverCapabilities.executeCommandProvider !== undefined
1111
}
1212

1313
public static registerCustomCallbackForCommand(command: string, callback: CommandCustomCallbackFunction): void {

lib/adapters/datatip-adapter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ export default class DatatipAdapter {
3333
const documentPositionParams = Convert.editorToTextDocumentPositionParams(editor, point)
3434

3535
const hover = await connection.hover(documentPositionParams)
36-
if (hover == null || DatatipAdapter.isEmptyHover(hover)) {
36+
if (hover === null || DatatipAdapter.isEmptyHover(hover)) {
3737
return null
3838
}
3939

40-
const range = hover.range == null ? Utils.getWordAtPosition(editor, point) : Convert.lsRangeToAtomRange(hover.range)
40+
const range = hover.range === undefined ? Utils.getWordAtPosition(editor, point) : Convert.lsRangeToAtomRange(hover.range)
4141

4242
const markedStrings = (Array.isArray(hover.contents) ? hover.contents : [hover.contents]).map((str) =>
4343
DatatipAdapter.convertMarkedString(editor, str)
@@ -47,6 +47,7 @@ export default class DatatipAdapter {
4747
}
4848

4949
private static isEmptyHover(hover: Hover): boolean {
50+
// TODO hover.contents is never null!
5051
return (
5152
hover.contents == null ||
5253
(typeof hover.contents === "string" && hover.contents.length === 0) ||

lib/adapters/definition-adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ export default class DefinitionAdapter {
4343
const definitionLocations = DefinitionAdapter.normalizeLocations(
4444
await connection.gotoDefinition(documentPositionParams)
4545
)
46-
if (definitionLocations == null || definitionLocations.length === 0) {
46+
if (definitionLocations === null || definitionLocations.length === 0) {
4747
return null
4848
}
4949

5050
let queryRange
5151
if (serverCapabilities.documentHighlightProvider) {
5252
const highlights = await connection.documentHighlight(documentPositionParams)
53-
if (highlights != null && highlights.length > 0) {
53+
if (highlights.length > 0) {
5454
queryRange = highlights.map((h) => Convert.lsRangeToAtomRange(h.range))
5555
}
5656
}

lib/adapters/document-sync-adapter.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ export default class DocumentSyncAdapter {
103103

104104
private _handleGrammarChange(editor: TextEditor): void {
105105
const sync = this._editors.get(editor)
106-
if (sync != null && !this._editorSelector(editor)) {
106+
if (sync !== undefined && !this._editorSelector(editor)) {
107107
this._editors.delete(editor)
108108
this._disposable.remove(sync)
109109
sync.didClose()
110110
sync.dispose()
111-
} else if (sync == null && this._editorSelector(editor)) {
111+
} else if (sync === undefined && this._editorSelector(editor)) {
112112
this._handleNewEditor(editor)
113113
}
114114
}
@@ -160,10 +160,11 @@ export class TextEditorSyncAdapter {
160160
private _versions: Map<string, number>,
161161
private _reportBusyWhile: Utils.ReportBusyWhile
162162
) {
163+
// TODO atom.project.onDidChangeFiles is never null
163164
this._fakeDidChangeWatchedFiles = atom.project.onDidChangeFiles == null
164165

165166
const changeTracking = this.setupChangeTracking(_documentSync)
166-
if (changeTracking != null) {
167+
if (changeTracking !== null) {
167168
this._disposable.add(changeTracking)
168169
}
169170

@@ -279,7 +280,7 @@ export class TextEditorSyncAdapter {
279280

280281
private _bumpVersion(): void {
281282
const filePath = this._editor.getPath()
282-
if (filePath == null) {
283+
if (filePath === undefined) {
283284
return
284285
}
285286
this._versions.set(filePath, this._getVersion(filePath) + 1)
@@ -291,7 +292,7 @@ export class TextEditorSyncAdapter {
291292
*/
292293
private didOpen(): void {
293294
const filePath = this._editor.getPath()
294-
if (filePath == null) {
295+
if (filePath === undefined) {
295296
return
296297
} // Not yet saved
297298

@@ -315,7 +316,7 @@ export class TextEditorSyncAdapter {
315316

316317
/** Called when the {TextEditor} is closed and sends the 'didCloseTextDocument' notification to the connected language server. */
317318
public didClose(): void {
318-
if (this._editor.getPath() == null) {
319+
if (this._editor.getPath() === undefined) {
319320
return
320321
} // Not yet saved
321322

lib/adapters/find-references-adapter.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ export default class FindReferencesAdapter {
3535
projectRoot: string | null
3636
): Promise<atomIde.FindReferencesReturn | null> {
3737
const locations = await connection.findReferences(FindReferencesAdapter.createReferenceParams(editor, point))
38-
if (locations == null) {
39-
return null
40-
}
41-
4238
const references: atomIde.Reference[] = locations.map(FindReferencesAdapter.locationToReference)
4339
return {
4440
type: "data",

lib/adapters/linter-push-v2-adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ export default class LinterPushV2Adapter {
118118
*/
119119
public getDiagnosticCode(editor: atom.TextEditor, range: atom.Range, text: string): DiagnosticCode | null {
120120
const path = editor.getPath()
121-
if (path != null) {
121+
if (path !== undefined) {
122122
const diagnosticCodes = this._diagnosticCodes.get(path)
123-
if (diagnosticCodes != null) {
123+
if (diagnosticCodes !== undefined) {
124124
return diagnosticCodes.get(getCodeKey(range, text)) || null
125125
}
126126
}

lib/adapters/notifications-adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class NotificationsAdapter {
4242
text: a.title,
4343
onDidClick: () => {
4444
resolve(a)
45-
if (notification != null) {
45+
if (notification !== null) {
4646
notification.dismiss()
4747
}
4848
},
@@ -51,7 +51,7 @@ export default class NotificationsAdapter {
5151

5252
const notification = addNotificationForMessage(params.type, params.message, options)
5353

54-
if (notification != null) {
54+
if (notification !== null) {
5555
notification.onDidDismiss(() => {
5656
resolve(null)
5757
})

lib/adapters/outline-view-adapter.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class OutlineViewAdapter {
8686
return symbols.map((symbol) => {
8787
const tree = OutlineViewAdapter.hierarchicalSymbolToOutline(symbol)
8888

89-
if (symbol.children != null) {
89+
if (symbol.children !== undefined) {
9090
tree.children = OutlineViewAdapter.createHierarchicalOutlineTrees(symbol.children)
9191
}
9292

@@ -123,37 +123,37 @@ export default class OutlineViewAdapter {
123123
// Create a map of containers by name with all items that have that name
124124
const containers = allItems.reduce((map, item) => {
125125
const name = item.outline.representativeName
126-
if (name != null) {
126+
if (name !== undefined) {
127127
const container = map.get(name)
128-
if (container == null) {
128+
if (container === undefined) {
129129
map.set(name, [item.outline])
130130
} else {
131131
container.push(item.outline)
132132
}
133133
}
134134
return map
135-
}, new Map())
135+
}, new Map<string, atomIde.OutlineTree[]>())
136136

137137
const roots: atomIde.OutlineTree[] = []
138138

139139
// Put each item within its parent and extract out the roots
140140
for (const item of allItems) {
141141
const containerName = item.containerName
142142
const child = item.outline
143-
if (containerName == null || containerName === "") {
143+
if (containerName === undefined || containerName === "") {
144144
roots.push(item.outline)
145145
} else {
146146
const possibleParents = containers.get(containerName)
147147
let closestParent = OutlineViewAdapter._getClosestParent(possibleParents, child)
148-
if (closestParent == null) {
148+
if (closestParent === null) {
149149
closestParent = {
150150
plainText: containerName,
151151
representativeName: containerName,
152152
startPosition: new Point(0, 0),
153153
children: [child],
154154
}
155155
roots.push(closestParent)
156-
if (possibleParents == null) {
156+
if (possibleParents === undefined) {
157157
containers.set(containerName, [closestParent])
158158
} else {
159159
possibleParents.push(closestParent)
@@ -168,10 +168,10 @@ export default class OutlineViewAdapter {
168168
}
169169

170170
private static _getClosestParent(
171-
candidates: atomIde.OutlineTree[] | null,
171+
candidates: atomIde.OutlineTree[] | undefined,
172172
child: atomIde.OutlineTree
173173
): atomIde.OutlineTree | null {
174-
if (candidates == null || candidates.length === 0) {
174+
if (candidates === undefined || candidates.length === 0) {
175175
return null
176176
}
177177

@@ -186,7 +186,7 @@ export default class OutlineViewAdapter {
186186
if (
187187
parent === undefined ||
188188
parent.startPosition.isLessThanOrEqual(candidate.startPosition) ||
189-
(parent.endPosition != null &&
189+
(parent.endPosition !== undefined &&
190190
candidate.endPosition &&
191191
parent.endPosition.isGreaterThanOrEqual(candidate.endPosition))
192192
) {
@@ -215,7 +215,7 @@ export default class OutlineViewAdapter {
215215
value: symbol.name,
216216
},
217217
],
218-
icon: icon != null ? icon : undefined,
218+
icon: icon !== null ? icon : undefined,
219219
representativeName: symbol.name,
220220
startPosition: Convert.positionToPoint(symbol.selectionRange.start),
221221
endPosition: Convert.positionToPoint(symbol.selectionRange.end),
@@ -238,7 +238,7 @@ export default class OutlineViewAdapter {
238238
value: symbol.name,
239239
},
240240
],
241-
icon: icon != null ? icon : undefined,
241+
icon: icon !== null ? icon : undefined,
242242
representativeName: symbol.name,
243243
startPosition: Convert.positionToPoint(symbol.location.range.start),
244244
endPosition: Convert.positionToPoint(symbol.location.range.end),

lib/adapters/signature-help-adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default class SignatureHelpAdapter {
1919

2020
/** @returns A {Boolean} indicating this adapter can adapt the server based on the given serverCapabilities. */
2121
public static canAdapt(serverCapabilities: ServerCapabilities): boolean {
22-
return serverCapabilities.signatureHelpProvider != null
22+
return serverCapabilities.signatureHelpProvider !== undefined
2323
}
2424

2525
public dispose(): void {
@@ -28,7 +28,7 @@ export default class SignatureHelpAdapter {
2828

2929
public attach(register: atomIde.SignatureHelpRegistry): void {
3030
const { signatureHelpProvider } = this._capabilities
31-
assert(signatureHelpProvider != null)
31+
assert(signatureHelpProvider !== undefined)
3232

3333
let triggerCharacters: Set<string> | undefined
3434
if (signatureHelpProvider && Array.isArray(signatureHelpProvider.triggerCharacters)) {

0 commit comments

Comments
 (0)