add initial "unknown screen" diagnostics
parent
652052c1f4
commit
7c0247fb11
15
package.json
15
package.json
|
@ -104,6 +104,21 @@
|
||||||
"",
|
"",
|
||||||
""
|
""
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"tailwindCSS.lint.unknownScreen": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"ignore",
|
||||||
|
"warning",
|
||||||
|
"error"
|
||||||
|
],
|
||||||
|
"default": "error",
|
||||||
|
"markdownDescription": "",
|
||||||
|
"markdownEnumDescriptions": [
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
""
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,16 @@ import {
|
||||||
findClassNamesInRange,
|
findClassNamesInRange,
|
||||||
findClassListsInDocument,
|
findClassListsInDocument,
|
||||||
getClassNamesInClassList,
|
getClassNamesInClassList,
|
||||||
|
findAll,
|
||||||
|
indexToPosition,
|
||||||
} from '../util/find'
|
} from '../util/find'
|
||||||
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'
|
import { getDocumentSettings } from '../util/getDocumentSettings'
|
||||||
|
const dlv = require('dlv')
|
||||||
|
|
||||||
function getCssDiagnostics(
|
function getUnsupportedApplyDiagnostics(
|
||||||
state: State,
|
state: State,
|
||||||
document: TextDocument,
|
document: TextDocument,
|
||||||
settings: Settings
|
settings: Settings
|
||||||
|
@ -128,6 +131,45 @@ function getUtilityConflictDiagnostics(
|
||||||
return diagnostics
|
return diagnostics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getScreenDirectiveDiagnostics(
|
||||||
|
state: State,
|
||||||
|
document: TextDocument,
|
||||||
|
settings: Settings
|
||||||
|
): Diagnostic[] {
|
||||||
|
let severity = settings.lint.unknownScreen
|
||||||
|
if (severity === 'ignore') return []
|
||||||
|
|
||||||
|
let text = document.getText()
|
||||||
|
let matches = findAll(/(?:\s|^)@screen\s+(?<screen>[^\s{]+)/g, text)
|
||||||
|
|
||||||
|
let screens = Object.keys(
|
||||||
|
dlv(state.config, 'theme.screens', dlv(state.config, 'screens', {}))
|
||||||
|
)
|
||||||
|
|
||||||
|
return matches
|
||||||
|
.map((match) => {
|
||||||
|
if (screens.includes(match.groups.screen)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
range: {
|
||||||
|
start: indexToPosition(
|
||||||
|
text,
|
||||||
|
match.index + match[0].length - match.groups.screen.length
|
||||||
|
),
|
||||||
|
end: indexToPosition(text, match.index + match[0].length),
|
||||||
|
},
|
||||||
|
severity:
|
||||||
|
severity === 'error'
|
||||||
|
? DiagnosticSeverity.Error
|
||||||
|
: DiagnosticSeverity.Warning,
|
||||||
|
message: 'Unknown screen',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(Boolean)
|
||||||
|
}
|
||||||
|
|
||||||
export async function provideDiagnostics(
|
export async function provideDiagnostics(
|
||||||
state: State,
|
state: State,
|
||||||
document: TextDocument
|
document: TextDocument
|
||||||
|
@ -138,7 +180,10 @@ export async function provideDiagnostics(
|
||||||
? [
|
? [
|
||||||
...getUtilityConflictDiagnostics(state, document, settings),
|
...getUtilityConflictDiagnostics(state, document, settings),
|
||||||
...(isCssDoc(state, document)
|
...(isCssDoc(state, document)
|
||||||
? getCssDiagnostics(state, document, settings)
|
? [
|
||||||
|
...getUnsupportedApplyDiagnostics(state, document, settings),
|
||||||
|
...getScreenDirectiveDiagnostics(state, document, settings),
|
||||||
|
]
|
||||||
: []),
|
: []),
|
||||||
]
|
]
|
||||||
: []
|
: []
|
||||||
|
|
|
@ -40,6 +40,7 @@ const defaultSettings: Settings = {
|
||||||
lint: {
|
lint: {
|
||||||
utilityConflicts: 'warning',
|
utilityConflicts: 'warning',
|
||||||
unsupportedApply: 'error',
|
unsupportedApply: 'error',
|
||||||
|
unknownScreen: 'error',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
let globalSettings: Settings = defaultSettings
|
let globalSettings: Settings = defaultSettings
|
||||||
|
|
|
@ -296,7 +296,7 @@ export function findClassListsInDocument(
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
function indexToPosition(str: string, index: number): Position {
|
export function indexToPosition(str: string, index: number): Position {
|
||||||
const { line, col } = lineColumn(str + '\n', index)
|
const { line, col } = lineColumn(str + '\n', index)
|
||||||
return { line: line - 1, character: col - 1 }
|
return { line: line - 1, character: col - 1 }
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ export type Settings = {
|
||||||
lint: {
|
lint: {
|
||||||
utilityConflicts: DiagnosticSeveritySetting
|
utilityConflicts: DiagnosticSeveritySetting
|
||||||
unsupportedApply: DiagnosticSeveritySetting
|
unsupportedApply: DiagnosticSeveritySetting
|
||||||
|
unknownScreen: DiagnosticSeveritySetting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue