From 03d99e588aee36e0f1bb81a5ff2cc2dc343d5380 Mon Sep 17 00:00:00 2001
From: George Stephanis <georgestephanis@automattic.com>
Date: Thu, 29 Jun 2017 14:07:31 -0400
Subject: [PATCH] [lint plugins] Provide better error messages if the lint
 library is missing

This should help developers building this functionality out that may not
realize they need to source the linting library seperately.
---
 addon/lint/coffeescript-lint.js | 6 ++++++
 addon/lint/css-lint.js          | 7 ++++++-
 addon/lint/html-lint.js         | 7 ++++++-
 addon/lint/javascript-lint.js   | 7 ++++++-
 addon/lint/json-lint.js         | 6 ++++++
 addon/lint/yaml-lint.js         | 6 ++++++
 6 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/addon/lint/coffeescript-lint.js b/addon/lint/coffeescript-lint.js
index 7e39428f7..70621a1bd 100644
--- a/addon/lint/coffeescript-lint.js
+++ b/addon/lint/coffeescript-lint.js
@@ -17,6 +17,12 @@
 
 CodeMirror.registerHelper("lint", "coffeescript", function(text) {
   var found = [];
+  if (!window.coffeelint) {
+    if (window.console) {
+      window.console.error("Error: window.coffeelint not defined, CodeMirror CoffeeScript linting cannot run.");
+    }
+    return found;
+  }
   var parseError = function(err) {
     var loc = err.lineNumber;
     found.push({from: CodeMirror.Pos(loc-1, 0),
diff --git a/addon/lint/css-lint.js b/addon/lint/css-lint.js
index 1f61b479b..b7e1a4fe5 100644
--- a/addon/lint/css-lint.js
+++ b/addon/lint/css-lint.js
@@ -17,7 +17,12 @@
 
 CodeMirror.registerHelper("lint", "css", function(text) {
   var found = [];
-  if (!window.CSSLint) return found;
+  if (!window.CSSLint) {
+    if (window.console) {
+        window.console.error("Error: window.CSSLint not defined, CodeMirror CSS linting cannot run.");
+    }
+    return found;
+  }
   var results = CSSLint.verify(text), messages = results.messages, message = null;
   for ( var i = 0; i < messages.length; i++) {
     message = messages[i];
diff --git a/addon/lint/html-lint.js b/addon/lint/html-lint.js
index 1e8417098..98c36b0b6 100644
--- a/addon/lint/html-lint.js
+++ b/addon/lint/html-lint.js
@@ -29,7 +29,12 @@
 
   CodeMirror.registerHelper("lint", "html", function(text, options) {
     var found = [];
-    if (!window.HTMLHint) return found;
+    if (!window.HTMLHint) {
+      if (window.console) {
+          window.console.error("Error: window.HTMLHint not defined, CodeMirror HTML linting cannot run.");
+      }
+      return found;
+    }
     var messages = HTMLHint.verify(text, options && options.rules || defaultRules);
     for (var i = 0; i < messages.length; i++) {
       var message = messages[i];
diff --git a/addon/lint/javascript-lint.js b/addon/lint/javascript-lint.js
index d4f2ae9a1..c58f78502 100644
--- a/addon/lint/javascript-lint.js
+++ b/addon/lint/javascript-lint.js
@@ -22,7 +22,12 @@
                  "Unclosed string", "Stopping, unable to continue" ];
 
   function validator(text, options) {
-    if (!window.JSHINT) return [];
+    if (!window.JSHINT) {
+      if (window.console) {
+        window.console.error("Error: window.JSHINT not defined, CodeMirror JavaScript linting cannot run.");
+      }
+      return [];
+    }
     JSHINT(text, options, options.globals);
     var errors = JSHINT.data().errors, result = [];
     if (errors) parseErrors(errors, result);
diff --git a/addon/lint/json-lint.js b/addon/lint/json-lint.js
index 9dbb616b3..849641ee5 100644
--- a/addon/lint/json-lint.js
+++ b/addon/lint/json-lint.js
@@ -17,6 +17,12 @@
 
 CodeMirror.registerHelper("lint", "json", function(text) {
   var found = [];
+  if (!window.jsonlint) {
+    if (window.console) {
+      window.console.error("Error: window.jsonlint not defined, CodeMirror JSON linting cannot run.");
+    }
+    return found;
+  }
   jsonlint.parseError = function(str, hash) {
     var loc = hash.loc;
     found.push({from: CodeMirror.Pos(loc.first_line - 1, loc.first_column),
diff --git a/addon/lint/yaml-lint.js b/addon/lint/yaml-lint.js
index 90b0eaab5..3954ed38e 100644
--- a/addon/lint/yaml-lint.js
+++ b/addon/lint/yaml-lint.js
@@ -17,6 +17,12 @@
 
 CodeMirror.registerHelper("lint", "yaml", function(text) {
   var found = [];
+  if (!window.jsyaml) {
+    if (window.console) {
+      window.console.error("Error: window.jsyaml not defined, CodeMirror YAML linting cannot run.");
+    }
+    return found;
+  }
   try { jsyaml.load(text); }
   catch(e) {
       var loc = e.mark,
-- 
GitLab