Accessing linting errors on update

Hey,

I would like to figure out after editor update, if there are any linting errors. Is there a way to do that?

Since the logic for linting json is fairly simple. I ended up copying logic from linter (JSON.parse) in the EditorView.updateListener to figure out if the value is valid.

There is now—@codemirror/lint 0.19.1 adds a diagnosticCount(state) function.

Is there any documentation on how this can be used with CodeMirror? I can see an exported linter function (lint/src/lint.ts at main · codemirror/lint · GitHub) but it’s unclear what parameters are required.

I’ve just found CodeMirror 6 Reference Manual, so perhaps I posted prematurely.

diagnosticCount seems to return a count for both lint errors and warnings for me, but I only need the count for the errors. Is there a way to get a count for only error-related diagnostics?

Could use forEachDiagnostic and count them yourself.

1 Like