在Codemirror上显示CoffeeScript Lint
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Codemirror上显示CoffeeScript Lint相关的知识,希望对你有一定的参考价值。
我之前在Codemirror上玩过CoffeeScript,我不知道为什么但linting不能与Codemirror一起使用。即使是随Codemirror包提供的lint也不适用于我。
我做错了什么,我该如何解决这个问题?
// 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
哈哈有趣的错误。我忘了添加lint.js
。
<script src="http://codemirror.net/addon/lint/lint.js"></script>
使用此功能的任何人都可以快速记下我尝试使用editor.refresh()
刷新lint来刷新CodeMirror实例以在我的编辑器中获取CoffeeScript lints而不是JavaScript lints,但是我能让它工作的唯一方法是禁用lints并重新启用...
editor.setOption("lint", false)
editor.setOption("lint", true)
这是片段!
// 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>
以上是关于在Codemirror上显示CoffeeScript Lint的主要内容,如果未能解决你的问题,请参考以下文章