Commit ff7bb55d authored by Jérome Perrin's avatar Jérome Perrin

monaco_editor: also lint javascript with jslint

parent 310121f8
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<script src="rsvp.js"></script> <script src="rsvp.js"></script>
<script src="renderjs.js"></script> <script src="renderjs.js"></script>
<script src="jslint.js" type="text/javascript"></script>
<script src="monaco-editor/prettier@1.14.0/standalone.js"></script> <script src="monaco-editor/prettier@1.14.0/standalone.js"></script>
<script src="monaco-editor/prettier@1.14.0/parser-babylon.js"></script> <script src="monaco-editor/prettier@1.14.0/parser-babylon.js"></script>
......
/*jslint nomen: true, indent: 2 */ /*jslint nomen: true, indent: 2 */
/*global window, rJS, monaco*/ /*global window, rJS, monaco, JSLINT */
(function(window, rJS, monaco) { (function(window, rJS, monaco) {
'use strict'; 'use strict';
...@@ -49,6 +49,29 @@ ...@@ -49,6 +49,29 @@
editor.getModel().onDidChangeContent(deferNotifyChange); editor.getModel().onDidChangeContent(deferNotifyChange);
}) })
.declareJob('runJsLint', function () {
var context = this;
return new RSVP.Queue()
.push(function () { return RSVP.delay(500); })
.push(function () {
if (context.state.model_language === 'javascript') {
JSLINT(context.editor.getValue(), {});
monaco.editor.setModelMarkers(
context.editor.getModel(),
'jslint',
JSLINT.data()
.errors.filter(Boolean)
.map(err => ({
startLineNumber: err.line,
startColumn: err.character,
message: err.reason,
severity: monaco.MarkerSeverity.Error,
source: 'jslint'
}))
);
}
});
})
.declareMethod('render', function(options) { .declareMethod('render', function(options) {
var model_language, var model_language,
state_dict = { state_dict = {
...@@ -112,7 +135,11 @@ ...@@ -112,7 +135,11 @@
} }
); );
// Annotations for javascript // lint with jslint
this.editor.getModel().onDidChangeContent(this.runJsLint.bind(this));
this.runJsLint();
// lint with typescript compiler
monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({ monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
noSemanticValidation: false, noSemanticValidation: false,
noSyntaxValidation: false noSyntaxValidation: false
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment