Skip to content

Commit 3a2c5cd

Browse files
Added lints for scripts
1 parent 77d5772 commit 3a2c5cd

7 files changed

Lines changed: 307 additions & 252 deletions

File tree

.eslintrc.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,27 @@ module.exports = {
9595
},
9696
overrides: [
9797
{
98-
files: [
99-
"scripts/**"
100-
],
98+
files: ["scripts/**"],
10199
env: {
102100
browser: false,
103101
node: true,
104102
es6: true
105103
},
104+
parserOptions: {
105+
project: "./scripts/tsconfig.json"
106+
},
106107
rules: {
107108
"@typescript-eslint/no-var-requires": "off"
108109
}
109-
}
110-
],
111-
overrides: [
110+
},
112111
{
113-
files: [
114-
"tests/**"
115-
],
112+
files: ["tests/**"],
116113
parserOptions: {
117114
project: "./tests/tsconfig.json"
118115
}
119116
}
120117
],
121118
ignorePatterns: [
122-
"scripts/**",
123119
"*.js",
124120
"index.d.ts",
125121
"src/js/unicode/**"

scripts/create-case-folding.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ import * as path from "path";
33
import { CharSet } from "../src/char-set";
44
import { printRanges } from "./util";
55

6+
const caseFoldingCommon: ReadonlyMap<number, number> = require("@unicode/unicode-13.0.0/Case_Folding/C/code-points");
7+
const caseFoldingSimple: ReadonlyMap<number, number> = require("@unicode/unicode-13.0.0/Case_Folding/S/code-points");
68

7-
const CaseFoldingCommon: ReadonlyMap<number, number> = require("@unicode/unicode-13.0.0/Case_Folding/C/code-points");
8-
const CaseFoldingSimple: ReadonlyMap<number, number> = require("@unicode/unicode-13.0.0/Case_Folding/S/code-points");
9+
createCaseFoldingFile(canonicalizeIgnoreCaseUTF16, 0xffff, "UTF16", "utf16-case-folding.ts");
10+
createCaseFoldingFile(canonicalizeIgnoreCaseUnicode, 0x10ffff, "Unicode", "unicode/case-folding.ts");
911

10-
11-
createCaseFoldingFile(UTF16CanonicalizeIgnoreCase, 0xFFFF, "UTF16", "utf16-case-folding.ts");
12-
createCaseFoldingFile(UnicodeCanonicalizeIgnoreCase, 0x10FFFF, "Unicode", "unicode/case-folding.ts");
13-
14-
function UTF16CanonicalizeIgnoreCase(ch: number): number {
12+
function canonicalizeIgnoreCaseUTF16(ch: number): number {
1513
// https://tc39.es/ecma262/#sec-runtime-semantics-canonicalize-ch
1614

1715
const s = String.fromCharCode(ch);
@@ -26,14 +24,14 @@ function UTF16CanonicalizeIgnoreCase(ch: number): number {
2624
return cu;
2725
}
2826

29-
function UnicodeCanonicalizeIgnoreCase(ch: number): number {
27+
function canonicalizeIgnoreCaseUnicode(ch: number): number {
3028
// https://tc39.es/ecma262/#sec-runtime-semantics-canonicalize-ch
3129

32-
let mapping = CaseFoldingCommon.get(ch);
30+
let mapping = caseFoldingCommon.get(ch);
3331
if (mapping !== undefined) {
3432
return mapping;
3533
}
36-
mapping = CaseFoldingSimple.get(ch);
34+
mapping = caseFoldingSimple.get(ch);
3735
if (mapping !== undefined) {
3836
return mapping;
3937
}
@@ -47,13 +45,12 @@ function createCaseFoldingFile(
4745
variablePrefix: string,
4846
filename: string
4947
): void {
50-
5148
const canonicalizeMapping = new Map<number, number[]>();
5249
for (let ch = 0; ch <= maxCharacter; ch++) {
5350
const c = canonicalize(ch);
5451
let list = canonicalizeMapping.get(c);
5552
if (list === undefined) {
56-
canonicalizeMapping.set(c, list = []);
53+
canonicalizeMapping.set(c, (list = []));
5754
}
5855
list.push(ch);
5956
}
@@ -66,18 +63,21 @@ function createCaseFoldingFile(
6663
});
6764

6865
let count = 0;
69-
const CASE_VARYING = CharSet.fromCharacters(maxCharacter, function* () {
70-
for (let i = 0; i < maxCharacter; i++) {
71-
const fold = caseFolding[i];
72-
if (fold.indexOf(i) === -1) {
73-
throw new Error(`The case folding of ${i} does not include itself.`);
74-
}
75-
if (fold.length > 1) {
76-
count++;
77-
yield i;
66+
const CASE_VARYING = CharSet.fromCharacters(
67+
maxCharacter,
68+
(function* () {
69+
for (let i = 0; i < maxCharacter; i++) {
70+
const fold = caseFolding[i];
71+
if (fold.indexOf(i) === -1) {
72+
throw new Error(`The case folding of ${i} does not include itself.`);
73+
}
74+
if (fold.length > 1) {
75+
count++;
76+
yield i;
77+
}
7878
}
79-
}
80-
}());
79+
})()
80+
);
8181

8282
const map: Record<number, number[]> = {};
8383
caseFolding.forEach((fold, i) => {
@@ -88,7 +88,6 @@ function createCaseFoldingFile(
8888

8989
console.log(`${variablePrefix}: ${count} characters vary in case`);
9090

91-
9291
const code = `/* eslint-disable */
9392
9493
// DO NOT EDIT!
@@ -100,17 +99,19 @@ import { CharSet } from "${"../".repeat(filename.split(/\//g).length)}char-set";
10099
/**
101100
* A character set of all characters that have at least one case variation.
102101
*/
103-
export const ${variablePrefix}CaseVarying: CharSet = CharSet.empty(${maxCharacter}).union(${printRanges(CASE_VARYING.ranges)
104-
});
102+
export const ${variablePrefix}CaseVarying: CharSet = CharSet.empty(${maxCharacter}).union(${printRanges(
103+
CASE_VARYING.ranges
104+
)});
105105
106106
/**
107107
* A map for a given character to all it case variations. The list of case variations also includes the key character
108108
* itself.
109109
*
110110
* If the given character do not have case variations, it will not be part of this map.
111111
*/
112-
export const ${variablePrefix}CaseFolding: Readonly<Record<number, readonly number[]>> = JSON.parse(${JSON.stringify(JSON.stringify(map))
113-
});
112+
export const ${variablePrefix}CaseFolding: Readonly<Record<number, readonly number[]>> = JSON.parse(${JSON.stringify(
113+
JSON.stringify(map)
114+
)});
114115
`;
115116

116117
fs.writeFileSync(path.join(__dirname, "../src/js", filename), code, "utf-8");

scripts/create-unicode.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import { CharSet } from "../src/char-set";
44
import * as aliases from "../src/js/unicode/alias";
55
import { printRanges } from "./util";
66

7-
87
const UNICODE_SRC_DIR = path.join(__dirname, "../src/js/unicode");
98

109
createDataFile(Object.values(aliases.Binary_Property), "Binary_Property", "binary-property-data.ts");
1110
createDataFile(Object.values(aliases.General_Category), "General_Category", "general-category-data.ts");
1211
createDataFile(Object.values(aliases.ScriptAndScript_Extensions), "Script", "script-data.ts");
1312
createDataFile(Object.values(aliases.ScriptAndScript_Extensions), "Script_Extensions", "script-extensions-data.ts");
1413

15-
1614
function createDataFile(properties: Iterable<string>, category: string, filename: string): void {
1715
console.log(`Creating ${filename}`);
1816

@@ -33,7 +31,7 @@ import { CharRange } from "../../char-set";
3331

3432
for (const prop of values) {
3533
const codePoints: number[] = require(`@unicode/unicode-13.0.0/${category}/${prop}/code-points`);
36-
const ranges = CharSet.fromCharacters(0x10FFFF, codePoints).ranges;
34+
const ranges = CharSet.fromCharacters(0x10ffff, codePoints).ranges;
3735

3836
code += `export const ${prop}: readonly CharRange[] = ${printRanges(ranges)};\n`;
3937
}

scripts/debug.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
import { combineTransformers, transform, NFA, DFA, ENFA, Words, JS, CharSet, CharacterClass, FiniteAutomaton, Expression, NoParent, Transformers } from "../src";
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
2+
import {
3+
CharSet,
4+
CharacterClass,
5+
DFA,
6+
ENFA,
7+
Expression,
8+
FiniteAutomaton,
9+
JS,
10+
NFA,
11+
NoParent,
12+
Transformers,
13+
Words,
14+
combineTransformers,
15+
transform,
16+
} from "../src";
217
import { performance } from "perf_hooks";
318
import { logDurations } from "./util";
419

@@ -42,16 +57,15 @@ function measure<T>(fn: () => T, samples: number = 1, label?: string): T {
4257

4358
logDurations(durations, label ?? fn.toString().replace(/^\(\) => /, ""));
4459

45-
return result
60+
return result;
4661
}
4762

4863
// actual debug code
4964
// DO NOT commit changes to this file
5065

51-
const dfa = toDFA(/a+(?:b+a+)*/)
66+
const dfa = toDFA(/a+(?:b+a+)*/);
5267
dfa.minimize();
5368
console.log(toRegExp(dfa));
5469

55-
5670
console.log(toENFA(/a*b/).toString());
5771
console.log(toENFA(/a*?b/).toString());

0 commit comments

Comments
 (0)