diff --git a/.changeset/slow-parents-sin.md b/.changeset/slow-parents-sin.md new file mode 100644 index 00000000..4f5866d5 --- /dev/null +++ b/.changeset/slow-parents-sin.md @@ -0,0 +1,7 @@ +--- +"@jackolope/lit-analyzer": patch +"@jackolope/ts-lit-plugin": patch +"lit-analyzer-plugin": patch +--- + +Fix: Update no-missing-import rule to avoid reporting on any listed globalTags diff --git a/packages/lit-analyzer/src/lib/rules/no-missing-import.ts b/packages/lit-analyzer/src/lib/rules/no-missing-import.ts index 5cad06b7..47786b05 100644 --- a/packages/lit-analyzer/src/lib/rules/no-missing-import.ts +++ b/packages/lit-analyzer/src/lib/rules/no-missing-import.ts @@ -22,6 +22,10 @@ const rule: RuleModule = { const isCustomElement = isCustomElementTagName(htmlNode.tagName); if (!isCustomElement) return; + // Return if this is listed as one of the always present `globalTags` in the config + const isGlobalTag = context.config.globalTags.includes(htmlNode.tagName); + if (isGlobalTag) return; + // Don't continue if this tag name doesn't have a definition. // If the html tag doesn't have a definition we won't know how to import it. const definition = definitionStore.getDefinitionForTagName(htmlNode.tagName); diff --git a/packages/lit-analyzer/src/test/rules/no-missing-import.ts b/packages/lit-analyzer/src/test/rules/no-missing-import.ts index c57b30ea..0f996d6b 100644 --- a/packages/lit-analyzer/src/test/rules/no-missing-import.ts +++ b/packages/lit-analyzer/src/test/rules/no-missing-import.ts @@ -9,6 +9,13 @@ tsTest("Report missing imports of custom elements", t => { hasDiagnostic(t, diagnostics, "no-missing-import"); }); +tsTest("Report missing imports of custom elements with a type-only import", t => { + const { diagnostics } = getDiagnostics([makeElement({}), "import type {} from './my-element'; html``"], { + rules: { "no-missing-import": true } + }); + hasDiagnostic(t, diagnostics, "no-missing-import"); +}); + tsTest("Don't report missing imports when the custom element has been imported 1", t => { const { diagnostics } = getDiagnostics([makeElement({}), "import './my-element'; html``"], { rules: { "no-missing-import": true } @@ -31,6 +38,14 @@ tsTest("Don't report missing imports when the custom element has been imported 2 hasNoDiagnostics(t, diagnostics); }); +tsTest("Don't report missing imports when the custom element is included in the globalTags config", t => { + const { diagnostics } = getDiagnostics([makeElement({}), "html``"], { + rules: { "no-missing-import": true }, + globalTags: ["my-element"] + }); + hasNoDiagnostics(t, diagnostics); +}); + tsTest("Suggest adding correct import statement", t => { const fileContentWithMissingImport = "html``"; const elementTagWithoutImport = "my-element";