Skip to content

Commit d8387a9

Browse files
authored
refactor: use optional chaining (#448)
1 parent a285fd4 commit d8387a9

4 files changed

Lines changed: 4 additions & 5 deletions

File tree

src/DocumentWatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export default class DocumentWatcher {
145145
}
146146

147147
private async handleTextEditorChange(editor?: TextEditor) {
148-
if (editor && editor.document) {
148+
if (editor?.document) {
149149
const newOptions = await resolveTextEditorOptions(
150150
(this.doc = editor.document),
151151
{

src/commands/generateEditorConfig.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ const readFile = promisify(_readFile)
1111
* current vscode settings.
1212
*/
1313
export async function generateEditorConfig(uri: Uri) {
14-
const workspaceUri =
15-
workspace.workspaceFolders && workspace.workspaceFolders[0].uri
14+
const workspaceUri = workspace.workspaceFolders?.[0].uri
1615
const currentUri = uri || workspaceUri
1716
if (!currentUri) {
1817
window.showErrorMessage("Workspace doesn't contain any folders.")

src/transformations/InsertFinalNewline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class InsertFinalNewline extends PreSaveTransformation {
3030
return { edits: [] }
3131
}
3232

33-
if (window.activeTextEditor && window.activeTextEditor.document === doc) {
33+
if (window.activeTextEditor?.document === doc) {
3434
commands.executeCommand('editor.action.insertFinalNewLine')
3535
return {
3636
edits: [],

src/transformations/TrimTrailingWhitespace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class TrimTrailingWhitespace extends PreSaveTransformation {
4040
return { edits: [] }
4141
}
4242

43-
if (window.activeTextEditor && window.activeTextEditor.document === doc) {
43+
if (window.activeTextEditor?.document === doc) {
4444
const trimReason =
4545
reason !== TextDocumentSaveReason.Manual ? 'auto-save' : null
4646
commands.executeCommand('editor.action.trimTrailingWhitespace', {

0 commit comments

Comments
 (0)