# Using the linter plugin for code errors

**URL:** <https://discuss.codemirror.net/t/using-the-linter-plugin-for-code-errors/8042>\
**Category:** v6\
**Created:** [March 25, 2024, 6:36pm UTC](https://discuss.codemirror.net/t/using-the-linter-plugin-for-code-errors/8042 "2024-03-25T18:36:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmmulani](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/mmmulani/32/4305_2.png) [@mmmulani](https://discuss.codemirror.net/u/mmmulani)\
**Post date:** [March 25, 2024, 6:36pm UTC](https://discuss.codemirror.net/t/using-the-linter-plugin-for-code-errors/8042/1 "2024-03-25T18:36:06Z")

</div>

I’m using the linter plugin in an IDE-like UI to display run time errors from the code being edited. This setup is a bit weird compared to the usual linting flow in that, it is more imperative and a result of the code being run rather than an operation that can be run on the code itself.

Right now I’m accomplishing this by using `setDiagnostics` after retrieving errors. However, the moment the user modifies the document (or even clicks in and alters the selection), the diagnostics will disappear as the linter will rerun. I am working around this by setting a config of `{ delay: Infinity }`. This seems to solve the problem for me.

Couple questions about all this.

1. Is using the linter plugin for setting code errors like this a good solution? Or does it make more sense to create my own extension?
2. Is the workaround of setting `delay: Infinity` a good idea? Or will I run into some unintended consequences and/or break down the line?

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)\
**Post date:** [March 25, 2024, 9:12pm UTC](https://discuss.codemirror.net/t/using-the-linter-plugin-for-code-errors/8042/2 "2024-03-25T21:12:15Z")

</div>

Don’t use `linter(...)` in your configuration to avoid having any linter run automatically. `setDiagnostics` will still work.

---

<div class="post-metadata">

**Author:** ![mmmulani](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/mmmulani/32/4305_2.png) [@mmmulani](https://discuss.codemirror.net/u/mmmulani)\
**Post date:** [March 25, 2024, 9:29pm UTC](https://discuss.codemirror.net/t/using-the-linter-plugin-for-code-errors/8042/3 "2024-03-25T21:29:47Z")

</div>

ahhh also found this conversation about this issue: [Linter that only refreshes on needsRefresh - #3 by kim](https://discuss.codemirror.net/t/linter-that-only-refreshes-on-needsrefresh/7803/3)

I’m not explicitly adding a linter but using @uiw/react-codemirror which probably adds something (though I thought I disabled everything).

What would be the easiest way to find another linter being added? setting a breakpoint in `linter()` didn’t seem to find anything

---

<div class="post-metadata">

**Author:** ![mmmulani](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/mmmulani/32/4305_2.png) [@mmmulani](https://discuss.codemirror.net/u/mmmulani)\
**Post date:** [March 25, 2024, 9:56pm UTC](https://discuss.codemirror.net/t/using-the-linter-plugin-for-code-errors/8042/4 "2024-03-25T21:56:19Z")

</div>

figured it out! wasn’t actually being caused by a linter but rather by the extensions being reconfigured on focus/unfocus events because of this line: [react-codemirror/core/src/useCodeMirror.ts at master · uiwjs/react-codemirror · GitHub](https://github.com/uiwjs/react-codemirror/blob/master/core/src/useCodeMirror.ts#L137C7-L137C77) which was firing off a `view.dispatch({ effects: StateEffect.reconfigure.of(getExtensions) })`

this is clearly not a CodeMirror bug per se, but leaving the findings here for anyone else. Once we wrapped all our callbacks in `useCallback`, we were able to avoid these reconfigure state effects, and solve the issue. I’m guessing by manually creating a linter extension, we avoided the lints being destroyed.
