Thank you for the awesome work on CodeMirror. Version 6 is truly amazing.
I am porting everything over. One thing I need is Linting for Javascript.
I imported the required variables:
import { linter, lintKeymap, lintGutter } from ‘@codemirror/lint’
import { javascript, esLint } from ‘@codemirror/lang-javascript’
My understanding is that I have to do something like this:
Codemirror’s official site provides a clear description of how linting works in Codemirror 6.
There’s two ways to do this:
Find a linter that you can run in the browser, run it on the content, and translate its output into the expected format.
Write one from scratch, possibly using the syntax tree kept by the editor.
What is the format? It’s the Diagnostic interface in the @codemirror/lint package.
If there’s a linter that works in the browser, the whole process is straightforward: passing the editView.state.doc.toString() to the linter to obtain the lint results and then converting the results to Diagnostic.
What if there’s no working linter in browser or the bundle is too big to bundle? I think using remotely lint is an option too.
Benefits of Using a Remote Solution
No additional bundle size, even if you have tens of linters on one page.
Stay updated with the latest versions of linters without waiting for updates to an npm package.