Skip to content

Commit 5017664

Browse files
committed
Finish refactor of components and test helpers to LitElements
1 parent 827b263 commit 5017664

4 files changed

Lines changed: 24 additions & 23 deletions

File tree

_TODO.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -269,22 +269,3 @@ This article has different approaches to [print pagination](https://www.customjs
269269
- cover.jpg for reliability-and-testing needs touch up in GIMP
270270
- We need to check for short form and deep article articles where the deep-dive index.pdf has a non-featured tag lik "argo-cd" only in the pdf.mdx. In those cases, we should make sure the callout for the deep dive includes the name of that non-featured (technology) tag and add the name to the tags: frontmatter key in the index.mdx
271271
- Need an article on OpenStack
272-
273-
## HTMLElement vs. extends HTMLElement
274-
275-
A bunch of our web components extend directly from HTMLElement instead of following the instructions to extend LitElement.
276-
277-
- Consent/Banner
278-
- Consent/Checkbox
279-
- Consent/Preferences
280-
281-
The WebComponentModule type in this file is used throughout component scripts:
282-
283-
`src/components/scripts/@types/webComponentModule.ts`
284-
285-
There are testing fixtures that might be targeting HTMLElement instead of LitElement:
286-
287-
`isLikelyWebComponent()` in `test/eslint/enforce-centralized-events-rule.ts`
288-
line 113 in `test/eslint/__tests__/enforce-centralized-events-rule.spec.ts`
289-
290-
interface `ElementWithTestProperties` in `test/e2e/assertions/index.ts`

src/components/scripts/@types/webComponentModule.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export interface WebComponentModule<TElement extends HTMLElement = HTMLElement> {
1+
import type { LitElement } from 'lit'
2+
3+
export interface WebComponentModule<TElement extends HTMLElement = LitElement> {
24
registeredName: string
35
componentCtor: CustomElementConstructor & { prototype: TElement }
46
registerWebComponent: (_tagName?: string) => Promise<void> | void

test/eslint/__tests__/enforce-centralized-events-rule.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ describe('enforce-centralized-events', () => {
116116
this.addEventListener('keyup', this.handleKeyUp);
117117
}
118118
}
119+
`,
120+
filename: 'src/components/MyComponent/index.ts',
121+
},
122+
123+
// ========================================
124+
// Valid: LitElement web components
125+
// ========================================
126+
{
127+
code: `
128+
import { LitElement } from 'lit';
129+
130+
class MyComponent extends LitElement {
131+
connectedCallback() {
132+
super.connectedCallback();
133+
this.addEventListener('click', this.handleClick);
134+
this.addEventListener('keyup', this.handleKeyUp);
135+
}
136+
}
119137
`,
120138
filename: 'src/components/MyComponent/index.ts',
121139
},

test/eslint/enforce-centralized-events-rule.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const enforceCentralizedEventsRule: Rule.RuleModule = {
7878
let foundWebComponent = false
7979
const visitorKeys = sourceCode.visitorKeys ?? {}
8080

81-
const isHTMLElementSubclass = (node: Node): boolean => {
81+
const isWebComponentSubclass = (node: Node): boolean => {
8282
if (node.type !== 'ClassDeclaration' && node.type !== 'ClassExpression') {
8383
return false
8484
}
@@ -87,14 +87,14 @@ const enforceCentralizedEventsRule: Rule.RuleModule = {
8787
return Boolean(
8888
superClass &&
8989
superClass.type === 'Identifier' &&
90-
superClass.name === 'HTMLElement',
90+
(superClass.name === 'HTMLElement' || superClass.name === 'LitElement'),
9191
)
9292
}
9393

9494
const checkNode = (astNode: Node | null | undefined): void => {
9595
if (!astNode || foundWebComponent) return
9696

97-
if (isHTMLElementSubclass(astNode)) {
97+
if (isWebComponentSubclass(astNode)) {
9898
foundWebComponent = true
9999
return
100100
}

0 commit comments

Comments
 (0)