add settings for utility conflict and unsupported apply lint rules

master
Brad Cornes 2020-06-12 16:22:04 +01:00
parent eb0b8e55be
commit 652052c1f4
4 changed files with 86 additions and 13 deletions

View File

@ -69,6 +69,41 @@
},
"default": {},
"markdownDescription": "Enable features in languages that are not supported by default. Add a mapping here between the new language and an already supported language.\n E.g.: `{\"plaintext\": \"html\"}`"
},
"tailwindCSS.validate": {
"type": "boolean",
"default": true,
"markdownDescription": ""
},
"tailwindCSS.lint.utilityConflicts": {
"type": "string",
"enum": [
"ignore",
"warning",
"error"
],
"default": "warning",
"markdownDescription": "",
"markdownEnumDescriptions": [
"",
"",
""
]
},
"tailwindCSS.lint.unsupportedApply": {
"type": "string",
"enum": [
"ignore",
"warning",
"error"
],
"default": "error",
"markdownDescription": "",
"markdownEnumDescriptions": [
"",
"",
""
]
}
}
}

View File

@ -3,7 +3,7 @@ import {
Diagnostic,
DiagnosticSeverity,
} from 'vscode-languageserver'
import { State } from '../util/state'
import { State, Settings } from '../util/state'
import { isCssDoc } from '../util/css'
import {
findClassNamesInRange,
@ -13,8 +13,16 @@ import {
import { getClassNameMeta } from '../util/getClassNameMeta'
import { getClassNameDecls } from '../util/getClassNameDecls'
import { equal } from '../../util/array'
import { getDocumentSettings } from '../util/getDocumentSettings'
function getCssDiagnostics(
state: State,
document: TextDocument,
settings: Settings
): Diagnostic[] {
let severity = settings.lint.unsupportedApply
if (severity === 'ignore') return []
function getCssDiagnostics(state: State, document: TextDocument): Diagnostic[] {
const classNames = findClassNamesInRange(document, undefined, 'css')
let diagnostics: Diagnostic[] = classNames
@ -49,7 +57,10 @@ function getCssDiagnostics(state: State, document: TextDocument): Diagnostic[] {
if (!message) return null
return {
severity: DiagnosticSeverity.Error,
severity:
severity === 'error'
? DiagnosticSeverity.Error
: DiagnosticSeverity.Warning,
range,
message,
}
@ -59,10 +70,14 @@ function getCssDiagnostics(state: State, document: TextDocument): Diagnostic[] {
return diagnostics
}
function getConflictDiagnostics(
function getUtilityConflictDiagnostics(
state: State,
document: TextDocument
document: TextDocument,
settings: Settings
): Diagnostic[] {
let severity = settings.lint.utilityConflicts
if (severity === 'ignore') return []
let diagnostics: Diagnostic[] = []
const classLists = findClassListsInDocument(state, document)
@ -90,7 +105,10 @@ function getConflictDiagnostics(
) {
diagnostics.push({
range: className.range,
severity: DiagnosticSeverity.Warning,
severity:
severity === 'error'
? DiagnosticSeverity.Error
: DiagnosticSeverity.Warning,
message: `You cant use \`${className.className}\` and \`${otherClassName.className}\` together`,
relatedInformation: [
{
@ -114,11 +132,19 @@ export async function provideDiagnostics(
state: State,
document: TextDocument
): Promise<void> {
const settings = await getDocumentSettings(state, document.uri)
const diagnostics: Diagnostic[] = settings.validate
? [
...getUtilityConflictDiagnostics(state, document, settings),
...(isCssDoc(state, document)
? getCssDiagnostics(state, document, settings)
: []),
]
: []
state.editor.connection.sendDiagnostics({
uri: document.uri,
diagnostics: [
...getConflictDiagnostics(state, document),
...(isCssDoc(state, document) ? getCssDiagnostics(state, document) : []),
],
diagnostics,
})
}

View File

@ -36,6 +36,11 @@ let workspaceFolder: string | null
const defaultSettings: Settings = {
emmetCompletions: false,
includeLanguages: {},
validate: true,
lint: {
utilityConflicts: 'warning',
unsupportedApply: 'error',
},
}
let globalSettings: Settings = defaultSettings
let documentSettings: Map<string, Settings> = new Map()
@ -172,9 +177,9 @@ connection.onDidChangeConfiguration((change) => {
)
}
state.editor.documents
.all()
.forEach((doc) => getDocumentSettings(state, doc.uri))
state.editor.documents.all().forEach((doc) => {
provideDiagnostics(state, doc)
})
})
connection.onCompletion(

View File

@ -25,9 +25,16 @@ export type EditorState = {
}
}
type DiagnosticSeveritySetting = 'ignore' | 'warning' | 'error'
export type Settings = {
emmetCompletions: boolean
includeLanguages: Record<string, string>
validate: boolean
lint: {
utilityConflicts: DiagnosticSeveritySetting
unsupportedApply: DiagnosticSeveritySetting
}
}
export type State = null | {