Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
root: true
extends:
- plugin:@mysticatea/es2018
- plugin:@eslint-community/mysticatea/es2018
parserOptions:
project: tsconfig.eslint.json
settings:
Expand All @@ -11,7 +11,15 @@ rules:
# tsc does.
"no-redeclare": "off"
# https://github.com/typescript-eslint/typescript-eslint/issues/743
"@mysticatea/ts/unbound-method": "off"
"@eslint-community/mysticatea/ts/unbound-method": "off"

# Temporary disabled rules
"@eslint-community/mysticatea/ts/naming-convention": "off"
"@eslint-community/mysticatea/ts/prefer-readonly-parameter-types": "off"
# Should be fixed by `@eslint-community/eslint-plugin-mysticatea`
"no-duplicate-imports": "off"
"@eslint-community/mysticatea/ts/no-duplicate-imports":
["error", { includeExports: true }]

overrides:
- files: "./src/unicode/ids.ts"
Expand All @@ -20,4 +28,4 @@ overrides:
no-misleading-character-class: "off"
- files: "./src/unicode/property-data.ts"
rules:
"@mysticatea/ts/camelcase": "off"
"@eslint-community/mysticatea/ts/camelcase": "off"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {},
"devDependencies": {
"@mysticatea/eslint-plugin": "^13.0.0",
"@eslint-community/eslint-plugin-mysticatea": "^15.3.0",
"@rollup/plugin-node-resolve": "^14.1.0",
"@types/eslint": "^6.8.1",
"@types/jsdom": "^16.2.15",
Expand Down
18 changes: 14 additions & 4 deletions scripts/clone-without-circular.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/* Temporarily disable these rules until we fix the `any` usage */
/* eslint
"@eslint-community/mysticatea/eslint-comments/no-use": "off",
"@eslint-community/mysticatea/ts/no-unsafe-argument": "off",
"@eslint-community/mysticatea/ts/no-unsafe-assignment": "off",
"@eslint-community/mysticatea/ts/no-unsafe-member-access": "off",
"@eslint-community/mysticatea/ts/no-unsafe-return": "off",
*/

import { posix } from "path"

function resolveLocation(
Expand Down Expand Up @@ -35,7 +44,7 @@ function cloneWithoutCircularRec(x: any, pathMap: Map<object, string>): any {
return x
}
if (Array.isArray(x)) {
return x.map(el => cloneWithoutCircularRec(el, pathMap))
return x.map((el) => cloneWithoutCircularRec(el, pathMap))
}

const y = {} as any
Expand All @@ -58,22 +67,23 @@ function getRelativePath(
return to
}
if (Array.isArray(to)) {
return to.map(el => getRelativePath(from, el, pathMap))
return to.map((el) => getRelativePath(from, el, pathMap))
}

const fromPath = pathMap.get(from)!
const toPath = pathMap.get(to)!
try {
return `♻️${posix.relative(fromPath, toPath).replace(/\/$/u, "")}`
} catch (err) {
console.error(fromPath, toPath, err.stack)
const error = err as Error
console.error(fromPath, toPath, error.stack)
return "💥💥💥💥💥💥💥💥"
}
}

export function cloneWithoutCircular(obj: object): object {
const path: string[] = []
const pathMap: Map<object, string> = new Map()
const pathMap = new Map<object, string>()
resolveLocation(obj, path, pathMap)

return cloneWithoutCircularRec(obj, pathMap)
Expand Down
7 changes: 5 additions & 2 deletions scripts/update-fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { AST, parseRegExpLiteral, visitRegExpAST } from "../src/index"
import type { AST } from "../src/index"
import { parseRegExpLiteral, visitRegExpAST } from "../src/index"
import type { RegExpSyntaxError } from "../src/regexp-syntax-error"
import * as Parser from "../test/fixtures/parser/literal"
import * as Visitor from "../test/fixtures/visitor"
import { cloneWithoutCircular } from "./clone-without-circular"
Expand All @@ -12,8 +14,9 @@ for (const filename of Object.keys(Parser.Fixtures)) {
const ast = parseRegExpLiteral(pattern, options)
fixture.patterns[pattern] = { ast: cloneWithoutCircular(ast) }
} catch (err) {
const error = err as RegExpSyntaxError
fixture.patterns[pattern] = {
error: { message: err.message, index: err.index },
error: { message: error.message, index: error.index },
}
}
}
Expand Down
29 changes: 17 additions & 12 deletions scripts/update-unicode-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const logger = console
// Main
const main = async () => {
let banner = ""
const idStartSet: Set<string> = new Set()
const idStartSet = new Set<string>()
const idStartSmall: [number, number][] = []
const idStartLarge: [number, number][] = []
const idContinueSmall: [number, number][] = []
const idContinueLarge: [number, number][] = []

logger.log("Fetching data... (%s)", DB_URL)
await processEachLine(line => {
await processEachLine((line) => {
let m: RegExpExecArray | null = null
if (banner === "") {
logger.log("Processing data... (%s)", line.slice(2))
Expand Down Expand Up @@ -113,38 +113,39 @@ function restoreRanges(data: string): number[] {
rules: { curly: "off" },
})
const result = engine.executeOnText(code, "ids.ts").results[0]
code = result.output || code
code = result.output ?? code

logger.log("Writing '%s'...", FILE_PATH)
await save(code)

logger.log("Completed!")
}

main().catch(error => {
main().catch((err) => {
const error = err as Error
logger.error(error.stack)
process.exitCode = 1
})

function processEachLine(cb: (line: string) => void): Promise<void> {
function processEachLine(processLine: (line: string) => void): Promise<void> {
return new Promise((resolve, reject) => {
http.get(DB_URL, res => {
http.get(DB_URL, (res) => {
let buffer = ""
res.setEncoding("utf8")
res.on("data", chunk => {
res.on("data", (chunk) => {
const lines = (buffer + String(chunk)).split("\n")
if (lines.length === 1) {
buffer = lines[0]
} else {
buffer = lines.pop()!
for (const line of lines) {
cb(line)
processLine(line)
}
}
})
res.on("end", () => {
if (buffer) {
cb(buffer)
processLine(buffer)
}
resolve()
})
Expand Down Expand Up @@ -189,8 +190,12 @@ function makeInitLargeIdRanges(ranges: [number, number][]): string {

function save(content: string): Promise<void> {
return new Promise((resolve, reject) => {
fs.writeFile(FILE_PATH, content, error =>
error ? reject(error) : resolve(),
)
fs.writeFile(FILE_PATH, content, (error) => {
if (error) {
reject(error)
} else {
resolve()
}
})
})
}
47 changes: 27 additions & 20 deletions scripts/update-unicode-properties.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "fs"
import { JSDOM, DOMWindow } from "jsdom"
import type { DOMWindow } from "jsdom"
import { JSDOM } from "jsdom"
import { CLIEngine } from "eslint"

const DataSources = [
Expand Down Expand Up @@ -43,7 +44,7 @@ type Datum = {

// Main
;(async () => {
const data: Record<number, Datum> = Object.create(null)
const data: Record<number, Datum> = {}
const existing = {
binProperties: new Set<string>(),
gcValues: new Set<string>(),
Expand All @@ -70,12 +71,13 @@ type Datum = {
try {
logger.log("Fetching data from %o", url)
;({ window } = await JSDOM.fromURL(url))
} catch (error) {
} catch (err) {
const error = err as Error
if (!error || error.message !== "Error: socket hang up") {
throw error
}
logger.log(error.message, "then retry.")
await new Promise(resolve => setTimeout(resolve, 2000))
await new Promise((resolve) => setTimeout(resolve, 2000))
}
} while (window == null)

Expand All @@ -99,13 +101,13 @@ ${makeClassDeclarationCode(Object.keys(data))}
const gcNameSet = new Set(["General_Category", "gc"])
const scNameSet = new Set(["Script", "Script_Extensions", "sc", "scx"])
const gcValueSets = new DataSet(${Object.values(data)
.map(d => makeDataCode(d.gcValues))
.map((d) => makeDataCode(d.gcValues))
.join(",")})
const scValueSets = new DataSet(${Object.values(data)
.map(d => makeDataCode(d.scValues))
.map((d) => makeDataCode(d.scValues))
.join(",")})
const binPropertySets = new DataSet(${Object.values(data)
.map(d => makeDataCode(d.binProperties))
.map((d) => makeDataCode(d.binProperties))
.join(",")})

export function isValidUnicodeProperty(version: number, name: string, value: string): boolean {
Expand Down Expand Up @@ -141,26 +143,27 @@ export function isValidLoneUnicodeProperty(version: number, value: string): bool
logger.log("Formatting code...")
const engine = new CLIEngine({ fix: true })
const result = engine.executeOnText(code, "properties.ts").results[0]
code = result.output || code
code = result.output ?? code

logger.log("Writing '%s'...", FILE_PATH)
await save(code)

logger.log("Completed!")
})().catch(error => {
})().catch((err) => {
const error = err as Error
logger.error(error.stack)
process.exitCode = 1
})

function collectValues(
window: Window,
window: DOMWindow,
id: string,
existingSet: Set<string>,
): string[] {
const selector = `${id} td:nth-child(1) code`
const nodes = window.document.querySelectorAll(selector)
const values = Array.from(nodes, node => node.textContent || "")
.filter(value => {
const values = Array.from(nodes, (node) => node.textContent ?? "")
.filter((value) => {
if (existingSet.has(value)) {
return false
}
Expand All @@ -183,15 +186,15 @@ function collectValues(
function makeClassDeclarationCode(versions: string[]): string {
const fields = versions
.map(
v =>
(v) =>
`private _raw${v}: string\nprivate _set${v}: Set<string> | undefined`,
)
.join("\n")
const parameters = versions.map(v => `raw${v}: string`).join(", ")
const init = versions.map(v => `this._raw${v} = raw${v}`).join("\n")
const parameters = versions.map((v) => `raw${v}: string`).join(", ")
const init = versions.map((v) => `this._raw${v} = raw${v}`).join("\n")
const getters = versions
.map(
v =>
(v) =>
`public get es${v}(): Set<string> { return this._set${v} || (this._set${v} = new Set(this._raw${v}.split(" "))) }`,
)
.join("\n")
Expand All @@ -209,7 +212,7 @@ function makeClassDeclarationCode(versions: string[]): string {

function makeDataCode(values: string[]): string {
return `"${values
.map(value => JSON.stringify(value).slice(1, -1))
.map((value) => JSON.stringify(value).slice(1, -1))
.join(" ")}"`
}

Expand All @@ -227,8 +230,12 @@ function makeVerificationCode(

function save(content: string): Promise<void> {
return new Promise((resolve, reject) => {
fs.writeFile(FILE_PATH, content, error =>
error ? reject(error) : resolve(),
)
fs.writeFile(FILE_PATH, content, (error) => {
if (error) {
reject(error)
} else {
resolve()
}
})
})
}
Loading