From 208daf838c2736397b233265ffc2a958c87acd67 Mon Sep 17 00:00:00 2001 From: Jack Robards Date: Mon, 7 Jul 2025 12:59:27 -0500 Subject: [PATCH 1/3] fix: Update no-missing-import rule to avoid reporting on any listed globalTags --- packages/lit-analyzer/src/lib/rules/no-missing-import.ts | 4 ++++ 1 file changed, 4 insertions(+) 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); From 5121f5f7c1d83b9ec6aa85a1481be6ba31ebb2cb Mon Sep 17 00:00:00 2001 From: Jack Robards Date: Mon, 7 Jul 2025 13:14:17 -0500 Subject: [PATCH 2/3] chore: Add tests to no-missing-import rule for globalTags config and type-only imports --- .../src/test/rules/no-missing-import.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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"; From 1abcf43c0dfcb17e9a256d0468f047c62121ea6a Mon Sep 17 00:00:00 2001 From: Jack Robards Date: Mon, 7 Jul 2025 13:17:36 -0500 Subject: [PATCH 3/3] chore: Add changeset --- .changeset/slow-parents-sin.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/slow-parents-sin.md 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