@@ -23,7 +23,7 @@ export default class CodeFormatManager {
23
23
_fileProviders : ProviderRegistry < FileCodeFormatProvider >
24
24
_onTypeProviders : ProviderRegistry < OnTypeCodeFormatProvider >
25
25
_onSaveProviders : ProviderRegistry < OnSaveCodeFormatProvider >
26
- _busySignalService : BusySignalService | undefined | null
26
+ _busySignalService : BusySignalService | undefined
27
27
28
28
constructor ( ) {
29
29
/**
@@ -34,9 +34,6 @@ export default class CodeFormatManager {
34
34
// Events from the explicit Atom command.
35
35
atom . commands . add ( "atom-text-editor" , "code-format:format-code" , async ( event ) => {
36
36
const editorElement = event . currentTarget
37
- if ( ! editorElement ) {
38
- return
39
- }
40
37
const editor = editorElement . getModel ( )
41
38
// Make sure we halt everything when the editor gets destroyed.
42
39
const edits = await this . _formatCodeInTextEditor ( editor )
@@ -85,7 +82,7 @@ export default class CodeFormatManager {
85
82
// Return the text edits used to format code in the editor specified.
86
83
async _formatCodeInTextEditor ( editor : TextEditor , range ?: Range ) : Promise < Array < TextEdit > > {
87
84
const buffer = editor . getBuffer ( )
88
- const selectionRange = range || editor . getSelectedBufferRange ( )
85
+ const selectionRange = range ?? editor . getSelectedBufferRange ( )
89
86
const { start : selectionStart , end : selectionEnd } = selectionRange
90
87
let formatRange : Range
91
88
if ( selectionRange . isEmpty ( ) ) {
@@ -216,9 +213,9 @@ export default class CodeFormatManager {
216
213
217
214
_reportBusy < T > ( editor : TextEditor , promise : Promise < T > , revealTooltip : boolean = true ) : Promise < T > {
218
215
const busySignalService = this . _busySignalService
219
- if ( busySignalService != null ) {
216
+ if ( busySignalService !== undefined ) {
220
217
const path = editor . getPath ( )
221
- const displayPath = path != null ? nuclideUri . basename ( path ) : "<untitled>"
218
+ const displayPath = path !== undefined ? nuclideUri . basename ( path ) : "<untitled>"
222
219
return busySignalService . reportBusyWhile ( `Formatting code in ${ displayPath } ` , ( ) => promise , { revealTooltip } )
223
220
}
224
221
return promise
@@ -243,7 +240,7 @@ export default class CodeFormatManager {
243
240
consumeBusySignal ( busySignalService : BusySignalService ) : Disposable {
244
241
this . _busySignalService = busySignalService
245
242
return new Disposable ( ( ) => {
246
- this . _busySignalService = null
243
+ this . _busySignalService = undefined
247
244
} )
248
245
}
249
246
@@ -271,7 +268,7 @@ function shouldFormatOnType(event: TextChange): boolean {
271
268
// We either just deleted something or replaced a selection. For the time
272
269
// being, we're not going to issue a reformat in that case.
273
270
return false
274
- } else if ( event . oldText === "" && event . newText === "" ) {
271
+ } else if ( event . newText === "" ) {
275
272
// Not sure what happened here; why did we get an event in this case? Bail
276
273
// for safety.
277
274
return false
@@ -286,10 +283,10 @@ function shouldFormatOnType(event: TextChange): boolean {
286
283
* assume that any pair of brackets that bracket-matcher recognizes was a pair matched by the package.
287
284
*/
288
285
function isBracketPair ( typedText : string ) : boolean {
289
- if ( atom . packages . getActivePackage ( "bracket-matcher" ) == null ) {
286
+ if ( atom . packages . getActivePackage ( "bracket-matcher" ) === undefined ) {
290
287
return false
291
288
}
292
- const validBracketPairs : Array < string > = atom . config . get ( "bracket-matcher.autocompleteCharacters" ) as any
289
+ const validBracketPairs = atom . config . get ( "bracket-matcher.autocompleteCharacters" ) as Array < string >
293
290
return validBracketPairs . includes ( typedText )
294
291
}
295
292
0 commit comments