diff options
author | Olivier Hallot <olivier.hallot@libreoffice.org> | 2020-02-11 15:49:05 -0300 |
---|---|---|
committer | Olivier Hallot <olivier.hallot@libreoffice.org> | 2020-02-11 19:52:21 +0100 |
commit | 9b13d491adb09073913c2f4a18e1834b54c44b29 (patch) | |
tree | ed0153450d11a5f97efebe1dad691b012d454ffc /help3/xhpeditor/cm/addon/lint/coffeescript-lint.js | |
parent | 96b7217971b02de9789b70e988aa8d03846b6c90 (diff) |
xhpeditor: refactor to make CM as component
Move codemirror to a folder to ease maintenance/update
Change-Id: Id1ec9451cc49bd305f53406dcfff8978bd639016
Reviewed-on: https://gerrit.libreoffice.org/c/dev-tools/+/88472
Tested-by: Olivier Hallot <olivier.hallot@libreoffice.org>
Reviewed-by: Olivier Hallot <olivier.hallot@libreoffice.org>
Diffstat (limited to 'help3/xhpeditor/cm/addon/lint/coffeescript-lint.js')
-rw-r--r-- | help3/xhpeditor/cm/addon/lint/coffeescript-lint.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/help3/xhpeditor/cm/addon/lint/coffeescript-lint.js b/help3/xhpeditor/cm/addon/lint/coffeescript-lint.js new file mode 100644 index 00000000..a54c7035 --- /dev/null +++ b/help3/xhpeditor/cm/addon/lint/coffeescript-lint.js @@ -0,0 +1,47 @@ +// CodeMirror, copyright (c) by Marijn Haverbeke and others +// Distributed under an MIT license: https://codemirror.net/LICENSE + +// Depends on coffeelint.js from http://www.coffeelint.org/js/coffeelint.js + +// declare global: coffeelint + +(function(mod) { + if (typeof exports == "object" && typeof module == "object") // CommonJS + mod(require("../../lib/codemirror")); + else if (typeof define == "function" && define.amd) // AMD + define(["../../lib/codemirror"], mod); + else // Plain browser env + mod(CodeMirror); +})(function(CodeMirror) { +"use strict"; + +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), + to: CodeMirror.Pos(loc, 0), + severity: err.level, + message: err.message}); + }; + try { + var res = coffeelint.lint(text); + for(var i = 0; i < res.length; i++) { + parseError(res[i]); + } + } catch(e) { + found.push({from: CodeMirror.Pos(e.location.first_line, 0), + to: CodeMirror.Pos(e.location.last_line, e.location.last_column), + severity: 'error', + message: e.message}); + } + return found; +}); + +}); |