Skip to content

Instantly share code, notes, and snippets.

@Ruben-E
Created December 13, 2021 15:23
Show Gist options
  • Select an option

  • Save Ruben-E/091c96ea508ce8fb33eec59d324bdfab to your computer and use it in GitHub Desktop.

Select an option

Save Ruben-E/091c96ea508ce8fb33eec59d324bdfab to your computer and use it in GitHub Desktop.

Revisions

  1. Ruben-E created this gist Dec 13, 2021.
    328 changes: 328 additions & 0 deletions test.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,328 @@
    // SOURCE: https://github.com/ionic-team/stencil-eslint/blob/main/src/rules/reserved-member-names.ts

    const HTML_ELEMENT_KEYS = [
    "title",
    "lang",
    "translate",
    "dir",
    // 'dataset',
    // 'hidden',
    "tabIndex",
    "accessKey",
    "draggable",
    // 'spellcheck',
    // 'autocapitalize',
    "contentEditable",
    "isContentEditable",
    // 'inputMode',
    "offsetParent",
    "offsetTop",
    "offsetLeft",
    "offsetWidth",
    "offsetHeight",
    "style",
    "innerText",
    "outerText",
    "oncopy",
    "oncut",
    "onpaste",
    "onabort",
    "onblur",
    "oncancel",
    "oncanplay",
    "oncanplaythrough",
    "onchange",
    "onclick",
    "onclose",
    "oncontextmenu",
    "oncuechange",
    "ondblclick",
    "ondrag",
    "ondragend",
    "ondragenter",
    "ondragleave",
    "ondragover",
    "ondragstart",
    "ondrop",
    "ondurationchange",
    "onemptied",
    "onended",
    "onerror",
    "onfocus",
    "oninput",
    "oninvalid",
    "onkeydown",
    "onkeypress",
    "onkeyup",
    "onload",
    "onloadeddata",
    "onloadedmetadata",
    "onloadstart",
    "onmousedown",
    "onmouseenter",
    "onmouseleave",
    "onmousemove",
    "onmouseout",
    "onmouseover",
    "onmouseup",
    "onmousewheel",
    "onpause",
    "onplay",
    "onplaying",
    "onprogress",
    "onratechange",
    "onreset",
    "onresize",
    "onscroll",
    "onseeked",
    "onseeking",
    "onselect",
    "onstalled",
    "onsubmit",
    "onsuspend",
    "ontimeupdate",
    "ontoggle",
    "onvolumechange",
    "onwaiting",
    "onwheel",
    "onauxclick",
    "ongotpointercapture",
    "onlostpointercapture",
    "onpointerdown",
    "onpointermove",
    "onpointerup",
    "onpointercancel",
    "onpointerover",
    "onpointerout",
    "onpointerenter",
    "onpointerleave",
    "onselectstart",
    "onselectionchange",
    "nonce",
    "click",
    "focus",
    "blur",
    ];

    const ELEMENT_KEYS = [
    "namespaceURI",
    "prefix",
    "localName",
    "tagName",
    "id",
    "className",
    "classList",
    "slot",
    "attributes",
    "shadowRoot",
    "assignedSlot",
    "innerHTML",
    "outerHTML",
    "scrollTop",
    "scrollLeft",
    "scrollWidth",
    "scrollHeight",
    "clientTop",
    "clientLeft",
    "clientWidth",
    "clientHeight",
    "attributeStyleMap",
    "onbeforecopy",
    "onbeforecut",
    "onbeforepaste",
    "onsearch",
    "previousElementSibling",
    "nextElementSibling",
    "children",
    "firstElementChild",
    "lastElementChild",
    "childElementCount",
    "onfullscreenchange",
    "onfullscreenerror",
    "onwebkitfullscreenchange",
    "onwebkitfullscreenerror",
    "setPointerCapture",
    "releasePointerCapture",
    "hasPointerCapture",
    "hasAttributes",
    "getAttributeNames",
    "getAttribute",
    "getAttributeNS",
    "setAttribute",
    "setAttributeNS",
    "removeAttribute",
    "removeAttributeNS",
    "hasAttribute",
    "hasAttributeNS",
    "toggleAttribute",
    "getAttributeNode",
    "getAttributeNodeNS",
    "setAttributeNode",
    "setAttributeNodeNS",
    "removeAttributeNode",
    "closest",
    "matches",
    "webkitMatchesSelector",
    "attachShadow",
    "getElementsByTagName",
    "getElementsByTagNameNS",
    "getElementsByClassName",
    "insertAdjacentElement",
    "insertAdjacentText",
    "insertAdjacentHTML",
    "requestPointerLock",
    "getClientRects",
    "getBoundingClientRect",
    "scrollIntoView",
    "scroll",
    "scrollTo",
    "scrollBy",
    "scrollIntoViewIfNeeded",
    "animate",
    "computedStyleMap",
    "before",
    "after",
    "replaceWith",
    "remove",
    "prepend",
    "append",
    "querySelector",
    "querySelectorAll",
    "requestFullscreen",
    "webkitRequestFullScreen",
    "webkitRequestFullscreen",
    "part",
    "createShadowRoot",
    "getDestinationInsertionPoints",
    ];

    const NODE_KEYS = [
    "ELEMENT_NODE",
    "ATTRIBUTE_NODE",
    "TEXT_NODE",
    "CDATA_SECTION_NODE",
    "ENTITY_REFERENCE_NODE",
    "ENTITY_NODE",
    "PROCESSING_INSTRUCTION_NODE",
    "COMMENT_NODE",
    "DOCUMENT_NODE",
    "DOCUMENT_TYPE_NODE",
    "DOCUMENT_FRAGMENT_NODE",
    "NOTATION_NODE",
    "DOCUMENT_POSITION_DISCONNECTED",
    "DOCUMENT_POSITION_PRECEDING",
    "DOCUMENT_POSITION_FOLLOWING",
    "DOCUMENT_POSITION_CONTAINS",
    "DOCUMENT_POSITION_CONTAINED_BY",
    "DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC",
    "nodeType",
    "nodeName",
    "baseURI",
    "isConnected",
    "ownerDocument",
    "parentNode",
    "parentElement",
    "childNodes",
    "firstChild",
    "lastChild",
    "previousSibling",
    "nextSibling",
    "nodeValue",
    "textContent",
    "hasChildNodes",
    "getRootNode",
    "normalize",
    "cloneNode",
    "isEqualNode",
    "isSameNode",
    "compareDocumentPosition",
    "contains",
    "lookupPrefix",
    "lookupNamespaceURI",
    "isDefaultNamespace",
    "insertBefore",
    "appendChild",
    "replaceChild",
    "removeChild",
    ];

    const JSX_KEYS = ["ref", "key"];

    const RESERVED_PUBLIC_MEMBERS = new Set(
    [...HTML_ELEMENT_KEYS, ...ELEMENT_KEYS, ...NODE_KEYS, ...JSX_KEYS].map((p) =>
    p.toLowerCase()
    )
    );

    function isReservedMember(memberName: string) {
    memberName = memberName.toLowerCase();
    return RESERVED_PUBLIC_MEMBERS.has(memberName);
    }

    // SOURCE: https://github.com/ionic-team/stencil/blob/main/src/declarations/stencil-public-runtime.ts#L1238

    const stencilHTMLAttributes = [
    "innerHTML",
    "accessKey",
    "class",
    "contentEditable",
    "contenteditable",
    "contextMenu",
    "contextmenu",
    "dir",
    "draggable",
    "hidden",
    "id",
    "lang",
    "spellcheck",
    "style",
    "tabIndex",
    "tabindex?",
    "title",
    "inputMode",
    "inputmode",
    "enterKeyHint",
    "enterkeyhint",
    "is",
    "radioGroup",
    "radiogroup",
    "role",
    "about",
    "datatype",
    "inlist",
    "prefix",
    "property",
    "resource",
    "typeof",
    "vocab",
    "autoCapitalize",
    "autocapitalize",
    "autoCorrect",
    "autocorrect",
    "autoSave",
    "autosave",
    "color",
    "itemProp",
    "itemprop",
    "itemScope",
    "itemscope",
    "itemType",
    "itemtype",
    "itemID",
    "itemid",
    "itemRef",
    "itemref",
    "results",
    "security",
    "unselectable",
    ];

    // CHECK

    console.log(
    new Set(
    stencilHTMLAttributes
    .map((a) => a.toLowerCase())
    .filter((a) => !isReservedMember(a))
    )
    );