Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #39 from mbullington/built-in-elements-cross-ref
Browse files Browse the repository at this point in the history
Limit `no-customized-built-in-elements` to built ins
  • Loading branch information
koddsson authored Feb 11, 2022
2 parents 911d30c + 216df45 commit 7bed82c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/rules/no-customized-built-in-elements.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const s = require('../custom-selectors')
const {builtInTagMap} = require('../tag-names')

module.exports = {
meta: {
type: 'problem',
Expand All @@ -8,7 +10,11 @@ module.exports = {
create(context) {
return {
[s.HTMLElementClass](node) {
if (node.superClass && node.superClass.name !== 'HTMLElement') {
if (
node.superClass &&
node.superClass.name !== 'HTMLElement' &&
Object.values(builtInTagMap).includes(node.superClass.name)
) {
context.report(node, 'Avoid extending built-in elements')
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/no-customized-built-in-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ ruleTester.run('no-customized-built-in-elements', rule, {
{code: 'class SomeMap extends Map { }'},
{code: 'class FooBarElement { }'},
{code: 'class FooBarElement extends HTMLElement { }'},
{code: 'const FooBarElement = class extends HTMLElement { }'}
{code: 'const FooBarElement = class extends HTMLElement { }'},
{code: 'const FooBarElement = class extends HTMLRandomNotBuiltInElement { }'}
],
invalid: [
{
Expand Down

0 comments on commit 7bed82c

Please sign in to comment.