1
1
import type { State , Settings } from '../util/state'
2
- import { type DeprecatedClassDiagnostic } from './types'
2
+ import { type DeprecatedClassDiagnostic , DiagnosticKind } from './types'
3
+ import { findClassListsInDocument , getClassNamesInClassList } from '../util/find'
3
4
import type { TextDocument } from 'vscode-languageserver-textdocument'
4
5
5
6
export async function getDeprecatedClassDiagnostics (
@@ -16,7 +17,46 @@ export async function getDeprecatedClassDiagnostics(
16
17
let severity = settings . tailwindCSS . lint . deprecatedClass
17
18
if ( severity === 'ignore' ) return [ ]
18
19
20
+ // Fill in the list of statically known deprecated classes
21
+ let deprecations = new Map < string , boolean > (
22
+ state . classList . map ( ( [ className , meta ] ) => [ className , meta . deprecated ?? false ] ) ,
23
+ )
24
+
25
+ function isDeprecated ( className : string ) {
26
+ if ( deprecations . has ( className ) ) {
27
+ return deprecations . get ( className )
28
+ }
29
+
30
+ let metadata = state . designSystem . classMetadata ( [ className ] ) [ 0 ]
31
+ let deprecated = metadata ?. deprecated ?? false
32
+
33
+ deprecations . set ( className , deprecated )
34
+
35
+ return deprecated
36
+ }
37
+
19
38
let diagnostics : DeprecatedClassDiagnostic [ ] = [ ]
39
+ let classLists = await findClassListsInDocument ( state , document )
40
+
41
+ for ( let classList of classLists ) {
42
+ let classNames = getClassNamesInClassList ( classList , state . blocklist )
43
+
44
+ for ( let className of classNames ) {
45
+ if ( ! isDeprecated ( className . className ) ) continue
46
+
47
+ diagnostics . push ( {
48
+ code : DiagnosticKind . DeprecatedClass ,
49
+ className,
50
+ range : className . range ,
51
+ severity :
52
+ severity === 'error'
53
+ ? 1 /* DiagnosticSeverity.Error */
54
+ : 2 /* DiagnosticSeverity.Warning */ ,
55
+ message : `'${ className . className } ' is deprecated.` ,
56
+ suggestions : [ ] ,
57
+ } )
58
+ }
59
+ }
20
60
21
61
return diagnostics
22
62
}
0 commit comments