Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/slow-parents-sin.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions packages/lit-analyzer/src/lib/rules/no-missing-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions packages/lit-analyzer/src/test/rules/no-missing-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`<my-element></my-element>`"], {
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`<my-element></my-element>`"], {
rules: { "no-missing-import": true }
Expand All @@ -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`<my-element></my-element>`"], {
rules: { "no-missing-import": true },
globalTags: ["my-element"]
});
hasNoDiagnostics(t, diagnostics);
});

tsTest("Suggest adding correct import statement", t => {
const fileContentWithMissingImport = "html`<my-element></my-element>`";
const elementTagWithoutImport = "my-element";
Expand Down
Loading