React-codemirror 2 linting 功能不起作用
React-codemirror 2 linting feature not working
我在我的 React 应用程序中创建了一个 react-codemirror 2 组件,但该包的 linting 功能不起作用。我尝试浏览其他堆栈溢出问题,但由于这些问题至少已有 2 年历史,它看起来像原始库的文件结构,即 codemirror 已更改,解决方案的 none 似乎有效。我还在他们的 Github 回购中提出了一个问题,但没有对此做出回应。希望你能帮忙,这是我的组件的代码。
import React from "react";
import { UnControlled as CodeMirror } from "react-codemirror2";
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/material.css';
import 'codemirror/addon/lint/lint.css';
import 'codemirror/addon/hint/show-hint.css';
import 'codemirror/mode/javascript/javascript.js';
import 'codemirror/addon/lint/javascript-lint';
import 'codemirror/addon/lint/lint.js';
import 'codemirror/addon/hint/javascript-hint';
const JsEditor = ({code}) => {
return (
<div>
<h1> JavaScript </h1>
<CodeMirror
value={code}
options={{
gutters: ["CodeMirror-lint-markers"],
mode: "javascript",
theme: "material",
lineNumbers: true,
lineWrapping: true,
lint: true,
}}
/>
</div>
);
};
export default JsEditor;
CodeMirror 的 lint 插件需要 jshint 库。如果你添加它 (npm i jshint
),下面的代码应该可以工作:
import React from 'react';
import { UnControlled as CodeMirror } from "react-codemirror2";
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/material.css';
import 'codemirror/addon/lint/lint.css';
import 'codemirror/addon/hint/show-hint.css';
import 'codemirror/mode/javascript/javascript.js';
import 'codemirror/addon/lint/javascript-lint';
import 'codemirror/addon/lint/lint.js';
import 'codemirror/addon/hint/javascript-hint';
import { JSHINT } from 'jshint';
window.JSHINT = JSHINT;
const JsEditor = ({ code }) => {
return (
<div>
<h1> JavaScript </h1>
<CodeMirror
value={code}
options={{
gutters: ["CodeMirror-lint-markers"],
mode: "javascript",
theme: "material",
lineNumbers: true,
lineWrapping: true,
lint: true,
}}
/>
</div>
);
};
function App() {
return (
<div className="App">
<JsEditor code={'var widgets =[]; debugger'} />
</div>
);
}
export default App;
我在我的 React 应用程序中创建了一个 react-codemirror 2 组件,但该包的 linting 功能不起作用。我尝试浏览其他堆栈溢出问题,但由于这些问题至少已有 2 年历史,它看起来像原始库的文件结构,即 codemirror 已更改,解决方案的 none 似乎有效。我还在他们的 Github 回购中提出了一个问题,但没有对此做出回应。希望你能帮忙,这是我的组件的代码。
import React from "react";
import { UnControlled as CodeMirror } from "react-codemirror2";
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/material.css';
import 'codemirror/addon/lint/lint.css';
import 'codemirror/addon/hint/show-hint.css';
import 'codemirror/mode/javascript/javascript.js';
import 'codemirror/addon/lint/javascript-lint';
import 'codemirror/addon/lint/lint.js';
import 'codemirror/addon/hint/javascript-hint';
const JsEditor = ({code}) => {
return (
<div>
<h1> JavaScript </h1>
<CodeMirror
value={code}
options={{
gutters: ["CodeMirror-lint-markers"],
mode: "javascript",
theme: "material",
lineNumbers: true,
lineWrapping: true,
lint: true,
}}
/>
</div>
);
};
export default JsEditor;
CodeMirror 的 lint 插件需要 jshint 库。如果你添加它 (npm i jshint
),下面的代码应该可以工作:
import React from 'react';
import { UnControlled as CodeMirror } from "react-codemirror2";
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/material.css';
import 'codemirror/addon/lint/lint.css';
import 'codemirror/addon/hint/show-hint.css';
import 'codemirror/mode/javascript/javascript.js';
import 'codemirror/addon/lint/javascript-lint';
import 'codemirror/addon/lint/lint.js';
import 'codemirror/addon/hint/javascript-hint';
import { JSHINT } from 'jshint';
window.JSHINT = JSHINT;
const JsEditor = ({ code }) => {
return (
<div>
<h1> JavaScript </h1>
<CodeMirror
value={code}
options={{
gutters: ["CodeMirror-lint-markers"],
mode: "javascript",
theme: "material",
lineNumbers: true,
lineWrapping: true,
lint: true,
}}
/>
</div>
);
};
function App() {
return (
<div className="App">
<JsEditor code={'var widgets =[]; debugger'} />
</div>
);
}
export default App;