Skip to content

Commit af5804e

Browse files
committed
fix: use === in the comparisons + remove excess null checks (wip)
1 parent 4947c9a commit af5804e

11 files changed

+44
-49
lines changed

lib/adapters/autocomplete-adapter.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ class PossiblyResolvedCompletionItem {
5252
*/
5353
export default class AutocompleteAdapter {
5454
public static canAdapt(serverCapabilities: ServerCapabilities): boolean {
55-
return serverCapabilities.completionProvider != null
55+
return serverCapabilities.completionProvider !== undefined
5656
}
5757

5858
public static canResolve(serverCapabilities: ServerCapabilities): boolean {
5959
return (
60-
serverCapabilities.completionProvider != null && serverCapabilities.completionProvider.resolveProvider === true
60+
serverCapabilities.completionProvider !== undefined && serverCapabilities.completionProvider.resolveProvider === true
6161
)
6262
}
6363

@@ -83,7 +83,7 @@ export default class AutocompleteAdapter {
8383
minimumWordLength?: number
8484
): Promise<ac.AnySuggestion[]> {
8585
const triggerChars =
86-
server.capabilities.completionProvider != null
86+
server.capabilities.completionProvider !== undefined
8787
? server.capabilities.completionProvider.triggerCharacters || []
8888
: []
8989

@@ -214,11 +214,11 @@ export default class AutocompleteAdapter {
214214
const cache = this._suggestionCache.get(server)
215215
if (cache) {
216216
const possiblyResolvedCompletionItem = cache.suggestionMap.get(suggestion)
217-
if (possiblyResolvedCompletionItem != null && possiblyResolvedCompletionItem.isResolved === false) {
217+
if (possiblyResolvedCompletionItem !== undefined && possiblyResolvedCompletionItem.isResolved === false) {
218218
const resolvedCompletionItem = await server.connection.completionItemResolve(
219219
possiblyResolvedCompletionItem.completionItem
220220
)
221-
if (resolvedCompletionItem != null) {
221+
if (resolvedCompletionItem !== null) {
222222
AutocompleteAdapter.resolveSuggestion(resolvedCompletionItem, suggestion, request, onDidConvertCompletionItem)
223223
possiblyResolvedCompletionItem.isResolved = true
224224
}
@@ -235,7 +235,7 @@ export default class AutocompleteAdapter {
235235
): void {
236236
// only the `documentation` and `detail` properties may change when resolving
237237
AutocompleteAdapter.applyDetailsToSuggestion(resolvedCompletionItem, suggestion)
238-
if (onDidConvertCompletionItem != null) {
238+
if (onDidConvertCompletionItem !== undefined) {
239239
onDidConvertCompletionItem(resolvedCompletionItem, suggestion as ac.AnySuggestion, request)
240240
}
241241
}
@@ -394,7 +394,7 @@ export default class AutocompleteAdapter {
394394
suggestion as TextSuggestion
395395
)
396396
AutocompleteAdapter.applySnippetToSuggestion(item, suggestion as SnippetSuggestion)
397-
if (onDidConvertCompletionItem != null) {
397+
if (onDidConvertCompletionItem !== undefined) {
398398
onDidConvertCompletionItem(item, suggestion as ac.AnySuggestion, request)
399399
}
400400

@@ -425,7 +425,7 @@ export default class AutocompleteAdapter {
425425
suggestion.description = item.documentation
426426
}
427427

428-
if (item.documentation != null && typeof item.documentation === "object") {
428+
if (item.documentation !== undefined && typeof item.documentation === "object") {
429429
// Newer format specifies the kind of documentation, assign appropriately
430430
if (item.documentation.kind === "markdown") {
431431
suggestion.descriptionMarkdown = item.documentation.value
@@ -469,7 +469,7 @@ export default class AutocompleteAdapter {
469469
*/
470470
public static applySnippetToSuggestion(item: CompletionItem, suggestion: SnippetSuggestion): void {
471471
if (item.insertTextFormat === InsertTextFormat.Snippet) {
472-
suggestion.snippet = item.textEdit != null ? item.textEdit.newText : item.insertText || ""
472+
suggestion.snippet = item.textEdit !== undefined ? item.textEdit.newText : item.insertText || ""
473473
}
474474
}
475475

lib/adapters/code-action-adapter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default class CodeActionAdapter {
4343
range: Range,
4444
diagnostics: atomIde.Diagnostic[]
4545
): Promise<atomIde.CodeAction[]> {
46-
if (linterAdapter == null) {
46+
if (linterAdapter === undefined) {
4747
return []
4848
}
4949
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
@@ -39,11 +39,11 @@ export default class DatatipAdapter {
3939
const documentPositionParams = Convert.editorToTextDocumentPositionParams(editor, point)
4040

4141
const hover = await connection.hover(documentPositionParams)
42-
if (hover == null || DatatipAdapter.isEmptyHover(hover)) {
42+
if (hover === null || DatatipAdapter.isEmptyHover(hover)) {
4343
return null
4444
}
4545

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

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

5555
private static isEmptyHover(hover: Hover): boolean {
56+
// TODO hover.contents is never null!
5657
return (
5758
hover.contents == null ||
5859
(typeof hover.contents === "string" && hover.contents.length === 0) ||

lib/adapters/definition-adapter.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ export default class DefinitionAdapter {
4646
const definitionLocations = DefinitionAdapter.normalizeLocations(
4747
await connection.gotoDefinition(documentPositionParams)
4848
)
49-
if (definitionLocations == null || definitionLocations.length === 0) {
49+
if (definitionLocations === null || definitionLocations.length === 0) {
5050
return null
5151
}
5252

5353
let queryRange
5454
if (serverCapabilities.documentHighlightProvider) {
5555
const highlights = await connection.documentHighlight(documentPositionParams)
56-
if (highlights != null && highlights.length > 0) {
56+
if (highlights.length > 0) {
5757
queryRange = highlights.map((h) => Convert.lsRangeToAtomRange(h.range))
5858
}
5959
}
@@ -72,10 +72,7 @@ export default class DefinitionAdapter {
7272
* @returns An {Array} of {Location}s or {null} if the locationResult was null.
7373
*/
7474
public static normalizeLocations(locationResult: Location | Location[]): Location[] | null {
75-
if (locationResult == null) {
76-
return null
77-
}
78-
return (Array.isArray(locationResult) ? locationResult : [locationResult]).filter((d) => d.range.start != null)
75+
return (Array.isArray(locationResult) ? locationResult : [locationResult]).filter((d) => d.range.start != null) // TODO d.range.start is never null!
7976
}
8077

8178
/**

lib/adapters/document-sync-adapter.ts

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

106106
private _handleGrammarChange(editor: TextEditor): void {
107107
const sync = this._editors.get(editor)
108-
if (sync != null && !this._editorSelector(editor)) {
108+
if (sync !== undefined && !this._editorSelector(editor)) {
109109
this._editors.delete(editor)
110110
this._disposable.remove(sync)
111111
sync.didClose()
112112
sync.dispose()
113-
} else if (sync == null && this._editorSelector(editor)) {
113+
} else if (sync === undefined && this._editorSelector(editor)) {
114114
this._handleNewEditor(editor)
115115
}
116116
}
@@ -162,10 +162,11 @@ export class TextEditorSyncAdapter {
162162
private _versions: Map<string, number>,
163163
private _reportBusyWhile: Utils.ReportBusyWhile
164164
) {
165+
// TODO atom.project.onDidChangeFiles is never null
165166
this._fakeDidChangeWatchedFiles = atom.project.onDidChangeFiles == null
166167

167168
const changeTracking = this.setupChangeTracking(_documentSync)
168-
if (changeTracking != null) {
169+
if (changeTracking !== null) {
169170
this._disposable.add(changeTracking)
170171
}
171172

@@ -293,7 +294,7 @@ export class TextEditorSyncAdapter {
293294

294295
private _bumpVersion(): void {
295296
const filePath = this._editor.getPath()
296-
if (filePath == null) {
297+
if (filePath === undefined) {
297298
return
298299
}
299300
this._versions.set(filePath, this._getVersion(filePath) + 1)
@@ -305,7 +306,7 @@ export class TextEditorSyncAdapter {
305306
*/
306307
private didOpen(): void {
307308
const filePath = this._editor.getPath()
308-
if (filePath == null) {
309+
if (filePath === undefined) {
309310
return
310311
} // Not yet saved
311312

@@ -332,7 +333,7 @@ export class TextEditorSyncAdapter {
332333
* the connected language server.
333334
*/
334335
public didClose(): void {
335-
if (this._editor.getPath() == null) {
336+
if (this._editor.getPath() === undefined) {
336337
return
337338
} // Not yet saved
338339

lib/adapters/find-references-adapter.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ export default class FindReferencesAdapter {
3838
projectRoot: string | null
3939
): Promise<atomIde.FindReferencesReturn | null> {
4040
const locations = await connection.findReferences(FindReferencesAdapter.createReferenceParams(editor, point))
41-
if (locations == null) {
42-
return null
43-
}
44-
4541
const references: atomIde.Reference[] = locations.map(FindReferencesAdapter.locationToReference)
4642
return {
4743
type: "data",

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

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

lib/adapters/notifications-adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class NotificationsAdapter {
4646
text: a.title,
4747
onDidClick: () => {
4848
resolve(a)
49-
if (notification != null) {
49+
if (notification !== null) {
5050
notification.dismiss()
5151
}
5252
},
@@ -55,7 +55,7 @@ export default class NotificationsAdapter {
5555

5656
const notification = addNotificationForMessage(params.type, params.message, options)
5757

58-
if (notification != null) {
58+
if (notification !== null) {
5959
notification.onDidDismiss(() => {
6060
resolve(null)
6161
})

lib/adapters/outline-view-adapter.ts

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

96-
if (symbol.children != null) {
96+
if (symbol.children !== undefined) {
9797
tree.children = OutlineViewAdapter.createHierarchicalOutlineTrees(symbol.children)
9898
}
9999

@@ -129,37 +129,37 @@ export default class OutlineViewAdapter {
129129
// Create a map of containers by name with all items that have that name
130130
const containers = allItems.reduce((map, item) => {
131131
const name = item.outline.representativeName
132-
if (name != null) {
132+
if (name !== undefined) {
133133
const container = map.get(name)
134-
if (container == null) {
134+
if (container === undefined) {
135135
map.set(name, [item.outline])
136136
} else {
137137
container.push(item.outline)
138138
}
139139
}
140140
return map
141-
}, new Map())
141+
}, new Map<string, atomIde.OutlineTree[]>())
142142

143143
const roots: atomIde.OutlineTree[] = []
144144

145145
// Put each item within its parent and extract out the roots
146146
for (const item of allItems) {
147147
const containerName = item.containerName
148148
const child = item.outline
149-
if (containerName == null || containerName === "") {
149+
if (containerName === undefined || containerName === "") {
150150
roots.push(item.outline)
151151
} else {
152152
const possibleParents = containers.get(containerName)
153153
let closestParent = OutlineViewAdapter._getClosestParent(possibleParents, child)
154-
if (closestParent == null) {
154+
if (closestParent === null) {
155155
closestParent = {
156156
plainText: containerName,
157157
representativeName: containerName,
158158
startPosition: new Point(0, 0),
159159
children: [child],
160160
}
161161
roots.push(closestParent)
162-
if (possibleParents == null) {
162+
if (possibleParents === undefined) {
163163
containers.set(containerName, [closestParent])
164164
} else {
165165
possibleParents.push(closestParent)
@@ -174,10 +174,10 @@ export default class OutlineViewAdapter {
174174
}
175175

176176
private static _getClosestParent(
177-
candidates: atomIde.OutlineTree[] | null,
177+
candidates: atomIde.OutlineTree[] | undefined,
178178
child: atomIde.OutlineTree
179179
): atomIde.OutlineTree | null {
180-
if (candidates == null || candidates.length === 0) {
180+
if (candidates === undefined || candidates.length === 0) {
181181
return null
182182
}
183183

@@ -192,7 +192,7 @@ export default class OutlineViewAdapter {
192192
if (
193193
parent === undefined ||
194194
parent.startPosition.isLessThanOrEqual(candidate.startPosition) ||
195-
(parent.endPosition != null &&
195+
(parent.endPosition !== undefined &&
196196
candidate.endPosition &&
197197
parent.endPosition.isGreaterThanOrEqual(candidate.endPosition))
198198
) {
@@ -222,7 +222,7 @@ export default class OutlineViewAdapter {
222222
value: symbol.name,
223223
},
224224
],
225-
icon: icon != null ? icon : undefined,
225+
icon: icon !== null ? icon : undefined,
226226
representativeName: symbol.name,
227227
startPosition: Convert.positionToPoint(symbol.selectionRange.start),
228228
endPosition: Convert.positionToPoint(symbol.selectionRange.end),
@@ -246,7 +246,7 @@ export default class OutlineViewAdapter {
246246
value: symbol.name,
247247
},
248248
],
249-
icon: icon != null ? icon : undefined,
249+
icon: icon !== null ? icon : undefined,
250250
representativeName: symbol.name,
251251
startPosition: Convert.positionToPoint(symbol.location.range.start),
252252
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
@@ -22,7 +22,7 @@ export default class SignatureHelpAdapter {
2222
* given serverCapabilities.
2323
*/
2424
public static canAdapt(serverCapabilities: ServerCapabilities): boolean {
25-
return serverCapabilities.signatureHelpProvider != null
25+
return serverCapabilities.signatureHelpProvider !== undefined
2626
}
2727

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

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

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

0 commit comments

Comments
 (0)