Can we manually force linting even if the document hasn't changed?

I’m working on a project with Codemirror 6 where I’m editing a JSON5 structure, and I have a custom linter that checks the values in the editor against related data that lives outside the editor.

For example, the value at a particular path in the JSON document must match one of the values in another list that is not part of the document.

// The document inside CodeMirror
{
   value: "abc"
}

And this this might be the other list that is maintained outside the editor. The linter checks that value in the editor is one of these values.

[ "abc", "def" ]

This works great for cases where I’m changing the document itself.

Now I’m working on forcing the lint to rerun when the values in the external list change, but the document itself hasn’t changed. With the above example, say if the external list changes to ['a', 'def'] then the abc value is no longer in the list so the linter will flag that.

But forceLinting doesn’t seem to handle this case. I took a look at the code, and it appears that forceLinting only actually forces it if this.set is true, which in turn only gets set if a state update comes in where docChanged is set.

Do you have any recommendations on how to deal with this? The obvious change IMO is to add an argument to forceLinting that will force the lint even if the document hasn’t changed, but maybe there’s a better way. Thanks!

p.s. I’m planning to publish my JSON5-specific work for CodeMirror (lezer parser, CodeMirror support, etc.) in a separate repo soon so all can use it :slight_smile:

With @codemirror/lint 0.19.2, you should be able to reconfigure your linter (just update a compartment with a different linter call) to cause the lint plugin to schedule a new lint pass.

1 Like

Perfect, I was already doing that anyway. Confirmed it works with 0.19.2. Thank you!