add initial "unsupported tailwind directive" lint rule
parent
2c2f63a0b8
commit
81aad28bc8
15
package.json
15
package.json
|
@ -149,6 +149,21 @@
|
||||||
"",
|
"",
|
||||||
""
|
""
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"tailwindCSS.lint.unsupportedTailwindDirective": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"ignore",
|
||||||
|
"warning",
|
||||||
|
"error"
|
||||||
|
],
|
||||||
|
"default": "error",
|
||||||
|
"markdownDescription": "",
|
||||||
|
"markdownEnumDescriptions": [
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
""
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { getClassNameDecls } from '../util/getClassNameDecls'
|
||||||
import { equal, flatten } from '../../util/array'
|
import { equal, flatten } from '../../util/array'
|
||||||
import { getDocumentSettings } from '../util/getDocumentSettings'
|
import { getDocumentSettings } from '../util/getDocumentSettings'
|
||||||
const dlv = require('dlv')
|
const dlv = require('dlv')
|
||||||
|
import semver from 'semver'
|
||||||
|
|
||||||
function getUnsupportedApplyDiagnostics(
|
function getUnsupportedApplyDiagnostics(
|
||||||
state: State,
|
state: State,
|
||||||
|
@ -265,6 +266,50 @@ function getUnknownConfigKeyDiagnostics(
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getUnsupportedTailwindDirectiveDiagnostics(
|
||||||
|
state: State,
|
||||||
|
document: TextDocument,
|
||||||
|
settings: Settings
|
||||||
|
): Diagnostic[] {
|
||||||
|
let severity = settings.lint.unsupportedTailwindDirective
|
||||||
|
if (severity === 'ignore') return []
|
||||||
|
|
||||||
|
let text = document.getText()
|
||||||
|
let matches = findAll(/(?:\s|^)@tailwind\s+(?<value>[^;]+)/g, text)
|
||||||
|
|
||||||
|
let allowed = [
|
||||||
|
'utilities',
|
||||||
|
'components',
|
||||||
|
'screens',
|
||||||
|
semver.gte(state.version, '1.0.0-beta.1') ? 'base' : 'preflight',
|
||||||
|
]
|
||||||
|
|
||||||
|
return matches
|
||||||
|
.map((match) => {
|
||||||
|
if (allowed.includes(match.groups.value)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
range: {
|
||||||
|
start: indexToPosition(
|
||||||
|
text,
|
||||||
|
match.index + match[0].length - match.groups.value.length
|
||||||
|
),
|
||||||
|
end: indexToPosition(text, match.index + match[0].length),
|
||||||
|
},
|
||||||
|
severity:
|
||||||
|
severity === 'error'
|
||||||
|
? DiagnosticSeverity.Error
|
||||||
|
: DiagnosticSeverity.Warning,
|
||||||
|
message: `Unsupported value: ${match.groups.value}${
|
||||||
|
match.groups.value === 'preflight' ? '. Use base instead.' : ''
|
||||||
|
}`,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(Boolean)
|
||||||
|
}
|
||||||
|
|
||||||
export async function provideDiagnostics(
|
export async function provideDiagnostics(
|
||||||
state: State,
|
state: State,
|
||||||
document: TextDocument
|
document: TextDocument
|
||||||
|
@ -280,6 +325,11 @@ export async function provideDiagnostics(
|
||||||
...getUnknownScreenDiagnostics(state, document, settings),
|
...getUnknownScreenDiagnostics(state, document, settings),
|
||||||
...getUnknownVariantDiagnostics(state, document, settings),
|
...getUnknownVariantDiagnostics(state, document, settings),
|
||||||
...getUnknownConfigKeyDiagnostics(state, document, settings),
|
...getUnknownConfigKeyDiagnostics(state, document, settings),
|
||||||
|
...getUnsupportedTailwindDirectiveDiagnostics(
|
||||||
|
state,
|
||||||
|
document,
|
||||||
|
settings
|
||||||
|
),
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
]
|
]
|
||||||
|
|
|
@ -43,6 +43,7 @@ const defaultSettings: Settings = {
|
||||||
unknownScreen: 'error',
|
unknownScreen: 'error',
|
||||||
unknownVariant: 'error',
|
unknownVariant: 'error',
|
||||||
unknownConfigKey: 'error',
|
unknownConfigKey: 'error',
|
||||||
|
unsupportedTailwindDirective: 'error',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
let globalSettings: Settings = defaultSettings
|
let globalSettings: Settings = defaultSettings
|
||||||
|
|
|
@ -37,6 +37,7 @@ export type Settings = {
|
||||||
unknownScreen: DiagnosticSeveritySetting
|
unknownScreen: DiagnosticSeveritySetting
|
||||||
unknownVariant: DiagnosticSeveritySetting
|
unknownVariant: DiagnosticSeveritySetting
|
||||||
unknownConfigKey: DiagnosticSeveritySetting
|
unknownConfigKey: DiagnosticSeveritySetting
|
||||||
|
unsupportedTailwindDirective: DiagnosticSeveritySetting
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue