Skip to content

Commit 14e88c4

Browse files
chore(deps-dev): update @mysticatea/eslint-plugin to @eslint-community/eslint-plugin-mysticatea (#31)
1 parent 8cb8fe0 commit 14e88c4

19 files changed

+275
-186
lines changed

.eslintrc.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
root: true
22
extends:
3-
- plugin:@mysticatea/es2018
3+
- plugin:@eslint-community/mysticatea/es2018
44
parserOptions:
55
project: tsconfig.eslint.json
66
settings:
@@ -11,7 +11,15 @@ rules:
1111
# tsc does.
1212
"no-redeclare": "off"
1313
# https://github.com/typescript-eslint/typescript-eslint/issues/743
14-
"@mysticatea/ts/unbound-method": "off"
14+
"@eslint-community/mysticatea/ts/unbound-method": "off"
15+
16+
# Temporary disabled rules
17+
"@eslint-community/mysticatea/ts/naming-convention": "off"
18+
"@eslint-community/mysticatea/ts/prefer-readonly-parameter-types": "off"
19+
# Should be fixed by `@eslint-community/eslint-plugin-mysticatea`
20+
"no-duplicate-imports": "off"
21+
"@eslint-community/mysticatea/ts/no-duplicate-imports":
22+
["error", { includeExports: true }]
1523

1624
overrides:
1725
- files: "./src/unicode/ids.ts"
@@ -20,4 +28,4 @@ overrides:
2028
no-misleading-character-class: "off"
2129
- files: "./src/unicode/property-data.ts"
2230
rules:
23-
"@mysticatea/ts/camelcase": "off"
31+
"@eslint-community/mysticatea/ts/camelcase": "off"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
"dependencies": {},
2020
"devDependencies": {
21-
"@mysticatea/eslint-plugin": "^13.0.0",
21+
"@eslint-community/eslint-plugin-mysticatea": "^15.3.0",
2222
"@rollup/plugin-node-resolve": "^14.1.0",
2323
"@types/eslint": "^6.8.1",
2424
"@types/jsdom": "^16.2.15",

scripts/clone-without-circular.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/* Temporarily disable these rules until we fix the `any` usage */
2+
/* eslint
3+
"@eslint-community/mysticatea/eslint-comments/no-use": "off",
4+
"@eslint-community/mysticatea/ts/no-unsafe-argument": "off",
5+
"@eslint-community/mysticatea/ts/no-unsafe-assignment": "off",
6+
"@eslint-community/mysticatea/ts/no-unsafe-member-access": "off",
7+
"@eslint-community/mysticatea/ts/no-unsafe-return": "off",
8+
*/
9+
110
import { posix } from "path"
211

312
function resolveLocation(
@@ -35,7 +44,7 @@ function cloneWithoutCircularRec(x: any, pathMap: Map<object, string>): any {
3544
return x
3645
}
3746
if (Array.isArray(x)) {
38-
return x.map(el => cloneWithoutCircularRec(el, pathMap))
47+
return x.map((el) => cloneWithoutCircularRec(el, pathMap))
3948
}
4049

4150
const y = {} as any
@@ -58,22 +67,23 @@ function getRelativePath(
5867
return to
5968
}
6069
if (Array.isArray(to)) {
61-
return to.map(el => getRelativePath(from, el, pathMap))
70+
return to.map((el) => getRelativePath(from, el, pathMap))
6271
}
6372

6473
const fromPath = pathMap.get(from)!
6574
const toPath = pathMap.get(to)!
6675
try {
6776
return `♻️${posix.relative(fromPath, toPath).replace(/\/$/u, "")}`
6877
} catch (err) {
69-
console.error(fromPath, toPath, err.stack)
78+
const error = err as Error
79+
console.error(fromPath, toPath, error.stack)
7080
return "💥💥💥💥💥💥💥💥"
7181
}
7282
}
7383

7484
export function cloneWithoutCircular(obj: object): object {
7585
const path: string[] = []
76-
const pathMap: Map<object, string> = new Map()
86+
const pathMap = new Map<object, string>()
7787
resolveLocation(obj, path, pathMap)
7888

7989
return cloneWithoutCircularRec(obj, pathMap)

scripts/update-fixtures.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { AST, parseRegExpLiteral, visitRegExpAST } from "../src/index"
1+
import type { AST } from "../src/index"
2+
import { parseRegExpLiteral, visitRegExpAST } from "../src/index"
3+
import type { RegExpSyntaxError } from "../src/regexp-syntax-error"
24
import * as Parser from "../test/fixtures/parser/literal"
35
import * as Visitor from "../test/fixtures/visitor"
46
import { cloneWithoutCircular } from "./clone-without-circular"
@@ -12,8 +14,9 @@ for (const filename of Object.keys(Parser.Fixtures)) {
1214
const ast = parseRegExpLiteral(pattern, options)
1315
fixture.patterns[pattern] = { ast: cloneWithoutCircular(ast) }
1416
} catch (err) {
17+
const error = err as RegExpSyntaxError
1518
fixture.patterns[pattern] = {
16-
error: { message: err.message, index: err.index },
19+
error: { message: error.message, index: error.index },
1720
}
1821
}
1922
}

scripts/update-unicode-ids.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ const logger = console
1212
// Main
1313
const main = async () => {
1414
let banner = ""
15-
const idStartSet: Set<string> = new Set()
15+
const idStartSet = new Set<string>()
1616
const idStartSmall: [number, number][] = []
1717
const idStartLarge: [number, number][] = []
1818
const idContinueSmall: [number, number][] = []
1919
const idContinueLarge: [number, number][] = []
2020

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

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

121121
logger.log("Completed!")
122122
}
123123

124-
main().catch(error => {
124+
main().catch((err) => {
125+
const error = err as Error
125126
logger.error(error.stack)
126127
process.exitCode = 1
127128
})
128129

129-
function processEachLine(cb: (line: string) => void): Promise<void> {
130+
function processEachLine(processLine: (line: string) => void): Promise<void> {
130131
return new Promise((resolve, reject) => {
131-
http.get(DB_URL, res => {
132+
http.get(DB_URL, (res) => {
132133
let buffer = ""
133134
res.setEncoding("utf8")
134-
res.on("data", chunk => {
135+
res.on("data", (chunk) => {
135136
const lines = (buffer + String(chunk)).split("\n")
136137
if (lines.length === 1) {
137138
buffer = lines[0]
138139
} else {
139140
buffer = lines.pop()!
140141
for (const line of lines) {
141-
cb(line)
142+
processLine(line)
142143
}
143144
}
144145
})
145146
res.on("end", () => {
146147
if (buffer) {
147-
cb(buffer)
148+
processLine(buffer)
148149
}
149150
resolve()
150151
})
@@ -189,8 +190,12 @@ function makeInitLargeIdRanges(ranges: [number, number][]): string {
189190

190191
function save(content: string): Promise<void> {
191192
return new Promise((resolve, reject) => {
192-
fs.writeFile(FILE_PATH, content, error =>
193-
error ? reject(error) : resolve(),
194-
)
193+
fs.writeFile(FILE_PATH, content, (error) => {
194+
if (error) {
195+
reject(error)
196+
} else {
197+
resolve()
198+
}
199+
})
195200
})
196201
}

scripts/update-unicode-properties.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from "fs"
2-
import { JSDOM, DOMWindow } from "jsdom"
2+
import type { DOMWindow } from "jsdom"
3+
import { JSDOM } from "jsdom"
34
import { CLIEngine } from "eslint"
45

56
const DataSources = [
@@ -43,7 +44,7 @@ type Datum = {
4344

4445
// Main
4546
;(async () => {
46-
const data: Record<number, Datum> = Object.create(null)
47+
const data: Record<number, Datum> = {}
4748
const existing = {
4849
binProperties: new Set<string>(),
4950
gcValues: new Set<string>(),
@@ -70,12 +71,13 @@ type Datum = {
7071
try {
7172
logger.log("Fetching data from %o", url)
7273
;({ window } = await JSDOM.fromURL(url))
73-
} catch (error) {
74+
} catch (err) {
75+
const error = err as Error
7476
if (!error || error.message !== "Error: socket hang up") {
7577
throw error
7678
}
7779
logger.log(error.message, "then retry.")
78-
await new Promise(resolve => setTimeout(resolve, 2000))
80+
await new Promise((resolve) => setTimeout(resolve, 2000))
7981
}
8082
} while (window == null)
8183

@@ -99,13 +101,13 @@ ${makeClassDeclarationCode(Object.keys(data))}
99101
const gcNameSet = new Set(["General_Category", "gc"])
100102
const scNameSet = new Set(["Script", "Script_Extensions", "sc", "scx"])
101103
const gcValueSets = new DataSet(${Object.values(data)
102-
.map(d => makeDataCode(d.gcValues))
104+
.map((d) => makeDataCode(d.gcValues))
103105
.join(",")})
104106
const scValueSets = new DataSet(${Object.values(data)
105-
.map(d => makeDataCode(d.scValues))
107+
.map((d) => makeDataCode(d.scValues))
106108
.join(",")})
107109
const binPropertySets = new DataSet(${Object.values(data)
108-
.map(d => makeDataCode(d.binProperties))
110+
.map((d) => makeDataCode(d.binProperties))
109111
.join(",")})
110112
111113
export function isValidUnicodeProperty(version: number, name: string, value: string): boolean {
@@ -141,26 +143,27 @@ export function isValidLoneUnicodeProperty(version: number, value: string): bool
141143
logger.log("Formatting code...")
142144
const engine = new CLIEngine({ fix: true })
143145
const result = engine.executeOnText(code, "properties.ts").results[0]
144-
code = result.output || code
146+
code = result.output ?? code
145147

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

149151
logger.log("Completed!")
150-
})().catch(error => {
152+
})().catch((err) => {
153+
const error = err as Error
151154
logger.error(error.stack)
152155
process.exitCode = 1
153156
})
154157

155158
function collectValues(
156-
window: Window,
159+
window: DOMWindow,
157160
id: string,
158161
existingSet: Set<string>,
159162
): string[] {
160163
const selector = `${id} td:nth-child(1) code`
161164
const nodes = window.document.querySelectorAll(selector)
162-
const values = Array.from(nodes, node => node.textContent || "")
163-
.filter(value => {
165+
const values = Array.from(nodes, (node) => node.textContent ?? "")
166+
.filter((value) => {
164167
if (existingSet.has(value)) {
165168
return false
166169
}
@@ -183,15 +186,15 @@ function collectValues(
183186
function makeClassDeclarationCode(versions: string[]): string {
184187
const fields = versions
185188
.map(
186-
v =>
189+
(v) =>
187190
`private _raw${v}: string\nprivate _set${v}: Set<string> | undefined`,
188191
)
189192
.join("\n")
190-
const parameters = versions.map(v => `raw${v}: string`).join(", ")
191-
const init = versions.map(v => `this._raw${v} = raw${v}`).join("\n")
193+
const parameters = versions.map((v) => `raw${v}: string`).join(", ")
194+
const init = versions.map((v) => `this._raw${v} = raw${v}`).join("\n")
192195
const getters = versions
193196
.map(
194-
v =>
197+
(v) =>
195198
`public get es${v}(): Set<string> { return this._set${v} || (this._set${v} = new Set(this._raw${v}.split(" "))) }`,
196199
)
197200
.join("\n")
@@ -209,7 +212,7 @@ function makeClassDeclarationCode(versions: string[]): string {
209212

210213
function makeDataCode(values: string[]): string {
211214
return `"${values
212-
.map(value => JSON.stringify(value).slice(1, -1))
215+
.map((value) => JSON.stringify(value).slice(1, -1))
213216
.join(" ")}"`
214217
}
215218

@@ -227,8 +230,12 @@ function makeVerificationCode(
227230

228231
function save(content: string): Promise<void> {
229232
return new Promise((resolve, reject) => {
230-
fs.writeFile(FILE_PATH, content, error =>
231-
error ? reject(error) : resolve(),
232-
)
233+
fs.writeFile(FILE_PATH, content, (error) => {
234+
if (error) {
235+
reject(error)
236+
} else {
237+
resolve()
238+
}
239+
})
233240
})
234241
}

0 commit comments

Comments
 (0)