3

Is there any way to integrate monaco editor with a jshint linting tool?

I know that monaco provides a possibility to set up compiler options, but they are not enough for me. For instance, I would like to require semicolons at the end of the statements but can't find a way to do that.

4

1 回答 1

3

好的,我找到了一种方法,但我仍在思考是否有更好的方法。

基本上,我可以手动运行我的代码的 JSHint 分析。

jshint.JSHINT(this.code, options, predef)

然后根据结果,我可以创建我的自定义模型标记。就像是:

let errors = jshint.JSHINT.data().errors.map(e => {
        return {
          startLineNumber: e.line,
          startColumn: e.character,
          endLineNumber: e.line,
          endColumn: e.character,
          message: e.raw,
          severity: e.code.startsWith('E') ? monaco.Severity.Error : monaco.Severity.Warning
        }
      })

并为我的编辑器设置模型标记。

monaco.editor.setModelMarkers(this.editor.getModel(), 'test', errors)

这行得通,虽然我仍然想自定义错误标记,但也许有更自然的方法?

于 2018-07-26T13:26:10.697 回答