Skip to content

Commit 976d945

Browse files
style: fix
1 parent be4a2b8 commit 976d945

File tree

11 files changed

+65
-61
lines changed

11 files changed

+65
-61
lines changed

compile-to-definitions/index.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ const makeDefinitionsForSchema = async (absSchemaPath, schemasDir) => {
3030
const filename = path.resolve(
3131
root,
3232
outputFolder,
33-
`${path.join(directory, basename)}.d.ts`
33+
`${path.join(directory, basename)}.d.ts`,
3434
);
3535
const schema = JSON.parse(fs.readFileSync(absSchemaPath, "utf-8"));
3636
const keys = Object.keys(schema);
3737
if (keys.length === 1 && keys[0] === "$ref") return;
3838

3939
const prettierConfig = await prettier.resolveConfig(
40-
path.resolve(root, outputFolder, "result.d.ts")
40+
path.resolve(root, outputFolder, "result.d.ts"),
4141
);
4242
const style = {
4343
printWidth: prettierConfig.printWidth,
@@ -56,7 +56,7 @@ const makeDefinitionsForSchema = async (absSchemaPath, schemasDir) => {
5656
(ts) => {
5757
ts = ts.replace(
5858
/\s+\*\s+\* This interface was referenced by `.+`'s JSON-Schema\s+\* via the `definition` ".+"\./g,
59-
""
59+
"",
6060
);
6161
let normalizedContent = "";
6262
try {
@@ -70,14 +70,14 @@ const makeDefinitionsForSchema = async (absSchemaPath, schemasDir) => {
7070
fs.mkdirSync(path.dirname(filename), { recursive: true });
7171
fs.writeFileSync(filename, ts, "utf-8");
7272
console.error(
73-
`declarations/${relPath.replace(/\\/g, "/")}.d.ts updated`
73+
`declarations/${relPath.replace(/\\/g, "/")}.d.ts updated`,
7474
);
7575
} else {
7676
console.error(
7777
`declarations/${relPath.replace(
7878
/\\/g,
79-
"/"
80-
)}.d.ts need to be updated`
79+
"/",
80+
)}.d.ts need to be updated`,
8181
);
8282
process.exitCode = 1;
8383
}
@@ -86,7 +86,7 @@ const makeDefinitionsForSchema = async (absSchemaPath, schemasDir) => {
8686
(err) => {
8787
console.error(err);
8888
process.exitCode = 1;
89-
}
89+
},
9090
);
9191
};
9292

@@ -113,7 +113,7 @@ const preprocessSchema = (schema, root = schema, path = []) => {
113113
const result = resolvePath(root, property.$ref);
114114
if (!result) {
115115
throw new Error(
116-
`Unable to resolve "$ref": "${property.$ref}" in ${path.join("/")}`
116+
`Unable to resolve "$ref": "${property.$ref}" in ${path.join("/")}`,
117117
);
118118
}
119119
schema.properties[key] = {
@@ -167,7 +167,7 @@ const preprocessSchema = (schema, root = schema, path = []) => {
167167
implementedNames.push(/\/([^\/]+)$/.exec(impl)[1]);
168168
}
169169
const propEntries = Object.entries(schema.properties).filter(
170-
([name]) => !implementedProps.has(name)
170+
([name]) => !implementedProps.has(name),
171171
);
172172
if (propEntries.length > 0) {
173173
const key =

declarations.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as ts from "typescript";
22
declare module "typescript" {
33
export function getDeclarationModifierFlagsFromSymbol(
4-
s: ts.Symbol
4+
s: ts.Symbol,
55
): ts.ModifierFlags;
66
export function signatureHasRestParameter(signature: ts.Signature): boolean;
77
interface Symbol {
88
type?: ts.Type;
9-
parent: Symbol | undefined
9+
parent: Symbol | undefined;
1010
}
1111
interface Declaration {
1212
expression?: ts.Expression;

format-file-header/index.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ const execToArray = (content, regexp) => {
4545
const schema = [
4646
{
4747
title: "license comment",
48-
regexp: /\/\*\n\s*MIT License http:\/\/www\.opensource\.org\/licenses\/mit-license\.php\n\s*(?:(Authors? .+)\n)?\s*\*\/\n/g,
48+
regexp:
49+
/\/\*\n\s*MIT License http:\/\/www\.opensource\.org\/licenses\/mit-license\.php\n\s*(?:(Authors? .+)\n)?\s*\*\/\n/g,
4950
updateMessage: "update the license comment",
5051
update(content, author) {
5152
return (
@@ -82,12 +83,13 @@ const schema = [
8283
},
8384
{
8485
title: "imports",
85-
regexp: /(const (\{\s+\w+(?::\s+\w+)?(,\s+\w+(?::\s+\w+)?)*\s+\}|\w+) = (\/\*\* @type \{TODO\} \*\/\s\()?require\("[^"]+"\)\)?(\.\w+)*;\n)+\n/g,
86+
regexp:
87+
/(const (\{\s+\w+(?::\s+\w+)?(,\s+\w+(?::\s+\w+)?)*\s+\}|\w+) = (\/\*\* @type \{TODO\} \*\/\s\()?require\("[^"]+"\)\)?(\.\w+)*;\n)+\n/g,
8688
updateMessage: "sort imports alphabetically",
8789
update(content) {
8890
const items = execToArray(
8991
content,
90-
/const (?:\{\s+\w+(?::\s+\w+)?(?:,\s+\w+(?::\s+\w+)?)*\s+\}|\w+) = (?:\/\*\* @type \{TODO\} \*\/\s\()?require\("([^"]+)"\)\)?((?:\.\w+)*);\n/g
92+
/const (?:\{\s+\w+(?::\s+\w+)?(?:,\s+\w+(?::\s+\w+)?)*\s+\}|\w+) = (?:\/\*\* @type \{TODO\} \*\/\s\()?require\("([^"]+)"\)\)?((?:\.\w+)*);\n/g,
9193
);
9294
items.sort(sortImport);
9395
return items.map((item) => item.content).join("") + "\n";
@@ -97,12 +99,13 @@ const schema = [
9799
},
98100
{
99101
title: "type imports",
100-
regexp: /(\/\*\* (?:@template \w+ )*@typedef \{(?:typeof )?import\("[^"]+"\)(\.\w+)*(?:<(?:(?:\w\.)*\w+, )*(?:\w\.)*\w+>)?\} \w+(?:<(?:(?:\w\.)*\w+, )*(?:\w\.)*\w+>)? \*\/\n)+\n/g,
102+
regexp:
103+
/(\/\*\* (?:@template \w+ )*@typedef \{(?:typeof )?import\("[^"]+"\)(\.\w+)*(?:<(?:(?:\w\.)*\w+, )*(?:\w\.)*\w+>)?\} \w+(?:<(?:(?:\w\.)*\w+, )*(?:\w\.)*\w+>)? \*\/\n)+\n/g,
101104
updateMessage: "sort type imports alphabetically",
102105
update(content) {
103106
const items = execToArray(
104107
content,
105-
/\/\*\* (?:@template \w+ )*@typedef \{(?:typeof )?import\("([^"]+)"\)((?:\.\w+)*(?:<(?:(?:\w\.)*\w+, )*(?:\w\.)*\w+>)?)\} \w+(?:<(?:(?:\w\.)*\w+, )*(?:\w\.)*\w+>)? \*\/\n/g
108+
/\/\*\* (?:@template \w+ )*@typedef \{(?:typeof )?import\("([^"]+)"\)((?:\.\w+)*(?:<(?:(?:\w\.)*\w+, )*(?:\w\.)*\w+>)?)\} \w+(?:<(?:(?:\w\.)*\w+, )*(?:\w\.)*\w+>)? \*\/\n/g,
106109
);
107110
items.sort(sortImport);
108111
return items.map((item) => item.content).join("") + "\n";
@@ -139,7 +142,7 @@ for (const filePath of allFiles) {
139142
}
140143
if (match.index !== pos) {
141144
console.log(
142-
`${filePath}: Unexpected code at ${pos}-${match.index}, expected ${current.title}`
145+
`${filePath}: Unexpected code at ${pos}-${match.index}, expected ${current.title}`,
143146
);
144147
process.exitCode = 1;
145148
pos = match.index;
@@ -181,12 +184,12 @@ for (const filePath of allFiles) {
181184
}
182185

183186
const matches = content.match(
184-
/makeSerializable\(\s*[^,]+,\s*"webpack\/lib\/[^"]+"\s*(?:,[^)]+)?\)/g
187+
/makeSerializable\(\s*[^,]+,\s*"webpack\/lib\/[^"]+"\s*(?:,[^)]+)?\)/g,
185188
);
186189
if (matches) {
187190
for (const match of matches) {
188191
const str = /makeSerializable\(\s*[^,]+,\s*"webpack\/lib\/([^"]+)"/.exec(
189-
match
192+
match,
190193
)[1];
191194
allSerializables.add(str);
192195
}
@@ -195,13 +198,13 @@ for (const filePath of allFiles) {
195198

196199
// Check if internalSerializables.js includes all serializables in webpack
197200
for (const internalSerializables of allFiles.filter((file) =>
198-
file.includes("internalSerializables")
201+
file.includes("internalSerializables"),
199202
)) {
200203
const content = fs.readFileSync(internalSerializables);
201204
for (const serializable of allSerializables) {
202205
if (!content.includes(`"../${serializable}"`)) {
203206
console.log(
204-
`${internalSerializables}: must include static require to ../${serializable}`
207+
`${internalSerializables}: must include static require to ../${serializable}`,
205208
);
206209
process.exitCode = 1;
207210
}

format-schemas/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ const minSlashes = schemas
1212
.map((p) => p.split(/[\\/]/).length)
1313
.reduce((a, b) => Math.min(a, b), Infinity);
1414
const baseSchemaPaths = schemas.filter(
15-
(p) => p.split(/[\\/]/).length === minSlashes
15+
(p) => p.split(/[\\/]/).length === minSlashes,
1616
);
1717
const baseDefinitions = new Map();
1818
for (const baseSchemaPath of baseSchemaPaths) {
1919
for (const [name, schema] of Object.entries(
20-
require(baseSchemaPath).definitions
20+
require(baseSchemaPath).definitions,
2121
)) {
2222
baseDefinitions.set(name, schema);
2323
}
@@ -131,15 +131,15 @@ const processJson = processSchema.bind(null, {
131131
...json,
132132
tsType: tsType.replace(
133133
/\.\.\//g,
134-
context.importPrefix + "../"
134+
context.importPrefix + "../",
135135
),
136136
};
137137
}
138138
return json;
139139
},
140140
},
141141
baseDef,
142-
{}
142+
{},
143143
);
144144
json.definitions[key] = baseDef;
145145
}
@@ -151,21 +151,21 @@ const processJson = processSchema.bind(null, {
151151
for (const impl of [].concat(json.implements)) {
152152
if (!impl.startsWith(prefix)) {
153153
console.warn(
154-
`"implements": "${impl}" -> should start with "${prefix}"`
154+
`"implements": "${impl}" -> should start with "${prefix}"`,
155155
);
156156
continue;
157157
}
158158
const name = impl.slice(prefix.length);
159159
const referencedSchema = context.definitions[name];
160160
if (!referencedSchema) {
161161
console.warn(
162-
`"implements": "${impl}" -> referenced schema not found`
162+
`"implements": "${impl}" -> referenced schema not found`,
163163
);
164164
continue;
165165
}
166166
if (typeof referencedSchema.properties !== "object") {
167167
console.warn(
168-
`"implements": "${impl}" -> referenced schema has no properties`
168+
`"implements": "${impl}" -> referenced schema has no properties`,
169169
);
170170
continue;
171171
}

inherit-types/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ for (const sourceFile of program.getSourceFiles()) {
7474
) {
7575
const baseDecl = findDeclarationInBaseClass(
7676
node,
77-
member.name.getText()
77+
member.name.getText(),
7878
);
7979
if (baseDecl) {
8080
const memberAsAny = /** @type {any} */ (member);
@@ -88,7 +88,7 @@ for (const sourceFile of program.getSourceFiles()) {
8888
if (baseJsDocText) {
8989
baseJsDocText = baseJsDocText.replace(
9090
/\t \* @abstract\r?\n/g,
91-
""
91+
"",
9292
);
9393
if (!currentJsDocText) {
9494
// add js doc
@@ -145,7 +145,7 @@ for (const sourceFile of program.getSourceFiles()) {
145145
console.log(file);
146146
for (const update of updates) {
147147
console.log(
148-
`* ${update.member} should have this JSDoc:\n\t${update.content}`
148+
`* ${update.member} should have this JSDoc:\n\t${update.content}`,
149149
);
150150
if (update.oldContent) {
151151
console.log(`instead of\n\t${update.oldContent}`);

lib/argv.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = require("yargs")
22
.boolean("write")
33
.describe(
44
"write",
5-
"Write updated files to disk, otherwise it only checks if they are correct."
5+
"Write updated files to disk, otherwise it only checks if they are correct.",
66
)
77

88
.boolean("verbose")
@@ -11,12 +11,12 @@ module.exports = require("yargs")
1111
.string("root")
1212
.describe(
1313
"root",
14-
"Root repository directory (optional if calling from package.json scripts)."
14+
"Root repository directory (optional if calling from package.json scripts).",
1515
)
1616
.default(
1717
"root",
1818
process.env.INIT_CWD || process.cwd(),
19-
"The root directory from calling package.json or the current directory"
19+
"The root directory from calling package.json or the current directory",
2020
)
2121

2222
.string("schemas")
@@ -26,7 +26,7 @@ module.exports = require("yargs")
2626
.string("declarations")
2727
.describe(
2828
"declarations",
29-
"Output folder for declarations generated from schemas."
29+
"Output folder for declarations generated from schemas.",
3030
)
3131
.default("declarations", "declarations")
3232

lib/typescript-program.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const parsedConfig = ts.parseJsonSourceFileConfigFileContent(
1111
configJsonFile,
1212
ts.sys,
1313
root,
14-
{ noEmit: true }
14+
{ noEmit: true },
1515
);
1616
const { fileNames, options } = parsedConfig;
1717

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
"license": "MIT",
99
"private": true,
1010
"scripts": {
11+
"pretty-lint-base": "node node_modules/prettier/bin/prettier.cjs --cache --ignore-unknown .",
12+
"pretty-lint-fix": "yarn pretty-lint-base --log-level warn --write",
13+
"pretty-lint": "yarn pretty-lint-base --check",
1114
"test": "yarn lint",
12-
"lint": "yarn special-lint && tsc",
15+
"lint": "yarn special-lint && yarn pretty-lint && tsc",
1316
"special-lint": "node lockfile-lint"
1417
},
1518
"peerDependencies": {

precompile-schemas/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ajv.addKeyword({
4343
code(ctx) {
4444
const { data, schema } = ctx;
4545
ctx.fail(
46-
_`${data}.includes("!") || (absolutePathRegExp.test(${data}) !== ${schema})`
46+
_`${data}.includes("!") || (absolutePathRegExp.test(${data}) !== ${schema})`,
4747
);
4848
},
4949
});
@@ -84,8 +84,8 @@ ajv.addKeyword({
8484
`Schema precompilation only supports primitive values in enum: ${JSON.stringify(
8585
item,
8686
null,
87-
2
88-
)}`
87+
2,
88+
)}`,
8989
);
9090
}
9191
}
@@ -99,7 +99,7 @@ ajv.addKeyword({
9999

100100
return _`${data} !== ${x}`;
101101
})
102-
.reduce((a, b) => _`${a} && ${b}`)
102+
.reduce((a, b) => _`${a} && ${b}`),
103103
);
104104
},
105105
});
@@ -163,7 +163,7 @@ const createDeclaration = (schemaPath, title, schemasDir) => {
163163
const filename = path.resolve(
164164
root,
165165
declarations,
166-
`${path.join(directory, basename)}`
166+
`${path.join(directory, basename)}`,
167167
);
168168
const fromSchemaToDeclaration = path
169169
.relative(path.dirname(schemaPath), filename)
@@ -213,12 +213,12 @@ const precompileSchema = async (schemaPath, schemasDir) => {
213213
const precompiledSchemaPath = schemaPath.replace(/\.json$/, ".check.js");
214214
const precompiledSchemaDeclarationPath = schemaPath.replace(
215215
/\.json$/,
216-
".check.d.ts"
216+
".check.d.ts",
217217
);
218218
updateFile(precompiledSchemaPath, code);
219219
updateFile(
220220
precompiledSchemaDeclarationPath,
221-
createDeclaration(schemaPath, title, schemasDir)
221+
createDeclaration(schemaPath, title, schemasDir),
222222
);
223223
} catch (e) {
224224
e.message += "\nduring precompilation of " + schemaPath;

0 commit comments

Comments
 (0)