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

后端 未结 2 1105
你的背包
你的背包 2021-01-13 03:23

I\'m trying to enable the linting addon of the react-codemirror component in a React/Redux/TS app. The normal codemirror stuff works fine, syntax highlighting, line numbers,

相关标签:
2条回答
  • 2021-01-13 04:01

    I had a similar issue and fixed it by making jshint available on the window by replacing:

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

    with

    (<any>window).JSHINT = require('jshint').JSHINT;
    
    0 讨论(0)
  • 2021-01-13 04:06

    You need to load the lint CSS

    codemirror/addon/lint/lint.css

    and any other CSS for code mirror.

    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
    }
    
    0 讨论(0)
提交回复
热议问题