Skip to content

Commit

Permalink
apply formatting before pr
Browse files Browse the repository at this point in the history
  • Loading branch information
David Blass committed May 22, 2024
1 parent 244dbda commit 382d039
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 98 deletions.
30 changes: 12 additions & 18 deletions ark/attest/__tests__/benchExpectedOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,39 @@ const fakeCallOptions = {

bench(
"bench call single stat median",
() => {
return "boofoozoo".includes("foo")
},
() => "boofoozoo".includes("foo"),
fakeCallOptions
).median([2, "ms"])

bench(
"bench call single stat",
() => {
return "boofoozoo".includes("foo")
},
() => "boofoozoo".includes("foo"),
fakeCallOptions
).mean([2, "ms"])

bench(
"bench call mark",
() => {
return /.*foo.*/.test("boofoozoo")
},
() => /.*foo.*/.test("boofoozoo"),
fakeCallOptions
).mark({ mean: [2, "ms"], median: [2, "ms"] })

type makeComplexType<S extends string> =
S extends `${infer head}${infer tail}` ? head | tail | makeComplexType<tail>
: S

bench("bench type", () => {
return {} as makeComplexType<"defenestration">
}).types([176, "instantiations"])
bench("bench type", () => ({}) as makeComplexType<"defenestration">).types([
176,
"instantiations"
])

bench("bench type from external module", () => {
return {} as externalmakeComplexType<"defenestration">
}).types([193, "instantiations"])
bench(
"bench type from external module",
() => ({}) as externalmakeComplexType<"defenestration">
).types([193, "instantiations"])

bench(
"bench call and type",
() => {
return {} as makeComplexType<"antidisestablishmentarianism">
},
() => ({}) as makeComplexType<"antidisestablishmentarianism">,
fakeCallOptions
)
.mean([2, "ms"])
Expand Down
27 changes: 9 additions & 18 deletions ark/attest/__tests__/benchTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,36 @@ const fakeCallOptions = {

bench(
"bench call single stat median",
() => {
return "boofoozoo".includes("foo")
},
() => "boofoozoo".includes("foo"),
fakeCallOptions
).median()

bench(
"bench call single stat",
() => {
return "boofoozoo".includes("foo")
},
() => "boofoozoo".includes("foo"),
fakeCallOptions
).mean()

bench(
"bench call mark",
() => {
return /.*foo.*/.test("boofoozoo")
},
() => /.*foo.*/.test("boofoozoo"),
fakeCallOptions
).mark()

type makeComplexType<S extends string> =
S extends `${infer head}${infer tail}` ? head | tail | makeComplexType<tail>
: S

bench("bench type", () => {
return {} as makeComplexType<"defenestration">
}).types()
bench("bench type", () => ({}) as makeComplexType<"defenestration">).types()

bench("bench type from external module", () => {
return {} as externalmakeComplexType<"defenestration">
}).types()
bench(
"bench type from external module",
() => ({}) as externalmakeComplexType<"defenestration">
).types()

bench(
"bench call and type",
() => {
return {} as makeComplexType<"antidisestablishmentarianism">
},
() => ({}) as makeComplexType<"antidisestablishmentarianism">,
fakeCallOptions
)
.mean()
Expand Down
7 changes: 3 additions & 4 deletions ark/attest/bench/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,13 @@ export const getBenchCtx = (
qualifiedPath: string[],
isAsync: boolean = false,
options: BenchOptions = {}
): BenchContext => {
return {
): BenchContext =>
({
qualifiedPath,
qualifiedName: qualifiedPath.join("/"),
options,
cfg: getConfig(),
benchCallPosition: caller(),
lastSnapCallPosition: undefined,
isAsync
} as BenchContext
}
}) as BenchContext
10 changes: 4 additions & 6 deletions ark/attest/bench/measure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ export type TypeUnit = (typeof TYPE_UNITS)[number]
export const createTypeComparison = (
value: number,
baseline: Measure<TypeUnit> | undefined
): MeasureComparison<TypeUnit> => {
return {
updated: [value, "instantiations"],
baseline
}
}
): MeasureComparison<TypeUnit> => ({
updated: [value, "instantiations"],
baseline
})

export const timeUnitRatios = {
ns: 0.000_001,
Expand Down
6 changes: 3 additions & 3 deletions ark/attest/cache/getCachedAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ const getAssertionsOfKindAtPosition = <kind extends TypeAssertionKind>(
`Found no assertion data for '${fileKey}' for TypeScript version ${version}.`
)
}
const matchingAssertion = assertions[fileKey].find(assertion => {
const matchingAssertion = assertions[fileKey].find(assertion =>
/**
* Depending on the environment, a trace can refer to any of these points
* attest(...)
* ^ ^ ^
* Because of this, it's safest to check if the call came from anywhere in the expected range.
*
*/
return isPositionWithinRange(position, assertion.location)
})
isPositionWithinRange(position, assertion.location)
)
if (!matchingAssertion) {
throw new Error(
`Found no assertion for TypeScript version ${version} at line ${position.line} char ${position.char} in '${fileKey}'.
Expand Down
34 changes: 15 additions & 19 deletions ark/attest/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,21 @@ type BaseAttestConfig = {

export type AttestConfig = Partial<BaseAttestConfig>

export const getDefaultAttestConfig = (): BaseAttestConfig => {
return {
tsconfig:
existsSync(fromCwd("tsconfig.json")) ?
fromCwd("tsconfig.json")
: undefined,
attestAliases: ["attest", "attestInternal"],
updateSnapshots: false,
skipTypes: false,
skipInlineInstantiations: false,
tsVersions: "typescript",
benchPercentThreshold: 20,
benchErrorOnThresholdExceeded: false,
filter: undefined,
testDeclarationAliases: ["bench", "it"],
formatter: `npm exec --no -- prettier --write`,
shouldFormat: true
}
}
export const getDefaultAttestConfig = (): BaseAttestConfig => ({
tsconfig:
existsSync(fromCwd("tsconfig.json")) ? fromCwd("tsconfig.json") : undefined,
attestAliases: ["attest", "attestInternal"],
updateSnapshots: false,
skipTypes: false,
skipInlineInstantiations: false,
tsVersions: "typescript",
benchPercentThreshold: 20,
benchErrorOnThresholdExceeded: false,
filter: undefined,
testDeclarationAliases: ["bench", "it"],
formatter: `npm exec --no -- prettier --write`,
shouldFormat: true
})

const hasFlag = (flag: keyof AttestConfig) =>
process.argv.some(arg => arg.includes(flag))
Expand Down
17 changes: 9 additions & 8 deletions ark/docs/src/components/HomeDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ const translateVSCodeTheme = (
colors: theme.colors,
rules: theme.tokenColors.flatMap(c => {
if (Array.isArray(c.scope)) {
return c.scope.map(sub => {
return {
token: sub,
background: c.settings.background,
foreground: c.settings.foreground,
fontStyle: c.settings.fontStyle
} as Monaco.editor.ITokenThemeRule
})
return c.scope.map(
sub =>
({
token: sub,
background: c.settings.background,
foreground: c.settings.foreground,
fontStyle: c.settings.fontStyle
}) as Monaco.editor.ITokenThemeRule
)
}
return {
token: c.scope,
Expand Down
4 changes: 1 addition & 3 deletions ark/fs/getCurrentLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,4 @@ export const getCurrentLine = (
frames: 0,
immediate: false
}
): Location => {
return getLocationFromError(new Error(), offset)
}
): Location => getLocationFromError(new Error(), offset)
11 changes: 5 additions & 6 deletions ark/schema/__tests__/parse.bench.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { bench } from "@arktype/attest"
import { schema } from "@arktype/schema"

bench("domain", () => {
return schema("string").infer
}).types([2, "instantiations"])
bench("domain", () => schema("string").infer).types([2, "instantiations"])

bench("intersection", () => {
return schema("string").and(schema("number"))
}).types([846, "instantiations"])
bench("intersection", () => schema("string").and(schema("number"))).types([
846,
"instantiations"
])

bench("no assignment", () => {
schema({ domain: "string", regex: "/.*/" })
Expand Down
4 changes: 1 addition & 3 deletions ark/schema/roots/intersection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,7 @@ export const intersectionImplementation: nodeImplementationOf<IntersectionDeclar
problem: ctx => `must be...\n${ctx.expected}`
},
intersections: {
intersection: (l, r, ctx) => {
return intersectIntersections(l, r, ctx)
},
intersection: (l, r, ctx) => intersectIntersections(l, r, ctx),
...defineRightwardIntersections("intersection", (l, r, ctx) => {
// if l is unknown, return r
if (l.children.length === 0) return r
Expand Down
4 changes: 3 additions & 1 deletion ark/type/__tests__/expressions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ contextualize(
"email",
"uuid",
"semver",
"ip",
"Record",
"instanceof",
"===",
Expand Down Expand Up @@ -90,7 +91,6 @@ contextualize(
"keyof",
"parse",
"void",
"[]",
"url",
"alpha",
"alphanumeric",
Expand All @@ -100,7 +100,9 @@ contextualize(
"email",
"uuid",
"semver",
"ip",
"Record",
"[]",
"|",
":",
"=>",
Expand Down
1 change: 0 additions & 1 deletion ark/type/parser/string/shift/operator/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const parseOperator = (s: DynamicStateWithRoot): void => {
)
}


export type parseOperator<s extends StaticState, $, args> =
s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ?
lookahead extends "[" ?
Expand Down
5 changes: 2 additions & 3 deletions ark/util/__tests__/hkt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ contextualize(() => {
const AddD = new (class AddD extends Hkt.UnaryKind {
hkt = (
args: conform<this[Hkt.args], { c: number }>
): show<typeof args & { d: (typeof args)["c"] }> => {
return Object.assign(args, { d: args.c } as const)
}
): show<typeof args & { d: (typeof args)["c"] }> =>
Object.assign(args, { d: args.c } as const)
})()
// @ts-expect-error
attest(() => Hkt.pipe(AddB, AddD)).type.errors.snap(
Expand Down
9 changes: 4 additions & 5 deletions ark/util/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ export type RegisteredReference<to extends string = string> = `$ark.${to}`
export const isDotAccessible = (keyName: string): boolean =>
/^[a-zA-Z_$][a-zA-Z_$0-9]*$/.test(keyName)

export const compileSerializedValue = (value: unknown): string => {
return hasDomain(value, "object") || typeof value === "symbol" ?
registeredReference(value)
: serializePrimitive(value as SerializablePrimitive)
}
export const compileSerializedValue = (value: unknown): string =>
hasDomain(value, "object") || typeof value === "symbol" ?
registeredReference(value)
: serializePrimitive(value as SerializablePrimitive)

const baseNameFor = (value: object | symbol) => {
switch (typeof value) {
Expand Down

0 comments on commit 382d039

Please sign in to comment.