简体   繁体   English

Codemirror lint功能在React / Redux / Typescript App中无法运行react-codemirror

[英]Codemirror lint feature not working react-codemirror in React/Redux/Typescript App

I'm trying to enable the linting addon of the react-codemirror component in a React/Redux/TS app. 我正在尝试在React / Redux / TS应用程序中启用react-codemirror组件的linting插件。 The normal codemirror stuff works fine, syntax highlighting, line numbers, etc. However, enabling linting adds the extra padding on the left for the lint messages to the component, but no messages are displayed. 正常的codemirror东西工作正常,语法高亮,行号等。但是,启用linting会在左侧添加额外的填充,以便将lint消息添加到组件,但不会显示任何消息。

I have a suspicion its something about the codemirror lint.js code not loading, but I'm not sure why. 我怀疑它是关于codemirror lint.js代码没有加载的东西,但我不知道为什么。 Relevant code snippets below: 以下相关代码段:

import * as CodeMirror from 'react-codemirror';
import '../../../node_modules/codemirror/mode/javascript/javascript';
import '../../../node_modules/codemirror/addon/lint/lint';
import '../../../node_modules/codemirror/addon/lint/javascript-lint';
import '../../../node_modules/jshint/dist/jshint';

...

<CodeMirror
    options={{
        lineNumbers: true,
        readOnly: false,
        mode: 'javascript',
        lint: true,
        gutters: ['CodeMirror-lint-markers']
    }}
/>

Has anyone been able to get this addon working successfully? 有没有人能够成功地使这个插件工作?

I had a similar issue and fixed it by making jshint available on the window by replacing: 我有一个类似的问题,并通过替换以下窗口使jshint可用来修复它:

import '../../../node_modules/jshint/dist/jshint';

with

(<any>window).JSHINT = require('jshint').JSHINT;

You need to load the lint CSS 您需要加载lint CSS

codemirror/addon/lint/lint.css codemirror /插件/皮棉/ lint.css

and any other CSS for code mirror. 和代码镜像的任何其他CSS。

Also, for further clarification here are my imports: 此外,为了进一步澄清这里是我的进口:

import CodeMirror from 'react-codemirror'
import { JSHINT } from 'jshint'

import 'codemirror/addon/lint/lint'
import 'codemirror/addon/lint/javascript-lint'
import 'codemirror/mode/javascript/javascript'

window.JSHINT = JSHINT

And don't forget these options: 不要忘记这些选择:

var options = {
  mode: 'javascript',
  gutters: ['CodeMirror-lint-markers'],
  lint: true
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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