Skip to content

Commit

Permalink
chore(deps): update dependency prettier to v3 (#815)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency prettier to v3
* style: prettier
* build: remove `@types/prettier` as prettier has it's own types
* build: update prettier API usage

---------
Co-authored-by: wolfy1339 <webmaster@wolfy1339.com>
  • Loading branch information
renovate[bot] committed Jul 6, 2023
1 parent 9f7f7f3 commit bedb17f
Show file tree
Hide file tree
Showing 24 changed files with 2,162 additions and 4,588 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ const handleWebhookEvent = (event: WebhookEvent) => {

const handleIssuesOpenedEvent = (event: IssuesOpenedEvent) => {
console.log(
`${event.sender.login} opened "${event.issue.title}" on ${event.repository.full_name}`
`${event.sender.login} opened "${event.issue.title}" on ${event.repository.full_name}`,
);
};
```
Expand Down
2 changes: 1 addition & 1 deletion bin/diff-interface-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const [
"first argument must be path to a property on an interface to compare the schema of",
"second argument must be path to a property on an interface to compare the schema of",
],
["full"]
["full"],
);

const schemas = loadMapOfSchemas();
Expand Down
16 changes: 8 additions & 8 deletions bin/extract-common-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const [
"first argument must be path to a property on an interface to extract into a common schema",
"second argument must be name of the interface the new common schema should generate",
],
["overwrite"]
["overwrite"],
);

const RequiredSchemaProperties = [
Expand All @@ -39,26 +39,26 @@ type CommonSchema = Required<
JSONSchema7;

function assertHasRequiredProperties(
schema: JSONSchema7
schema: JSONSchema7,
): asserts schema is CommonSchema {
const missingProperties = RequiredSchemaProperties.filter(
(property) => schema[property] === undefined
(property) => schema[property] === undefined,
).join(", ");

assert.ok(
missingProperties.length === 0,
`schema is missing the following required properties: ${missingProperties}`
`schema is missing the following required properties: ${missingProperties}`,
);
}

const writeNewCommonSchema = (name: string, schema: JSONSchema7) => {
const writeNewCommonSchema = async (name: string, schema: JSONSchema7) => {
const pathToSchema = `${pathToSchemas}/common/${name}.schema.json`;

assertHasRequiredProperties(schema);

fs.writeFileSync(
pathToSchema,
format(
await format(
JSON.stringify(schema, (key, value: unknown) => {
if (
key === "$ref" &&
Expand All @@ -71,9 +71,9 @@ const writeNewCommonSchema = (name: string, schema: JSONSchema7) => {

return value;
}),
{ parser: "json" }
{ parser: "json" },
),
{ flag: overwriteIfExists ? "w" : "wx" }
{ flag: overwriteIfExists ? "w" : "wx" },
);
};

Expand Down
6 changes: 3 additions & 3 deletions bin/format-with-prettier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import {
const [, { check: checkOnly }] = parseArgv(__filename, [], ["check"]);

const formatJsonInDirectory = (pathToJsons: string) => {
forEachJsonFile(pathToJsons, (filePath) => {
forEachJsonFile(pathToJsons, async (filePath) => {
const contentsBefore = fs.readFileSync(filePath, "utf-8");
const contentsAfter = format(
const contentsAfter = await format(
JSON.stringify(JSON.parse(contentsBefore) as JSONSchema7),
{ parser: "json" }
{ parser: "json" },
);

if (contentsBefore === contentsAfter) {
Expand Down
6 changes: 3 additions & 3 deletions bin/octokit-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async function run() {

fs.writeFileSync(
"./payload-schemas/schema.json",
format(
await format(
JSON.stringify(schema, (key, value: unknown) => {
if (key === "$id") {
return undefined;
Expand All @@ -137,8 +137,8 @@ async function run() {

return value;
}),
{ parser: "json" }
)
{ parser: "json" },
),
);
} catch (err) {
console.error(err);
Expand Down
10 changes: 5 additions & 5 deletions bin/octokit-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ parseArgv(__filename, []);
const getEventName = (ref: string): string => {
assert.ok(
ref.startsWith("#/definitions/"),
`${ref} does not point to definitions`
`${ref} does not point to definitions`,
);

assert.ok(
ref.endsWith("event"),
`${ref} does not point to an event definition`
`${ref} does not point to an event definition`,
);

const [, eventName] = /^#\/definitions\/(.+)[$_]event$/u.exec(ref) ?? [];
Expand All @@ -44,7 +44,7 @@ const buildEventPayloadMap = (schema: Schema): string => {

const getSchema = async () =>
JSON.parse(
await fs.readFile("./payload-schemas/schema.json", "utf-8")
await fs.readFile("./payload-schemas/schema.json", "utf-8"),
) as Schema;

declare module "json-schema" {
Expand All @@ -71,7 +71,7 @@ const compileSchema = async (): Promise<string> => {
}

return value;
}
},
) as JSONSchema4;

return compile(schema, "Schema", { format: false });
Expand All @@ -92,7 +92,7 @@ const run = async () => {

await fs.writeFile(
"./payload-types/schema.d.ts",
format(ts, { parser: "typescript" })
await format(ts, { parser: "typescript" }),
);
};

Expand Down
16 changes: 8 additions & 8 deletions bin/optimize-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const JSONSchema7TypeNameOrder = [
] as const;

const standardizeTypeProperty = (
types: JSONSchema7TypeName[]
types: JSONSchema7TypeName[],
): JSONSchema7TypeName | JSONSchema7TypeName[] => {
if (types.length === 1) {
return types[0];
Expand All @@ -39,7 +39,7 @@ const standardizeTypeProperty = (
};

const isNullType = (
object: JSONSchema7Definition
object: JSONSchema7Definition,
): object is { type: "null" | ["null"] } & JSONSchema7 => {
if (typeof object === "boolean") {
return false;
Expand Down Expand Up @@ -68,12 +68,12 @@ const addNullToObject = (object: JSONSchema7) => {
}
};

forEachJsonFile(pathToSchemas, (pathToSchema) => {
forEachJsonFile(pathToSchemas, async (pathToSchema) => {
const contents = JSON.parse(fs.readFileSync(pathToSchema, "utf-8"));

fs.writeFileSync(
pathToSchema,
format(
await format(
JSON.stringify(contents, (key, value: unknown | JSONSchema7) => {
if (!isJsonSchemaObject(value)) {
return value;
Expand Down Expand Up @@ -112,12 +112,12 @@ forEachJsonFile(pathToSchemas, (pathToSchema) => {
// { "type": "null" } & { ... } can be combined as "type" supports an array
if (value.oneOf.some(isNullType)) {
const [notNullType] = value.oneOf.filter(
(object) => !isNullType(object)
(object) => !isNullType(object),
);

assert.ok(
typeof notNullType !== "boolean",
"unexpected boolean in oneOf"
"unexpected boolean in oneOf",
);

if (!notNullType.$ref && !notNullType.allOf) {
Expand All @@ -135,7 +135,7 @@ forEachJsonFile(pathToSchemas, (pathToSchema) => {

return value;
}),
{ parser: "json" }
)
{ parser: "json" },
),
);
});
16 changes: 8 additions & 8 deletions bin/ref-common-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ const commonSchemas = fs
.map<[name: string, schema: JSONSchema7]>((commonSchema) => [
commonSchema,
normalizeSchema(
require(`../${pathToSchemas}/common/${commonSchema}`) as JSONSchema7
require(`../${pathToSchemas}/common/${commonSchema}`) as JSONSchema7,
),
]);

const findCommonSchema = (object: JSONSchema7) => {
const normalisedSchema = normalizeSchema(object);

const [schema] = commonSchemas.find(([, commonSchema]) =>
deepEqual(commonSchema, normalisedSchema)
deepEqual(commonSchema, normalisedSchema),
) ?? [null];

return schema;
};

const splitIntoObjectAndNull = (
object: Readonly<JSONSchema7>
object: Readonly<JSONSchema7>,
): [JSONSchema7, { type: "null" } | null] => {
// if the object cannot be null, just return the object
if (!ensureArray(object.type).includes("null")) {
Expand All @@ -56,7 +56,7 @@ const splitIntoObjectAndNull = (

let count = 0;

forEachJsonFile(pathToSchemas, (filePath) => {
forEachJsonFile(pathToSchemas, async (filePath) => {
if (filePath.includes("/common/")) {
return;
}
Expand All @@ -65,7 +65,7 @@ forEachJsonFile(pathToSchemas, (filePath) => {

fs.writeFileSync(
filePath,
format(
await format(
JSON.stringify(schema, (key, value) => {
if (typeof value === "object" && value !== null) {
const [object, nullType] = splitIntoObjectAndNull(value);
Expand All @@ -87,11 +87,11 @@ forEachJsonFile(pathToSchemas, (filePath) => {

return value;
}),
{ parser: "json" }
)
{ parser: "json" },
),
);
});

console.log(
`replaced ${count} ${count === 1 ? "property" : "properties"} with $ref`
`replaced ${count} ${count === 1 ? "property" : "properties"} with $ref`,
);
12 changes: 6 additions & 6 deletions bin/utils/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ type Join<T extends unknown[], D extends string> = T extends []

type CapitalizeIf<
Condition extends boolean,
T extends string
T extends string,
> = Condition extends true ? Capitalize<T> : T;

type SplitCamel<
S extends string,
D extends string,
IsTail extends boolean = false
IsTail extends boolean = false,
> = string extends S
? string[]
: S extends ""
Expand Down Expand Up @@ -49,7 +49,7 @@ const getArgsAndFlags = (argv: string[]): [args: string[], flags: string[]] => {

function assertHasRequiredArgs<T extends string[]>(
foundArgs: string[],
requiredArgs: T
requiredArgs: T,
): asserts foundArgs is T {
requiredArgs.forEach((missingMessage, index) => {
assert.ok(foundArgs[index], missingMessage);
Expand Down Expand Up @@ -81,12 +81,12 @@ const getHelpText = (pathToScript: string, full = false): string => {

const isSupportedFlag = <TFlag extends string>(
flag: string,
supportedFlags: TFlag[]
supportedFlags: TFlag[],
): flag is TFlag => supportedFlags.includes(flag as TFlag);

const processFlags = <TFlag extends string>(
flags: string[],
supportedFlags: TFlag[] = []
supportedFlags: TFlag[] = [],
): CamelCasedFlags<TFlag> => {
const finalFlags: CamelCasedFlags<TFlag> = {};

Expand All @@ -106,7 +106,7 @@ const processFlags = <TFlag extends string>(
export const parseArgv = <TRequiredArgs extends string[], TFlag extends string>(
pathToScript: string,
argsMissingMessages: TRequiredArgs,
supportedFlags: TFlag[] = []
supportedFlags: TFlag[] = [],
): [args: TRequiredArgs, flags: CamelCasedFlags<TFlag>] => {
const [foundArgs, flags] = getArgsAndFlags(process.argv.slice(2));

Expand Down
2 changes: 1 addition & 1 deletion bin/utils/forEachJsonFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from "fs";

export const forEachJsonFile = (
directory: string,
callback: (pathToFile: string) => void
callback: (pathToFile: string) => void,
) => {
fs.readdirSync(directory, { withFileTypes: true }).forEach((entity) => {
const pathToEntity = `${directory}/${entity.name}`;
Expand Down
8 changes: 4 additions & 4 deletions bin/utils/getSchemaFromPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const extractFromSchema = (schema: JSONSchema7, name: string): JSONSchema7 => {
if (ensureArray(schema.type).includes("object")) {
assert.ok(
schema.properties,
"cannot extract from an object-type schema that lacks properties"
"cannot extract from an object-type schema that lacks properties",
);

const value = schema.properties[name];
Expand All @@ -25,17 +25,17 @@ const extractFromSchema = (schema: JSONSchema7, name: string): JSONSchema7 => {
}

throw new Error(
`schemas can only be extracted from objects or arrays (got ${schema.type})`
`schemas can only be extracted from objects or arrays (got ${schema.type})`,
);
};

export const getSchemaFromPath = (
interfacePropertyPath: string,
schemas: Record<string, JSONSchema7>
schemas: Record<string, JSONSchema7>,
): JSONSchema7 =>
interfacePropertyPath
.split(".")
.reduce<JSONSchema7>(
(schema, segment) => extractFromSchema(schema, segment),
{ type: "object", properties: schemas }
{ type: "object", properties: schemas },
);
2 changes: 1 addition & 1 deletion bin/utils/loadMapOfSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const loadMapOfSchemas = (): Record<string, JSONSchema7> => {

forEachJsonFile(pathToSchemas, (pathToSchema) => {
const schema = JSON.parse(
fs.readFileSync(pathToSchema, "utf-8")
fs.readFileSync(pathToSchema, "utf-8"),
) as JSONSchema7;

entries.push([guessAtInterfaceName(schema), schema]);
Expand Down
6 changes: 3 additions & 3 deletions bin/validate-payload-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { forEachJsonFile, parseArgv, pathToPayloads } from "./utils";
const [, { continueOnError = false }] = parseArgv(
__filename,
[],
["continue-on-error"]
["continue-on-error"],
);

const printAjvErrors = () => {
Expand All @@ -18,7 +18,7 @@ const printAjvErrors = () => {
ajv.errors?.forEach((error) => {
const similarError = finalErrors.find(
(er) =>
er.keyword === error.keyword && er.instancePath === error.instancePath
er.keyword === error.keyword && er.instancePath === error.instancePath,
) as DefinedError | undefined;

if (similarError?.keyword === "enum") {
Expand All @@ -37,7 +37,7 @@ forEachJsonFile(pathToPayloads, (filePath) => {
if (filePath.includes("/index.json")) return;
const file = require(`../${filePath}`) as unknown;
const { dir: event, base: filename } = path.parse(
path.relative(pathToPayloads, filePath)
path.relative(pathToPayloads, filePath),
);

try {
Expand Down
2 changes: 1 addition & 1 deletion bin/validate-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ addFormats(ajv);
ajv.addKeyword("tsAdditionalProperties");

const schema = JSON.parse(
readFileSync(resolve(__dirname, "../payload-schemas/schema.json"), "utf-8")
readFileSync(resolve(__dirname, "../payload-schemas/schema.json"), "utf-8"),
);

// if this is invalid, an error will be thrown
Expand Down
Loading

0 comments on commit bedb17f

Please sign in to comment.