简体   繁体   中英

Show CoffeeScript Lint on Codemirror

I was playing with CoffeeScript earlier on Codemirror and I don't know why but linting is not working with Codemirror. Even the lint that's provided with the Codemirror package is not working for me.

What am I doing wrong and how can I solve this problem?

 // Initialize CodeMirror editor var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: "text/x-coffeescript", tabMode: "indent", styleActiveLine: true, lineNumbers: true, lineWrapping: true, autoCloseTags: true, foldGutter: true, dragDrop: true, lint: true, gutters: ["CodeMirror-lint-markers", "CodeMirror-linenumbers", "CodeMirror-foldgutter"] }) 
 .CodeMirror { width: 100%; height: auto; } 
 <link rel="stylesheet" href="https://necolas.github.io/normalize.css/4.0.0/normalize.css"> <link rel="stylesheet" href="http://codemirror.net/lib/codemirror.css"> <link rel="stylesheet" href="http://codemirror.net/addon/fold/foldgutter.css"> <link rel="stylesheet" href="http://codemirror.net/addon/hint/show-hint.css"> <link rel="stylesheet" href="http://codemirror.net/addon/lint/lint.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://codemirror.net/lib/codemirror.js"></script> <script src="http://codemirror.net/mode/javascript/javascript.js"></script> <script src="http://codemirror.net/mode/xml/xml.js"></script> <script src="http://codemirror.net/mode/css/css.js"></script> <script src="http://codemirror.net/mode/htmlmixed/htmlmixed.js"></script> <script src="http://codemirror.net/addon/edit/closetag.js"></script> <script src="http://codemirror.net/addon/edit/matchbrackets.js"></script> <script src="http://codemirror.net/addon/selection/active-line.js"></script> <script src="http://codemirror.net/addon/fold/foldcode.js"></script> <script src="http://codemirror.net/addon/fold/foldgutter.js"></script> <script src="http://codemirror.net/addon/fold/brace-fold.js"></script> <script src="http://codemirror.net/addon/fold/xml-fold.js"></script> <script src="http://codemirror.net/addon/fold/comment-fold.js"></script> <script src="http://coffeescript.org/extras/coffee-script.js"></script> <script src="http://coffeelint.org/js/coffeelint.js"></script> <script src="http://codemirror.net/mode/coffeescript/coffeescript.js"></script> <script src="http://codemirror.net/addon/lint/coffeescript-lint.js"></script> <textarea id="code">function () {}</textarea> 

http://kodeweave.sourceforge.net/editor/#362e030f5d37beb17766999e92ef4e88

Haha funny mistake. I forgot to add lint.js .

<script src="http://codemirror.net/addon/lint/lint.js"></script>

A quick note for anyone using this. I tried refreshing the lint with editor.refresh() to refresh the CodeMirror instance to get CoffeeScript lints instead of JavaScript lints in my editor, but the only way I could get it to work was disabling lints and re-enabling with...

editor.setOption("lint", false)
editor.setOption("lint", true)

Here's the snippet!

 // Initialize CodeMirror editor var editor = CodeMirror.fromTextArea(document.getElementById("code"), { mode: "text/x-coffeescript", tabMode: "indent", styleActiveLine: true, lineNumbers: true, lineWrapping: true, autoCloseTags: true, foldGutter: true, dragDrop: true, lint: true, gutters: ["CodeMirror-lint-markers", "CodeMirror-linenumbers", "CodeMirror-foldgutter"] }) 
 .CodeMirror { width: 100%; height: auto; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" href="https://necolas.github.io/normalize.css/4.0.0/normalize.css"> <link rel="stylesheet" href="http://codemirror.net/lib/codemirror.css"> <link rel="stylesheet" href="http://codemirror.net/addon/lint/lint.css"> <script src="http://codemirror.net/lib/codemirror.js"></script> <script src="http://codemirror.net/addon/lint/lint.js"></script> <script src="http://codemirror.net/mode/coffeescript/coffeescript.js"></script> <script src="http://coffeescript.org/extras/coffee-script.js"></script> <script src="http://coffeelint.org/js/coffeelint.js"></script> <script src="http://codemirror.net/addon/lint/coffeescript-lint.js"></script> <textarea id="code">function () {} # Initialize CodeMirror editor editor = CodeMirror.fromTextArea(document.getElementById('code'), mode: 'text/x-coffeescript' tabMode: 'indent' styleActiveLine: true lineNumbers: true lineWrapping: true autoCloseTags: true foldGutter: true dragDrop: true lint: true gutters: [ 'CodeMirror-lint-markers' 'CodeMirror-linenumbers' 'CodeMirror-foldgutter' ])</textarea> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM