-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathvalid-compile.ts
60 lines (56 loc) · 1.5 KB
/
valid-compile.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
58
59
60
import { createRule } from "../utils"
import type { Warning } from "../shared/svelte-compile-warns"
import { getSvelteCompileWarnings } from "../shared/svelte-compile-warns"
export default createRule("valid-compile", {
meta: {
docs: {
description: "disallow warnings when compiling.",
category: "Possible Errors",
recommended: true,
},
schema: [
{
type: "object",
properties: {
ignoreWarnings: { type: "boolean" },
},
additionalProperties: false,
},
],
messages: {},
type: "problem",
},
create(context) {
if (!context.parserServices.isSvelte) {
return {}
}
const ignoreWarnings = Boolean(context.options[0]?.ignoreWarnings)
const ignores = ["missing-declaration", "dynamic-slot-name"]
/**
* report
*/
function report(warnings: Warning[]) {
for (const warn of warnings) {
if (warn.code && ignores.includes(warn.code)) {
continue
}
context.report({
loc: {
start: warn.start || warn.end || { line: 1, column: 0 },
end: warn.end || warn.start || { line: 1, column: 0 },
},
message: `${warn.message}${warn.code ? `(${warn.code})` : ""}`,
})
}
}
return {
"Program:exit"() {
const result = getSvelteCompileWarnings(context)
if (ignoreWarnings && result.kind === "warn") {
return
}
report(result.warnings)
},
}
},
})