Skip to content

Commit b2e2bdf

Browse files
committed
fix: remove redundant checks
1 parent 7614553 commit b2e2bdf

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/CodeFormatManager.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class CodeFormatManager {
2323
_fileProviders: ProviderRegistry<FileCodeFormatProvider>
2424
_onTypeProviders: ProviderRegistry<OnTypeCodeFormatProvider>
2525
_onSaveProviders: ProviderRegistry<OnSaveCodeFormatProvider>
26-
_busySignalService: BusySignalService | undefined | null
26+
_busySignalService: BusySignalService | undefined
2727

2828
constructor() {
2929
/**
@@ -34,9 +34,6 @@ export default class CodeFormatManager {
3434
// Events from the explicit Atom command.
3535
atom.commands.add("atom-text-editor", "code-format:format-code", async (event) => {
3636
const editorElement = event.currentTarget
37-
if (!editorElement) {
38-
return
39-
}
4037
const editor = editorElement.getModel()
4138
// Make sure we halt everything when the editor gets destroyed.
4239
const edits = await this._formatCodeInTextEditor(editor)
@@ -85,7 +82,7 @@ export default class CodeFormatManager {
8582
// Return the text edits used to format code in the editor specified.
8683
async _formatCodeInTextEditor(editor: TextEditor, range?: Range): Promise<Array<TextEdit>> {
8784
const buffer = editor.getBuffer()
88-
const selectionRange = range || editor.getSelectedBufferRange()
85+
const selectionRange = range ?? editor.getSelectedBufferRange()
8986
const { start: selectionStart, end: selectionEnd } = selectionRange
9087
let formatRange: Range
9188
if (selectionRange.isEmpty()) {
@@ -216,9 +213,9 @@ export default class CodeFormatManager {
216213

217214
_reportBusy<T>(editor: TextEditor, promise: Promise<T>, revealTooltip: boolean = true): Promise<T> {
218215
const busySignalService = this._busySignalService
219-
if (busySignalService != null) {
216+
if (busySignalService !== undefined) {
220217
const path = editor.getPath()
221-
const displayPath = path != null ? nuclideUri.basename(path) : "<untitled>"
218+
const displayPath = path !== undefined ? nuclideUri.basename(path) : "<untitled>"
222219
return busySignalService.reportBusyWhile(`Formatting code in ${displayPath}`, () => promise, { revealTooltip })
223220
}
224221
return promise
@@ -243,7 +240,7 @@ export default class CodeFormatManager {
243240
consumeBusySignal(busySignalService: BusySignalService): Disposable {
244241
this._busySignalService = busySignalService
245242
return new Disposable(() => {
246-
this._busySignalService = null
243+
this._busySignalService = undefined
247244
})
248245
}
249246

@@ -271,7 +268,7 @@ function shouldFormatOnType(event: TextChange): boolean {
271268
// We either just deleted something or replaced a selection. For the time
272269
// being, we're not going to issue a reformat in that case.
273270
return false
274-
} else if (event.oldText === "" && event.newText === "") {
271+
} else if (event.newText === "") {
275272
// Not sure what happened here; why did we get an event in this case? Bail
276273
// for safety.
277274
return false
@@ -286,10 +283,10 @@ function shouldFormatOnType(event: TextChange): boolean {
286283
* assume that any pair of brackets that bracket-matcher recognizes was a pair matched by the package.
287284
*/
288285
function isBracketPair(typedText: string): boolean {
289-
if (atom.packages.getActivePackage("bracket-matcher") == null) {
286+
if (atom.packages.getActivePackage("bracket-matcher") === undefined) {
290287
return false
291288
}
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>
293290
return validBracketPairs.includes(typedText)
294291
}
295292

0 commit comments

Comments
 (0)