marijnh/CodeMirror — pull request #1258 by angelozerr (2013-02-16 12:36:04+00:00)
Title: JSON+Javascript Lint.

Here my JSON+Javascript Lint contribution.

This commit contains several files :

* \lib\codemirror-lint.css : CSS for lint.

* addon\lint\lint.js : genric lint manager (manage mark, marker text, tooltip, etc). It waits a collectAnnotations function to collect annotations (errors, warning). So you can manage any syntax checcking (js, json, xquery, etc)
* addon\lint\javascript-lint.js: provides collectAnnotations to manage js syntax checking with JSHint.
* addon\lint\json-lint.js: provides collectAnnotations to manage json syntax checking with JSONLint.
* addon\lint\jsonlint.js: copy of the JSONLint coming from https://github.com/zaach/jsonlint

* \demo\javascriptlint.html : demo with CodeMirror Javascript Lint.
* \demo\jsonlint.html : demo with CodeMirror JSON Lint.

I have managed multiple annotations. Please see TODO in lint.js to improve the lint (like open the tooltip when mouse move to the text marked as error).

You will see that therare too optionnal getContents and formatAnnotation methods that I'm using like this :

-----------------------------------------
CodeMirror.validate(editor, CodeMirror.javascriptValidator, {
getContents : function () {
return 'var f=' + editor.getValue() + ';';
},
formatAnnotation : function(annotation) {
if (annotation.lineStart == 0) {
annotation.charStart = annotation.charStart - ('var f='.length);
annotation.charEnd = annotation.charEnd - ('var f='.length);
}
return annotation;
}
});
-----------------------------------------

because in my case my editor contains

----------------
function() {

}
----------------

which is not a valid JS, but I need that, so I add var f= before validation and I must adjust the chartStart for the line 0.
So please keep thoses methods, many thank's.

Don't hesitate to change my code to clean it.

Hope you will like it.

Regards Angelo