overleaf/services/web/frontend/js/features/source-editor/extensions/linting.ts
Mathias Jakobsen 80a6280231 Merge pull request #19253 from overleaf/mj-bibtex-linter
[cm6] Add bibtex linter for missing keys in entries

GitOrigin-RevId: fac79cab6420e10bfb1316262a1d0217515503f4
2024-07-15 09:01:21 +00:00

26 lines
723 B
TypeScript

import { Compartment, EditorState } from '@codemirror/state'
import { setSyntaxValidationEffect } from './language'
import { linter } from '@codemirror/lint'
export const createLinter: typeof linter = (lintSource, config) => {
const linterConfig = new Compartment()
return [
linterConfig.of([]),
// enable/disable the linter to match the syntaxValidation setting
EditorState.transactionExtender.of(tr => {
for (const effect of tr.effects) {
if (effect.is(setSyntaxValidationEffect)) {
return {
effects: linterConfig.reconfigure(
effect.value ? linter(lintSource, config) : []
),
}
}
}
return null
}),
]
}