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
68
69
70
71
72
73
74
75
|
diff --git a/src/lsp/providers/diagnosticsProvider.ts b/src/lsp/providers/diagnosticsProvider.ts
index 18f3bc50f69c3b45bea242b280564e42d252fe90..866c07d56dabc00b1759e3d154f43154c872931c 100644
--- a/src/lsp/providers/diagnosticsProvider.ts
+++ b/src/lsp/providers/diagnosticsProvider.ts
@@ -17,6 +17,7 @@ import { getClassNameDecls } from '../util/getClassNameDecls'
import { equal, flatten } from '../../util/array'
import { getDocumentSettings } from '../util/getDocumentSettings'
const dlv = require('dlv')
+import semver from 'semver'
function getUnsupportedApplyDiagnostics(
state: State,
@@ -265,6 +266,50 @@ })
.filter(Boolean)
}
+function getUnsupportedTailwindDirectiveDiagnostics(
+ state: State,
+ document: TextDocument,
+ settings: Settings
+): Diagnostic[] {
+ let severity = settings.lint.unsupportedTailwindDirective
+ if (severity === 'ignore') return []
+
+ let text = document.getText()
+ let matches = findAll(/(?:\s|^)@tailwind\s+(?<value>[^;]+)/g, text)
+
+ let allowed = [
+ 'utilities',
+ 'components',
+ 'screens',
+ semver.gte(state.version, '1.0.0-beta.1') ? 'base' : 'preflight',
+ ]
+
+ return matches
+ .map((match) => {
+ if (allowed.includes(match.groups.value)) {
+ return null
+ }
+
+ return {
+ range: {
+ start: indexToPosition(
+ text,
+ match.index + match[0].length - match.groups.value.length
+ ),
+ end: indexToPosition(text, match.index + match[0].length),
+ },
+ severity:
+ severity === 'error'
+ ? DiagnosticSeverity.Error
+ : DiagnosticSeverity.Warning,
+ message: `Unsupported value: ${match.groups.value}${
+ match.groups.value === 'preflight' ? '. Use base instead.' : ''
+ }`,
+ }
+ })
+ .filter(Boolean)
+}
+
export async function provideDiagnostics(
state: State,
document: TextDocument
@@ -280,6 +325,11 @@ ...getUnsupportedApplyDiagnostics(state, document, settings),
...getUnknownScreenDiagnostics(state, document, settings),
...getUnknownVariantDiagnostics(state, document, settings),
...getUnknownConfigKeyDiagnostics(state, document, settings),
+ ...getUnsupportedTailwindDirectiveDiagnostics(
+ state,
+ document,
+ settings
+ ),
]
: []),
]
|