From 216df45874dcbd0e4f98969221d156bc4083b2cd Mon Sep 17 00:00:00 2001 From: Michael Bullington Date: Tue, 8 Feb 2022 12:14:35 -0500 Subject: [PATCH] fix: :bug: Cross reference no-customized-built-in-elements with builtInTagMap This may change the actual (not expected) behavior of no-customized-built-in-elements in slight ways --- lib/rules/no-customized-built-in-elements.js | 8 +++++++- test/no-customized-built-in-elements.js | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/rules/no-customized-built-in-elements.js b/lib/rules/no-customized-built-in-elements.js index 566cc26..7fb2c91 100644 --- a/lib/rules/no-customized-built-in-elements.js +++ b/lib/rules/no-customized-built-in-elements.js @@ -1,4 +1,6 @@ const s = require('../custom-selectors') +const {builtInTagMap} = require('../tag-names') + module.exports = { meta: { type: 'problem', @@ -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') } } diff --git a/test/no-customized-built-in-elements.js b/test/no-customized-built-in-elements.js index 6ba1fab..98d328a 100644 --- a/test/no-customized-built-in-elements.js +++ b/test/no-customized-built-in-elements.js @@ -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: [ {