diff --git a/lib/utils/deprecated-html-elements.json b/lib/utils/deprecated-html-elements.json index daf23f512..63a3f7162 100644 --- a/lib/utils/deprecated-html-elements.json +++ b/lib/utils/deprecated-html-elements.json @@ -1 +1,31 @@ -["acronym","applet","basefont","bgsound","big","blink","center","command","content","dir","element","font","frame","frameset","image","isindex","keygen","listing","marquee","menuitem","multicol","nextid","nobr","noembed","noframes","plaintext","shadow","spacer","strike","tt","xmp"] \ No newline at end of file +[ + "acronym", + "applet", + "basefont", + "bgsound", + "big", + "blink", + "center", + "dir", + "font", + "frame", + "frameset", + "isindex", + "keygen", + "listing", + "marquee", + "menuitem", + "multicol", + "nextid", + "nobr", + "noembed", + "noframes", + "param", + "plaintext", + "rb", + "rtc", + "spacer", + "strike", + "tt", + "xmp" +] diff --git a/lib/utils/html-elements.json b/lib/utils/html-elements.json index 721f7876d..cd30177fa 100644 --- a/lib/utils/html-elements.json +++ b/lib/utils/html-elements.json @@ -1 +1,113 @@ -["html","body","base","head","link","meta","style","title","address","article","aside","footer","header","h1","h2","h3","h4","h5","h6","hgroup","nav","section","div","dd","dl","dt","figcaption","figure","hr","img","li","main","ol","p","pre","ul","a","b","abbr","bdi","bdo","br","cite","code","data","dfn","em","i","kbd","mark","q","rp","rt","rtc","ruby","s","samp","small","span","strong","sub","sup","time","u","var","wbr","area","audio","map","track","video","embed","object","param","source","canvas","script","noscript","del","ins","caption","col","colgroup","table","thead","tbody","tfoot","td","th","tr","button","datalist","fieldset","form","input","label","legend","meter","optgroup","option","output","progress","select","textarea","details","dialog","menu","menuitem","summary","content","element","shadow","template","slot","blockquote","iframe","noframes","picture"] +[ + "a", + "abbr", + "address", + "area", + "article", + "aside", + "audio", + "b", + "base", + "bdi", + "bdo", + "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", + "html", + "i", + "iframe", + "img", + "input", + "ins", + "kbd", + "label", + "legend", + "li", + "link", + "main", + "map", + "mark", + "menu", + "meta", + "meter", + "nav", + "noscript", + "object", + "ol", + "optgroup", + "option", + "output", + "p", + "picture", + "pre", + "progress", + "q", + "rp", + "rt", + "ruby", + "s", + "samp", + "script", + "section", + "select", + "slot", + "small", + "source", + "span", + "strong", + "style", + "sub", + "summary", + "sup", + "table", + "tbody", + "td", + "template", + "textarea", + "tfoot", + "th", + "thead", + "time", + "title", + "tr", + "track", + "u", + "ul", + "var", + "video", + "wbr" +] diff --git a/lib/utils/svg-elements.json b/lib/utils/svg-elements.json index aaee2e6f3..f214aad24 100644 --- a/lib/utils/svg-elements.json +++ b/lib/utils/svg-elements.json @@ -1 +1,65 @@ -["a","animate","animateMotion","animateTransform","audio","canvas","circle","clipPath","defs","desc","discard","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","foreignObject","g","iframe","image","line","linearGradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialGradient","rect","script","set","stop","style","svg","switch","symbol","text","textPath","title","tspan","unknown","use","video","view"] +[ + "a", + "animate", + "animateMotion", + "animateTransform", + "circle", + "clipPath", + "defs", + "desc", + "ellipse", + "feBlend", + "feColorMatrix", + "feComponentTransfer", + "feComposite", + "feConvolveMatrix", + "feDiffuseLighting", + "feDisplacementMap", + "feDistantLight", + "feDropShadow", + "feFlood", + "feFuncA", + "feFuncB", + "feFuncG", + "feFuncR", + "feGaussianBlur", + "feImage", + "feMerge", + "feMergeNode", + "feMorphology", + "feOffset", + "fePointLight", + "feSpecularLighting", + "feSpotLight", + "feTile", + "feTurbulence", + "filter", + "foreignObject", + "g", + "image", + "line", + "linearGradient", + "marker", + "mask", + "metadata", + "mpath", + "path", + "pattern", + "polygon", + "polyline", + "radialGradient", + "rect", + "script", + "set", + "stop", + "style", + "svg", + "switch", + "symbol", + "text", + "textPath", + "title", + "tspan", + "use", + "view" +] diff --git a/package.json b/package.json index a1b04d855..89ed35344 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "mocha": "^10.0.0", "nyc": "^15.1.0", "prettier": "^2.6.2", - "typescript": "^4.9.3", + "typescript": "^5.0.4", "vitepress": "^1.0.0-alpha.29" } } diff --git a/tests/lib/rules/no-reserved-component-names.js b/tests/lib/rules/no-reserved-component-names.js index d9114810b..3ddc74dca 100644 --- a/tests/lib/rules/no-reserved-component-names.js +++ b/tests/lib/rules/no-reserved-component-names.js @@ -279,8 +279,6 @@ const invalidElements = [ 'Defs', 'desc', 'Desc', - 'discard', - 'Discard', 'ellipse', 'Ellipse', 'feBlend', @@ -352,8 +350,6 @@ const invalidElements = [ 'textPath', 'tspan', 'Tspan', - 'unknown', - 'Unknown', 'use', 'Use', 'view', diff --git a/tools/lib/http.js b/tools/lib/http.js new file mode 100644 index 000000000..2be517c46 --- /dev/null +++ b/tools/lib/http.js @@ -0,0 +1,34 @@ +const https = require('https') +const { URL } = require('url') + +module.exports = { + httpGet +} +function httpGet(url) { + return new Promise((resolve, reject) => { + let result = '' + https + .get(url, (res) => { + if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400) { + // redirect + let redirectUrl = res.headers.location + if (!redirectUrl.startsWith('http')) { + const baseUrl = new URL(url) + baseUrl.pathname = redirectUrl + redirectUrl = String(baseUrl) + } + resolve(httpGet(redirectUrl)) + return + } + res.setEncoding('utf8') + res.on('data', (chunk) => { + result += String(chunk) + }) + res.on('end', () => { + resolve(result) + }) + res.on('error', reject) + }) + .on('error', reject) + }) +} diff --git a/tools/update-resources.js b/tools/update-resources.js new file mode 100644 index 000000000..2b62268d3 --- /dev/null +++ b/tools/update-resources.js @@ -0,0 +1,120 @@ +'use strict' + +const fs = require('fs') +const tsParser = require('@typescript-eslint/parser') +const { httpGet } = require('./lib/http') + +/** + * @typedef {import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration} TSInterfaceDeclaration + */ + +main() + +async function main() { + const libDomDTsText = await httpGet( + 'https://unpkg.com/typescript/lib/lib.dom.d.ts' + ) + const rootNode = tsParser.parse(libDomDTsText, { + loc: true, + range: true + }) + updateDeprecatedHTMLElements() + updateHTMLElements() + updateSVGElements() + + // ------------------------------------------------------------------------------ + // Update deprecated-html-elements.json + // ------------------------------------------------------------------------------ + function updateDeprecatedHTMLElements() { + const DEPRECATED_HTML_ELEMENTS_PATH = require.resolve( + '../lib/utils/deprecated-html-elements.json' + ) + const elements = new Set() + /** @type {TSInterfaceDeclaration} */ + const interfaceDeclaration = rootNode.body.find( + (body) => + body.type === 'TSInterfaceDeclaration' && + body.id.name === 'HTMLElementDeprecatedTagNameMap' + ) + + for (const name of extractPropNames(interfaceDeclaration)) { + elements.add(name) + } + + fs.writeFileSync( + DEPRECATED_HTML_ELEMENTS_PATH, + `${JSON.stringify([...elements].sort(), null, 2)}\n`, + 'utf8' + ) + } + + // ------------------------------------------------------------------------------ + // Update html-elements.json + // ------------------------------------------------------------------------------ + function updateHTMLElements() { + const HTML_ELEMENTS_PATH = require.resolve( + '../lib/utils/html-elements.json' + ) + const elements = new Set() + const deprecatedHtmlElements = new Set( + require('../lib/utils/deprecated-html-elements.json') + ) + /** @type {TSInterfaceDeclaration} */ + const interfaceDeclaration = rootNode.body.find( + (body) => + body.type === 'TSInterfaceDeclaration' && + body.id.name === 'HTMLElementTagNameMap' + ) + + for (const name of extractPropNames(interfaceDeclaration)) { + if (deprecatedHtmlElements.has(name)) { + continue + } + elements.add(name) + } + + fs.writeFileSync( + HTML_ELEMENTS_PATH, + `${JSON.stringify([...elements].sort(), null, 2)}\n`, + 'utf8' + ) + } + + // ------------------------------------------------------------------------------ + // Update svg-elements.json + // ------------------------------------------------------------------------------ + function updateSVGElements() { + const SVG_ELEMENTS_PATH = require.resolve('../lib/utils/svg-elements.json') + const elements = new Set() + /** @type {TSInterfaceDeclaration} */ + const interfaceDeclaration = rootNode.body.find( + (body) => + body.type === 'TSInterfaceDeclaration' && + body.id.name === 'SVGElementTagNameMap' + ) + + for (const name of extractPropNames(interfaceDeclaration)) { + elements.add(name) + } + + fs.writeFileSync( + SVG_ELEMENTS_PATH, + `${JSON.stringify([...elements].sort(), null, 2)}\n`, + 'utf8' + ) + } +} + +/** + * @param {TSInterfaceDeclaration} node + */ +function* extractPropNames(node) { + for (const m of node.body.body) { + if ( + (m.type === 'TSPropertySignature' || m.type === 'TSMethodSignature') && + (m.key.type === 'Identifier' || m.key.type === 'Literal') + ) { + yield m.key.type === 'Identifier' ? m.key.name : `${m.key.value}` + } + } +} diff --git a/tools/update-vue3-export-names.js b/tools/update-vue3-export-names.js index 8a3de00ea..d6870c3d9 100644 --- a/tools/update-vue3-export-names.js +++ b/tools/update-vue3-export-names.js @@ -6,9 +6,8 @@ const fs = require('fs') const path = require('path') -const https = require('https') -const { URL } = require('url') const tsParser = require('@typescript-eslint/parser') +const { httpGet } = require('./lib/http') main() @@ -144,32 +143,3 @@ async function resolveTypeContents(m) { } return await httpGet(`https://unpkg.com/${m}/${typesPath}`) } - -function httpGet(url) { - return new Promise((resolve, reject) => { - let result = '' - https - .get(url, (res) => { - if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400) { - // redirect - let redirectUrl = res.headers.location - if (!redirectUrl.startsWith('http')) { - const baseUrl = new URL(url) - baseUrl.pathname = redirectUrl - redirectUrl = String(baseUrl) - } - resolve(httpGet(redirectUrl)) - return - } - res.setEncoding('utf8') - res.on('data', (chunk) => { - result += String(chunk) - }) - res.on('end', () => { - resolve(result) - }) - res.on('error', reject) - }) - .on('error', reject) - }) -} diff --git a/tools/update.js b/tools/update.js index 266aedbcc..60b1cef58 100644 --- a/tools/update.js +++ b/tools/update.js @@ -10,6 +10,7 @@ require('./update-lib-configs') require('./update-lib-index') require('./update-docs') require('./update-docs-rules-index') +require('./update-resources') if (process.env.IN_VERSION_SCRIPT) { require('./update-vue3-export-names')