|
| 1 | +import { joinWithAnd } from '../util/joinWithAnd' |
| 2 | +import type { State, Settings } from '../util/state' |
| 3 | +import { type DeprecatedClassDiagnostic, DiagnosticKind } from './types' |
| 4 | +import { findClassListsInDocument, getClassNamesInClassList } from '../util/find' |
| 5 | +import type { TextDocument } from 'vscode-languageserver-textdocument' |
| 6 | + |
| 7 | +export async function getDeprecatedClassDiagnostics( |
| 8 | + state: State, |
| 9 | + document: TextDocument, |
| 10 | + settings: Settings, |
| 11 | +): Promise<DeprecatedClassDiagnostic[]> { |
| 12 | + // Only v4 projects can report deprecations |
| 13 | + if (!state.v4) return [] |
| 14 | + |
| 15 | + let severity = settings.tailwindCSS.lint.deprecatedClass |
| 16 | + if (severity === 'ignore') return [] |
| 17 | + |
| 18 | + let deprecatedClasses = new Set( |
| 19 | + state.classList.filter(([_, meta]) => meta.deprecated ?? false).map(([className]) => className), |
| 20 | + ) |
| 21 | + |
| 22 | + let diagnostics: DeprecatedClassDiagnostic[] = [] |
| 23 | + let classLists = await findClassListsInDocument(state, document) |
| 24 | + |
| 25 | + for (let classList of classLists) { |
| 26 | + let classNames = getClassNamesInClassList(classList, state.blocklist) |
| 27 | + |
| 28 | + for (let className of classNames) { |
| 29 | + if (!deprecatedClasses.has(className.className)) continue |
| 30 | + |
| 31 | + diagnostics.push({ |
| 32 | + code: DiagnosticKind.DeprecatedClass, |
| 33 | + className, |
| 34 | + range: className.range, |
| 35 | + severity: |
| 36 | + severity === 'error' |
| 37 | + ? 1 /* DiagnosticSeverity.Error */ |
| 38 | + : 2 /* DiagnosticSeverity.Warning */, |
| 39 | + message: `'${className.className}' is deprecated.`, |
| 40 | + suggestions: [], |
| 41 | + }) |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + return diagnostics |
| 46 | +} |
0 commit comments