diff --git a/RuboCop.novaextension/CHANGELOG.md b/RuboCop.novaextension/CHANGELOG.md index 7898564..e33c28e 100644 --- a/RuboCop.novaextension/CHANGELOG.md +++ b/RuboCop.novaextension/CHANGELOG.md @@ -2,6 +2,7 @@ ## UNRELEASED +- Added an informative notice to the user when RuboCop could not be found. - Restructured the project to allow for npm dependencies to be consumed. - Added a new icon for the extension. - Added documentation to the README. diff --git a/Source/Scripts/RuboCopProcess.js b/Source/Scripts/RuboCopProcess.js index 19b7ce4..ebb474f 100644 --- a/Source/Scripts/RuboCopProcess.js +++ b/Source/Scripts/RuboCopProcess.js @@ -6,6 +6,7 @@ // const Offense = require("./Offense"); +var isUserNotifiedOfMissingCommand; class RuboCopProcess { @@ -46,7 +47,11 @@ class RuboCopProcess { } handleError(error) { - console.error(error); + if (error.match(/(no such file or directory|command not found)/i)) { + this.handleMissingCommand(); + } else { + console.error(error); + } } handleOutput(output) { @@ -62,6 +67,26 @@ class RuboCopProcess { } } + handleMissingCommand() { + if (isUserNotifiedOfMissingCommand) { return; } + + const request = new NotificationRequest("rubocop-not-found"); + request.title = nova.localize("RuboCop Not Found"); + request.body = nova.localize("The \"rubocop\" command could not be found in your environment."); + request.actions = [nova.localize("OK"), nova.localize("More Information…")]; + + const notificationPromise = nova.notifications.add(request); + notificationPromise.then((response) => { + if (response.actionIdx === 1) { // More Information… + nova.openURL("https://github.com/jsmecham/nova-rubocop/wiki/Environment"); + } + }).catch((error) => { + console.error(error); + }).finally(() => { + isUserNotifiedOfMissingCommand = true; + }); + } + onComplete(callback) { this._onCompleteCallback = callback; }