Skip to content

Commit

Permalink
Add update-resources script
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed May 14, 2023
1 parent 659a50f commit 8c9935f
Show file tree
Hide file tree
Showing 9 changed files with 366 additions and 39 deletions.
32 changes: 31 additions & 1 deletion lib/utils/deprecated-html-elements.json
Original file line number Diff line number Diff line change
@@ -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"]
[
"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"
]
114 changes: 113 additions & 1 deletion lib/utils/html-elements.json
Original file line number Diff line number Diff line change
@@ -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"
]
66 changes: 65 additions & 1 deletion lib/utils/svg-elements.json
Original file line number Diff line number Diff line change
@@ -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"
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
4 changes: 0 additions & 4 deletions tests/lib/rules/no-reserved-component-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ const invalidElements = [
'Defs',
'desc',
'Desc',
'discard',
'Discard',
'ellipse',
'Ellipse',
'feBlend',
Expand Down Expand Up @@ -352,8 +350,6 @@ const invalidElements = [
'textPath',
'tspan',
'Tspan',
'unknown',
'Unknown',
'use',
'Use',
'view',
Expand Down
34 changes: 34 additions & 0 deletions tools/lib/http.js
Original file line number Diff line number Diff line change
@@ -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)
})
}
120 changes: 120 additions & 0 deletions tools/update-resources.js
Original file line number Diff line number Diff line change
@@ -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}`
}
}
}
Loading

0 comments on commit 8c9935f

Please sign in to comment.