From f0e03bbddc9263f44a19810c2857155bc41e53f2 Mon Sep 17 00:00:00 2001 From: Landon Abney Date: Wed, 6 Dec 2017 09:42:48 -0800 Subject: [PATCH] Guard against invalid TextEditor and empty paths Occasionally `lint()` somehow gets called with invalid `TextEditor`s, or ones without a path. When these cases are hit simply return `null` instead of trying to process them. Fixes #527. --- lib/main.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/main.js b/lib/main.js index 8a1eb39..a1a7925 100644 --- a/lib/main.js +++ b/lib/main.js @@ -179,11 +179,21 @@ export default { scope: 'file', lintOnFly: true, lint: async (textEditor) => { - loadDeps(); + if (!atom.workspace.isTextEditor(textEditor)) { + // Invalid TextEditor + return null; + } const filePath = textEditor.getPath(); + if (!filePath) { + // Invalid path + return null; + } const fileText = textEditor.getText(); + // Load dependencies if they aren't already + loadDeps(); + const parameters = ['--format=default']; const projectPath = atom.project.relativizePath(filePath)[0];