update diagnostic name

master
Brad Cornes 2021-05-05 14:52:22 +01:00
parent 2942881928
commit 15fd935c57
6 changed files with 22 additions and 22 deletions

View File

@ -11,7 +11,7 @@ import {
isInvalidTailwindDirectiveDiagnostic, isInvalidTailwindDirectiveDiagnostic,
isInvalidScreenDiagnostic, isInvalidScreenDiagnostic,
isInvalidVariantDiagnostic, isInvalidVariantDiagnostic,
isIncorrectVariantOrderDiagnostic, isRecommendedVariantOrderDiagnostic,
} from '../diagnostics/types' } from '../diagnostics/types'
import { flatten, dedupeBy } from '../util/array' import { flatten, dedupeBy } from '../util/array'
import { provideCssConflictCodeActions } from './provideCssConflictCodeActions' import { provideCssConflictCodeActions } from './provideCssConflictCodeActions'
@ -63,7 +63,7 @@ export async function doCodeActions(state: State, params: CodeActionParams): Pro
isInvalidTailwindDirectiveDiagnostic(diagnostic) || isInvalidTailwindDirectiveDiagnostic(diagnostic) ||
isInvalidScreenDiagnostic(diagnostic) || isInvalidScreenDiagnostic(diagnostic) ||
isInvalidVariantDiagnostic(diagnostic) || isInvalidVariantDiagnostic(diagnostic) ||
isIncorrectVariantOrderDiagnostic(diagnostic) isRecommendedVariantOrderDiagnostic(diagnostic)
) { ) {
return provideSuggestionCodeActions(state, params, diagnostic) return provideSuggestionCodeActions(state, params, diagnostic)
} }

View File

@ -5,7 +5,7 @@ import {
InvalidTailwindDirectiveDiagnostic, InvalidTailwindDirectiveDiagnostic,
InvalidScreenDiagnostic, InvalidScreenDiagnostic,
InvalidVariantDiagnostic, InvalidVariantDiagnostic,
IncorrectVariantOrderDiagnostic, RecommendedVariantOrderDiagnostic,
} from '../diagnostics/types' } from '../diagnostics/types'
export function provideSuggestionCodeActions( export function provideSuggestionCodeActions(
@ -16,7 +16,7 @@ export function provideSuggestionCodeActions(
| InvalidTailwindDirectiveDiagnostic | InvalidTailwindDirectiveDiagnostic
| InvalidScreenDiagnostic | InvalidScreenDiagnostic
| InvalidVariantDiagnostic | InvalidVariantDiagnostic
| IncorrectVariantOrderDiagnostic | RecommendedVariantOrderDiagnostic
): CodeAction[] { ): CodeAction[] {
return diagnostic.suggestions.map((suggestion) => ({ return diagnostic.suggestions.map((suggestion) => ({
title: `Replace with '${suggestion}'`, title: `Replace with '${suggestion}'`,

View File

@ -7,7 +7,7 @@ import { getInvalidScreenDiagnostics } from './getInvalidScreenDiagnostics'
import { getInvalidVariantDiagnostics } from './getInvalidVariantDiagnostics' import { getInvalidVariantDiagnostics } from './getInvalidVariantDiagnostics'
import { getInvalidConfigPathDiagnostics } from './getInvalidConfigPathDiagnostics' import { getInvalidConfigPathDiagnostics } from './getInvalidConfigPathDiagnostics'
import { getInvalidTailwindDirectiveDiagnostics } from './getInvalidTailwindDirectiveDiagnostics' import { getInvalidTailwindDirectiveDiagnostics } from './getInvalidTailwindDirectiveDiagnostics'
import { getIncorrectVariantOrderDiagnostics } from './getIncorrectVariantOrderDiagnostics' import { getRecommendedVariantOrderDiagnostics } from './getRecommendedVariantOrderDiagnostics'
export async function doValidate( export async function doValidate(
state: State, state: State,
@ -19,7 +19,7 @@ export async function doValidate(
DiagnosticKind.InvalidVariant, DiagnosticKind.InvalidVariant,
DiagnosticKind.InvalidConfigPath, DiagnosticKind.InvalidConfigPath,
DiagnosticKind.InvalidTailwindDirective, DiagnosticKind.InvalidTailwindDirective,
DiagnosticKind.IncorrectVariantOrder, DiagnosticKind.RecommendedVariantOrder,
] ]
): Promise<AugmentedDiagnostic[]> { ): Promise<AugmentedDiagnostic[]> {
const settings = await state.editor.getConfiguration(document.uri) const settings = await state.editor.getConfiguration(document.uri)
@ -44,8 +44,8 @@ export async function doValidate(
...(only.includes(DiagnosticKind.InvalidTailwindDirective) ...(only.includes(DiagnosticKind.InvalidTailwindDirective)
? getInvalidTailwindDirectiveDiagnostics(state, document, settings) ? getInvalidTailwindDirectiveDiagnostics(state, document, settings)
: []), : []),
...(only.includes(DiagnosticKind.IncorrectVariantOrder) ...(only.includes(DiagnosticKind.RecommendedVariantOrder)
? await getIncorrectVariantOrderDiagnostics(state, document, settings) ? await getRecommendedVariantOrderDiagnostics(state, document, settings)
: []), : []),
] ]
: [] : []

View File

@ -1,22 +1,22 @@
import { State, Settings } from '../util/state' import { State, Settings } from '../util/state'
import type { TextDocument } from 'vscode-languageserver' import type { TextDocument } from 'vscode-languageserver'
import { IncorrectVariantOrderDiagnostic, DiagnosticKind } from './types' import { RecommendedVariantOrderDiagnostic, DiagnosticKind } from './types'
import { findClassListsInDocument, getClassNamesInClassList } from '../util/find' 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'
export async function getIncorrectVariantOrderDiagnostics( export async function getRecommendedVariantOrderDiagnostics(
state: State, state: State,
document: TextDocument, document: TextDocument,
settings: Settings settings: Settings
): Promise<IncorrectVariantOrderDiagnostic[]> { ): Promise<RecommendedVariantOrderDiagnostic[]> {
if (!state.jit) return [] if (!state.jit) return []
let severity = settings.tailwindCSS.lint.incorrectVariantOrder let severity = settings.tailwindCSS.lint.recommendedVariantOrder
if (severity === 'ignore') return [] if (severity === 'ignore') return []
let diagnostics: IncorrectVariantOrderDiagnostic[] = [] let diagnostics: RecommendedVariantOrderDiagnostic[] = []
const classLists = await findClassListsInDocument(state, document) const classLists = await findClassListsInDocument(state, document)
classLists.forEach((classList) => { classLists.forEach((classList) => {
@ -34,7 +34,7 @@ export async function getIncorrectVariantOrderDiagnostics(
if (!equalExact(variants, sortedVariants)) { if (!equalExact(variants, sortedVariants)) {
diagnostics.push({ diagnostics.push({
code: DiagnosticKind.IncorrectVariantOrder, code: DiagnosticKind.RecommendedVariantOrder,
suggestions: [ suggestions: [
[...sortedVariants, className.className.substr(offset)].join(state.separator), [...sortedVariants, className.className.substr(offset)].join(state.separator),
], ],

View File

@ -8,7 +8,7 @@ export enum DiagnosticKind {
InvalidVariant = 'invalidVariant', InvalidVariant = 'invalidVariant',
InvalidConfigPath = 'invalidConfigPath', InvalidConfigPath = 'invalidConfigPath',
InvalidTailwindDirective = 'invalidTailwindDirective', InvalidTailwindDirective = 'invalidTailwindDirective',
IncorrectVariantOrder = 'incorrectVariantOrder', RecommendedVariantOrder = 'recommendedVariantOrder',
} }
export type CssConflictDiagnostic = Diagnostic & { export type CssConflictDiagnostic = Diagnostic & {
@ -78,15 +78,15 @@ export function isInvalidTailwindDirectiveDiagnostic(
return diagnostic.code === DiagnosticKind.InvalidTailwindDirective return diagnostic.code === DiagnosticKind.InvalidTailwindDirective
} }
export type IncorrectVariantOrderDiagnostic = Diagnostic & { export type RecommendedVariantOrderDiagnostic = Diagnostic & {
code: DiagnosticKind.IncorrectVariantOrder code: DiagnosticKind.RecommendedVariantOrder
suggestions: string[] suggestions: string[]
} }
export function isIncorrectVariantOrderDiagnostic( export function isRecommendedVariantOrderDiagnostic(
diagnostic: AugmentedDiagnostic diagnostic: AugmentedDiagnostic
): diagnostic is IncorrectVariantOrderDiagnostic { ): diagnostic is RecommendedVariantOrderDiagnostic {
return diagnostic.code === DiagnosticKind.IncorrectVariantOrder return diagnostic.code === DiagnosticKind.RecommendedVariantOrder
} }
export type AugmentedDiagnostic = export type AugmentedDiagnostic =
@ -96,4 +96,4 @@ export type AugmentedDiagnostic =
| InvalidVariantDiagnostic | InvalidVariantDiagnostic
| InvalidConfigPathDiagnostic | InvalidConfigPathDiagnostic
| InvalidTailwindDirectiveDiagnostic | InvalidTailwindDirectiveDiagnostic
| IncorrectVariantOrderDiagnostic | RecommendedVariantOrderDiagnostic

View File

@ -48,7 +48,7 @@ export type Settings = {
invalidVariant: DiagnosticSeveritySetting invalidVariant: DiagnosticSeveritySetting
invalidConfigPath: DiagnosticSeveritySetting invalidConfigPath: DiagnosticSeveritySetting
invalidTailwindDirective: DiagnosticSeveritySetting invalidTailwindDirective: DiagnosticSeveritySetting
incorrectVariantOrder: DiagnosticSeveritySetting recommendedVariantOrder: DiagnosticSeveritySetting
} }
experimental: { experimental: {
classRegex: string[] classRegex: string[]