Remove linters from code interface

Fixes #812
This commit is contained in:
rijkvanzanten
2020-10-29 16:43:59 -04:00
parent 94b81f0cce
commit e3c5acd636
4 changed files with 130 additions and 221 deletions

View File

@@ -124,14 +124,19 @@ export default defineComponent({
async function setLanguage() {
if (codemirror.value) {
const lang = props.language.toLowerCase();
if (lang === 'json') {
// @ts-ignore
await import('codemirror/mode/javascript/javascript.js');
const jsonlint = (await import('jsonlint-mod')) as any;
codemirror.value.setOption('mode', { name: 'javascript', json: true });
CodeMirror.registerHelper('lint', 'json', (text: string) => {
const found: {}[] = [];
const parser = jsonlint.parser;
parser.parseError = (str: string, hash: any) => {
const loc = hash.loc;
found.push({
@@ -147,25 +152,6 @@ export default defineComponent({
}
return found;
});
} else if (lang === 'javascript' || lang === 'htmlmixed' || lang === 'yaml') {
let linter = lang;
if (lang === 'javascript') {
const jshint = await import('jshint');
(window as any).JSHINT = jshint;
} else if (lang === 'htmlmixed') {
linter = 'html';
const htmlhint = await import('htmlhint');
(window as any).HTMLHint = htmlhint;
} else if (lang === 'yaml') {
const jsyaml = await import('js-yaml');
(window as any).jsyaml = jsyaml;
}
await import(`codemirror/mode/${lang}/${lang}.js`);
await import(`codemirror/addon/lint/${linter}-lint.js`);
codemirror.value.setOption('lint', (CodeMirror as any).lint[linter]);
await import(`codemirror/mode/${lang}/${lang}.js`);
codemirror.value.setOption('mode', { name: lang });
} else if (lang === 'text/plain') {
codemirror.value.setOption('mode', { name: null });
} else {