uiwjs / react-codemirror

CodeMirror 6 component for React. @codemirror https://uiwjs.github.io/react-codemirror/
https://uiwjs.github.io/react-codemirror/
MIT License
1.64k stars 130 forks source link

How to lint code #469

Open Jenny-pyl opened 1 year ago

Jenny-pyl commented 1 year ago

I use 'uiwjs/react-codemmmirror' to write a 'json-editor' component, but I have no idea about how to lint code.Thanks

jaywcjlove commented 1 year ago

@Jenny-pyl https://codemirror.net/examples/lint/

edymusajev commented 1 year ago

@Jenny-pyl Here's how to add linting to react-codemirror

import CodeMirror from "@uiw/react-codemirror";
import { json, jsonParseLinter } from "@codemirror/lang-json";
import { linter } from "@codemirror/lint";
import { useState } from "react";

export function JsonEditor() {
  const [value, setValue] = useState("");
  return (
    <div>
      <CodeMirror
        value={value}
        onChange={(value) => setValue(value)}
        height="200px"
        extensions={[json(), linter(jsonParseLinter())]}
      />
    </div>
  );
}
fabpico commented 7 months ago

Can this be added to the documentatoin or readme? Consider also the very important but almost hiddenly documented lintGutter.

jaywcjlove commented 7 months ago

Can this be added to the documentatoin or readme? Consider also the very important but almost hiddenly documented lintGutter.

@fabpico Welcome to update the documentation