UNPKG

eslint-plugin-sonarjs

Version:
141 lines (140 loc) 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decorate = void 0; const helpers_1 = require("../helpers"); const meta_1 = require("./meta"); function decorate(rule) { return (0, helpers_1.interceptReport)({ ...rule, meta: (0, helpers_1.generateMeta)(meta_1.meta, rule.meta), }, (context, reportDescriptor) => { const { node } = reportDescriptor; const parent = node.parent; if (parent.children !== undefined) { for (const child of parent.children) { if (child.type === 'JSXElement' && isCustomComponent(child)) { // we ignore the issue return; } } } const name = node.name; context.report({ ...reportDescriptor, node: name }); }); } exports.decorate = decorate; function isCustomComponent(node) { return !KNOWN_HTML_TAGS.has(node.openingElement.name.name); } const KNOWN_HTML_TAGS = new Set([ 'a', 'area', 'abbr', 'address', 'article', 'aside', 'audio', 'b', 'base', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'menu', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'search', 'section', 'select', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'svg', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr', ]);