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
61
62
63
64
65
66
67
|
diff --git a/src/lsp/providers/diagnosticsProvider.ts b/src/lsp/providers/diagnosticsProvider.ts
index bf87c9fc7a7d2cccd86fb8276845244f8baa3580..18f3bc50f69c3b45bea242b280564e42d252fe90 100644
--- a/src/lsp/providers/diagnosticsProvider.ts
+++ b/src/lsp/providers/diagnosticsProvider.ts
@@ -217,6 +217,54 @@ .filter(Boolean)
)
}
+function getUnknownConfigKeyDiagnostics(
+ state: State,
+ document: TextDocument,
+ settings: Settings
+): Diagnostic[] {
+ let severity = settings.lint.unknownConfigKey
+ if (severity === 'ignore') return []
+
+ let text = document.getText()
+ let matches = findAll(
+ /(?<prefix>\s|^)(?<helper>config|theme)\((?<quote>['"])(?<key>[^)]+)\k<quote>\)/g,
+ text
+ )
+
+ return matches
+ .map((match) => {
+ let base = match.groups.helper === 'theme' ? ['theme'] : []
+ let keys = match.groups.key.split(/[.\[\]]/).filter(Boolean)
+ let value = dlv(state.config, [...base, ...keys])
+
+ // TODO: check that the type is valid
+ // e.g. objects are not valid
+ if (typeof value !== 'undefined') {
+ return null
+ }
+
+ let startIndex =
+ match.index +
+ match.groups.prefix.length +
+ match.groups.helper.length +
+ 1 + // open paren
+ match.groups.quote.length
+
+ return {
+ range: {
+ start: indexToPosition(text, startIndex),
+ end: indexToPosition(text, startIndex + match.groups.key.length),
+ },
+ severity:
+ severity === 'error'
+ ? DiagnosticSeverity.Error
+ : DiagnosticSeverity.Warning,
+ message: `Unknown ${match.groups.helper} key: ${match.groups.key}`,
+ }
+ })
+ .filter(Boolean)
+}
+
export async function provideDiagnostics(
state: State,
document: TextDocument
@@ -231,6 +279,7 @@ ? [
...getUnsupportedApplyDiagnostics(state, document, settings),
...getUnknownScreenDiagnostics(state, document, settings),
...getUnknownVariantDiagnostics(state, document, settings),
+ ...getUnknownConfigKeyDiagnostics(state, document, settings),
]
: []),
]
|