-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmarkup.ts
57 lines (49 loc) · 1.35 KB
/
markup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Rule } from 'eslint'
import { sync } from '../sync.js'
export const markup: Rule.RuleModule = {
meta: {
fixable: 'code',
type: 'problem',
},
create(context) {
const filename = context.getFilename()
const sourceText = context.getSourceCode().text
const markuplintOptions = {
sourceCode: sourceText,
name: filename,
}
const runMarkuplint = (fix?: boolean) =>
sync.markuplintSync(markuplintOptions, fix)
return {
Program() {
const { violations } = runMarkuplint()
if (violations.length === 0) {
return
}
let fixed = 0
for (const { ruleId, severity, message, line, col } of violations) {
context.report({
message: JSON.stringify({ severity, message, ruleId }),
loc: {
line,
// ! eslint ast column is 0-indexed, but markuplint is 1-indexed
column: col - 1,
},
fix() {
if (fixed++) {
return null
}
const { fixedCode } = runMarkuplint(true)
return sourceText === fixedCode
? null
: {
range: [0, sourceText.length],
text: fixedCode,
}
},
})
}
},
}
},
}