-
Notifications
You must be signed in to change notification settings - Fork 195
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 a31c7ae
Showing
10 changed files
with
89 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
46 changes: 46 additions & 0 deletions
46
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,46 @@ | ||
import { joinWithAnd } from '../util/joinWithAnd' | ||
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 [] | ||
|
||
let severity = settings.tailwindCSS.lint.deprecatedClass | ||
if (severity === 'ignore') return [] | ||
|
||
let deprecatedClasses = new Set( | ||
state.classList.filter(([_, meta]) => meta.deprecated ?? false).map(([className]) => className), | ||
) | ||
|
||
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 (!deprecatedClasses.has(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