Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat (no-invalid-extends): new rule #96

Merged
merged 2 commits into from
Jul 23, 2023
Merged

Conversation

43081j
Copy link
Owner

@43081j 43081j commented Jul 23, 2023

Enforces that custom elements extend from a list of allowed classes.

By default, the only allowed class is HTMLElement unless you use the extends option when defining the element. In those cases, it must extend the known built-in class (e.g. HTMLDivElement).

For example:

// invalid

/** @customElement */
class Foo extends Bar {}
customElements.define('foo', Foo);

// valid

/** @customElement */
class Foo extends HTMLElement {}
customElements.define('foo', Foo);

// also valid

/** @customElement */
class Foo extends HTMLDivElement {}
customElements.define('foo', Foo, {extends: 'div'});

// also invalid

/** @customElement */
class Foo extends HTMLDivElement {}
customElements.define('foo', Foo);

cc @keithamus

Enforces that custom elements extend from a list of allowed classes.

By default, the only allowed class is `HTMLElement` unless you use the
`extends` option when defining the element. In those cases, it must
extend the known built-in class (e.g. HTMLDivElement).

For example:

```ts
// invalid

/** @CustomElement */
class Foo extends Bar {}
customElements.define('foo', Foo);

// valid

/** @CustomElement */
class Foo extends HTMLElement {}
customElements.define('foo', Foo);

// also valid

/** @CustomElement */
class Foo extends HTMLDivElement {}
customElements.define('foo', Foo, {extends: 'div'});

// also invalid

/** @CustomElement */
class Foo extends HTMLDivElement {}
customElements.define('foo', Foo);
```
Copy link
Collaborator

@keithamus keithamus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks real nice!

@43081j
Copy link
Owner Author

43081j commented Jul 23, 2023

also dropped node 12 from CI since this moves to outputting es2021 (i.e. optional chaining)

think we should be ok, though may break some old school consumers but at least they can stay on the old version

@43081j 43081j merged commit f887a3e into ce-next Jul 23, 2023
4 checks passed
@43081j 43081j deleted the ce-next-invalid-extends branch July 23, 2023 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants