Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
add initial "unknown config key" lint rule
Brad Cornes <bradlc41@gmail.com>
4 years ago
4 changed files, 67 additions(+), 0 deletions(-)
M package.json -> package.json
diff --git a/package.json b/package.json
index 5992723278fc2e10c501a3165d3509a1754294b3..0aa66cb573a5d20b01a4468772dfae745f0cda5a 100755
--- a/package.json
+++ b/package.json
@@ -134,6 +134,21 @@             "",
             "",
             ""
           ]
+        },
+        "tailwindCSS.lint.unknownConfigKey": {
+          "type": "string",
+          "enum": [
+            "ignore",
+            "warning",
+            "error"
+          ],
+          "default": "error",
+          "markdownDescription": "",
+          "markdownEnumDescriptions": [
+            "",
+            "",
+            ""
+          ]
         }
       }
     }
M src/lsp/providers/diagnosticsProvider.ts -> src/lsp/providers/diagnosticsProvider.ts
diff --git a/src/lsp/providers/diagnosticsProvider.ts b/src/lsp/providers/diagnosticsProvider.ts
index bf87c9fc7a7d2cccd86fb8276845244f8baa3580..18f3bc50f69c3b45bea242b280564e42d252fe90 100644
--- a/src/lsp/providers/diagnosticsProvider.ts
+++ b/src/lsp/providers/diagnosticsProvider.ts
@@ -218,6 +218,55 @@   )
 }
 
 import {
+  const classLists = findClassListsInDocument(state, document)
+  state: State,
+  document: TextDocument,
+  settings: Settings
+): Diagnostic[] {
+  let severity = settings.lint.unknownConfigKey
+  if (severity === 'ignore') return []
+
+  let text = document.getText()
+  let matches = findAll(
+    /(?<prefix>\s|^)(?<helper>config|theme)\((?<quote>['"])(?<key>[^)]+)\k<quote>\)/g,
+    text
+  )
+
+  return matches
+    .map((match) => {
+      let base = match.groups.helper === 'theme' ? ['theme'] : []
+      let keys = match.groups.key.split(/[.\[\]]/).filter(Boolean)
+      let value = dlv(state.config, [...base, ...keys])
+
+      // TODO: check that the type is valid
+      // e.g. objects are not valid
+      if (typeof value !== 'undefined') {
+        return null
+      }
+
+      let startIndex =
+        match.index +
+        match.groups.prefix.length +
+        match.groups.helper.length +
+        1 + // open paren
+        match.groups.quote.length
+
+      return {
+        range: {
+          start: indexToPosition(text, startIndex),
+          end: indexToPosition(text, startIndex + match.groups.key.length),
+        },
+        severity:
+          severity === 'error'
+            ? DiagnosticSeverity.Error
+            : DiagnosticSeverity.Warning,
+        message: `Unknown ${match.groups.helper} key: ${match.groups.key}`,
+      }
+    })
+    .filter(Boolean)
+}
+
+import {
           message = `\`@apply\` cannot be used with \`.${className}\` because its definition includes a pseudo-selector (${meta.pseudo[0]})`
   state: State,
   document: TextDocument
@@ -232,6 +281,7 @@           ? [
               ...getUnsupportedApplyDiagnostics(state, document, settings),
               ...getUnknownScreenDiagnostics(state, document, settings),
               ...getUnknownVariantDiagnostics(state, document, settings),
+              ...getUnknownConfigKeyDiagnostics(state, document, settings),
             ]
           : []),
       ]
M src/lsp/server.ts -> src/lsp/server.ts
diff --git a/src/lsp/server.ts b/src/lsp/server.ts
index c3cefc3dd7ab8ac6be4d7e65662a8f87da824ee4..3c97071aadce03b25d43372f562207764156de7c 100644
--- a/src/lsp/server.ts
+++ b/src/lsp/server.ts
@@ -42,6 +42,7 @@     utilityConflicts: 'warning',
     unsupportedApply: 'error',
     unknownScreen: 'error',
     unknownVariant: 'error',
+    unknownConfigKey: 'error',
   },
 }
 let globalSettings: Settings = defaultSettings
M src/lsp/util/state.ts -> src/lsp/util/state.ts
diff --git a/src/lsp/util/state.ts b/src/lsp/util/state.ts
index f4d8a9f37ef3f3ae42adcd6b8e8d638754fa2836..45f4106e87a1cc3701390b9d1c07b43076cc4c60 100644
--- a/src/lsp/util/state.ts
+++ b/src/lsp/util/state.ts
@@ -36,6 +36,7 @@     utilityConflicts: DiagnosticSeveritySetting
     unsupportedApply: DiagnosticSeveritySetting
     unknownScreen: DiagnosticSeveritySetting
     unknownVariant: DiagnosticSeveritySetting
+    unknownConfigKey: DiagnosticSeveritySetting
   }
 }