Disable variant order linting and sorting for tailwindcss v3

master
Brad Cornes 2021-12-06 15:40:54 +00:00
parent ddabfe9390
commit 4e8918ad8c
2 changed files with 13 additions and 4 deletions

View File

@ -123,13 +123,19 @@ export function completionsFromClassList(
let items: CompletionItem[] = [] let items: CompletionItem[] = []
if (!important) { if (!important) {
let shouldSortVariants = !semver.gte(state.version, '2.99.0')
items.push( items.push(
...Object.entries(state.variants) ...Object.entries(state.variants)
.filter(([variant]) => !existingVariants.includes(variant)) .filter(([variant]) => !existingVariants.includes(variant))
.map(([variant, definition], index) => { .map(([variant, definition], index) => {
let resultingVariants = [...existingVariants, variant].sort( let resultingVariants = [...existingVariants, variant]
if (shouldSortVariants) {
resultingVariants = resultingVariants.sort(
(a, b) => allVariants.indexOf(b) - allVariants.indexOf(a) (a, b) => allVariants.indexOf(b) - allVariants.indexOf(a)
) )
}
return { return {
label: variant + sep, label: variant + sep,
@ -146,7 +152,7 @@ export function completionsFromClassList(
range: replacementRange, range: replacementRange,
}, },
additionalTextEdits: additionalTextEdits:
resultingVariants.length > 1 shouldSortVariants && resultingVariants.length > 1
? [ ? [
{ {
newText: newText:

View File

@ -5,6 +5,7 @@ import { findClassListsInDocument, getClassNamesInClassList } from '../util/find
import * as jit from '../util/jit' import * as jit from '../util/jit'
import { getVariantsFromClassName } from '../util/getVariantsFromClassName' import { getVariantsFromClassName } from '../util/getVariantsFromClassName'
import { equalExact } from '../util/array' import { equalExact } from '../util/array'
import semver from 'semver'
export async function getRecommendedVariantOrderDiagnostics( export async function getRecommendedVariantOrderDiagnostics(
state: State, state: State,
@ -13,6 +14,8 @@ export async function getRecommendedVariantOrderDiagnostics(
): Promise<RecommendedVariantOrderDiagnostic[]> { ): Promise<RecommendedVariantOrderDiagnostic[]> {
if (!state.jit) return [] if (!state.jit) return []
if (semver.gte(state.version, '2.99.0')) return []
let severity = settings.tailwindCSS.lint.recommendedVariantOrder let severity = settings.tailwindCSS.lint.recommendedVariantOrder
if (severity === 'ignore') return [] if (severity === 'ignore') return []