-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
386394c
commit 7247d2e
Showing
11 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/tailwindcss-language-service/src/diagnostics/getDeprecatedClassDiagnostics.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type { State, Settings } from '../util/state' | ||
import { type DeprecatedClassDiagnostic, DiagnosticKind } from './types' | ||
import { findClassListsInDocument, getClassNamesInClassList } from '../util/find' | ||
import type { TextDocument } from 'vscode-languageserver-textdocument' | ||
|
||
export async function getDeprecatedClassDiagnostics( | ||
state: State, | ||
document: TextDocument, | ||
settings: Settings, | ||
): Promise<DeprecatedClassDiagnostic[]> { | ||
// Only v4 projects can report deprecations | ||
if (!state.v4) return [] | ||
|
||
// This is an earlier v4 version that does not support class deprecations | ||
if (!state.designSystem.classMetadata) return [] | ||
|
||
let severity = settings.tailwindCSS.lint.deprecatedClass | ||
if (severity === 'ignore') return [] | ||
|
||
// Fill in the list of statically known deprecated classes | ||
let deprecations = new Map<string, boolean>( | ||
state.classList.map(([className, meta]) => [className, meta.deprecated ?? false]), | ||
) | ||
|
||
function isDeprecated(className: string) { | ||
if (deprecations.has(className)) { | ||
return deprecations.get(className) | ||
} | ||
|
||
let metadata = state.designSystem.classMetadata([className])[0] | ||
let deprecated = metadata?.deprecated ?? false | ||
|
||
deprecations.set(className, deprecated) | ||
|
||
return deprecated | ||
} | ||
|
||
let diagnostics: DeprecatedClassDiagnostic[] = [] | ||
let classLists = await findClassListsInDocument(state, document) | ||
|
||
for (let classList of classLists) { | ||
let classNames = getClassNamesInClassList(classList, state.blocklist) | ||
|
||
for (let className of classNames) { | ||
if (!isDeprecated(className.className)) continue | ||
|
||
diagnostics.push({ | ||
code: DiagnosticKind.DeprecatedClass, | ||
className, | ||
range: className.range, | ||
severity: | ||
severity === 'error' | ||
? 1 /* DiagnosticSeverity.Error */ | ||
: 2 /* DiagnosticSeverity.Warning */, | ||
message: `'${className.className}' is deprecated.`, | ||
suggestions: [], | ||
}) | ||
} | ||
} | ||
|
||
return diagnostics | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters