add settings for utility conflict and unsupported apply lint rules
parent
eb0b8e55be
commit
652052c1f4
35
package.json
35
package.json
|
@ -69,6 +69,41 @@
|
||||||
},
|
},
|
||||||
"default": {},
|
"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\"}`"
|
"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": [
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
""
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import {
|
||||||
Diagnostic,
|
Diagnostic,
|
||||||
DiagnosticSeverity,
|
DiagnosticSeverity,
|
||||||
} from 'vscode-languageserver'
|
} from 'vscode-languageserver'
|
||||||
import { State } from '../util/state'
|
import { State, Settings } from '../util/state'
|
||||||
import { isCssDoc } from '../util/css'
|
import { isCssDoc } from '../util/css'
|
||||||
import {
|
import {
|
||||||
findClassNamesInRange,
|
findClassNamesInRange,
|
||||||
|
@ -13,8 +13,16 @@ import {
|
||||||
import { getClassNameMeta } from '../util/getClassNameMeta'
|
import { getClassNameMeta } from '../util/getClassNameMeta'
|
||||||
import { getClassNameDecls } from '../util/getClassNameDecls'
|
import { getClassNameDecls } from '../util/getClassNameDecls'
|
||||||
import { equal } from '../../util/array'
|
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')
|
const classNames = findClassNamesInRange(document, undefined, 'css')
|
||||||
|
|
||||||
let diagnostics: Diagnostic[] = classNames
|
let diagnostics: Diagnostic[] = classNames
|
||||||
|
@ -49,7 +57,10 @@ function getCssDiagnostics(state: State, document: TextDocument): Diagnostic[] {
|
||||||
if (!message) return null
|
if (!message) return null
|
||||||
|
|
||||||
return {
|
return {
|
||||||
severity: DiagnosticSeverity.Error,
|
severity:
|
||||||
|
severity === 'error'
|
||||||
|
? DiagnosticSeverity.Error
|
||||||
|
: DiagnosticSeverity.Warning,
|
||||||
range,
|
range,
|
||||||
message,
|
message,
|
||||||
}
|
}
|
||||||
|
@ -59,10 +70,14 @@ function getCssDiagnostics(state: State, document: TextDocument): Diagnostic[] {
|
||||||
return diagnostics
|
return diagnostics
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConflictDiagnostics(
|
function getUtilityConflictDiagnostics(
|
||||||
state: State,
|
state: State,
|
||||||
document: TextDocument
|
document: TextDocument,
|
||||||
|
settings: Settings
|
||||||
): Diagnostic[] {
|
): Diagnostic[] {
|
||||||
|
let severity = settings.lint.utilityConflicts
|
||||||
|
if (severity === 'ignore') return []
|
||||||
|
|
||||||
let diagnostics: Diagnostic[] = []
|
let diagnostics: Diagnostic[] = []
|
||||||
const classLists = findClassListsInDocument(state, document)
|
const classLists = findClassListsInDocument(state, document)
|
||||||
|
|
||||||
|
@ -90,7 +105,10 @@ function getConflictDiagnostics(
|
||||||
) {
|
) {
|
||||||
diagnostics.push({
|
diagnostics.push({
|
||||||
range: className.range,
|
range: className.range,
|
||||||
severity: DiagnosticSeverity.Warning,
|
severity:
|
||||||
|
severity === 'error'
|
||||||
|
? DiagnosticSeverity.Error
|
||||||
|
: DiagnosticSeverity.Warning,
|
||||||
message: `You can’t use \`${className.className}\` and \`${otherClassName.className}\` together`,
|
message: `You can’t use \`${className.className}\` and \`${otherClassName.className}\` together`,
|
||||||
relatedInformation: [
|
relatedInformation: [
|
||||||
{
|
{
|
||||||
|
@ -114,11 +132,19 @@ export async function provideDiagnostics(
|
||||||
state: State,
|
state: State,
|
||||||
document: TextDocument
|
document: TextDocument
|
||||||
): Promise<void> {
|
): 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({
|
state.editor.connection.sendDiagnostics({
|
||||||
uri: document.uri,
|
uri: document.uri,
|
||||||
diagnostics: [
|
diagnostics,
|
||||||
...getConflictDiagnostics(state, document),
|
|
||||||
...(isCssDoc(state, document) ? getCssDiagnostics(state, document) : []),
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,11 @@ let workspaceFolder: string | null
|
||||||
const defaultSettings: Settings = {
|
const defaultSettings: Settings = {
|
||||||
emmetCompletions: false,
|
emmetCompletions: false,
|
||||||
includeLanguages: {},
|
includeLanguages: {},
|
||||||
|
validate: true,
|
||||||
|
lint: {
|
||||||
|
utilityConflicts: 'warning',
|
||||||
|
unsupportedApply: 'error',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
let globalSettings: Settings = defaultSettings
|
let globalSettings: Settings = defaultSettings
|
||||||
let documentSettings: Map<string, Settings> = new Map()
|
let documentSettings: Map<string, Settings> = new Map()
|
||||||
|
@ -172,9 +177,9 @@ connection.onDidChangeConfiguration((change) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
state.editor.documents
|
state.editor.documents.all().forEach((doc) => {
|
||||||
.all()
|
provideDiagnostics(state, doc)
|
||||||
.forEach((doc) => getDocumentSettings(state, doc.uri))
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
connection.onCompletion(
|
connection.onCompletion(
|
||||||
|
|
|
@ -25,9 +25,16 @@ export type EditorState = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DiagnosticSeveritySetting = 'ignore' | 'warning' | 'error'
|
||||||
|
|
||||||
export type Settings = {
|
export type Settings = {
|
||||||
emmetCompletions: boolean
|
emmetCompletions: boolean
|
||||||
includeLanguages: Record<string, string>
|
includeLanguages: Record<string, string>
|
||||||
|
validate: boolean
|
||||||
|
lint: {
|
||||||
|
utilityConflicts: DiagnosticSeveritySetting
|
||||||
|
unsupportedApply: DiagnosticSeveritySetting
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type State = null | {
|
export type State = null | {
|
||||||
|
|
Loading…
Reference in New Issue