Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update to prettier 3.2.5 #2385

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/.vuepress/theme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ module.exports = (options, ctx) => {
return {
alias() {
return {
"@AlgoliaSearchBox": isAlgoliaSearch
? path.resolve(__dirname, "components/AlgoliaSearchBox.vue")
"@AlgoliaSearchBox":
isAlgoliaSearch ?
path.resolve(__dirname, "components/AlgoliaSearchBox.vue")
: path.resolve(__dirname, "noopModule.js"),
}
},
Expand Down
5 changes: 2 additions & 3 deletions lib/ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ class Ajv extends AjvCore {
_addDefaultMetaSchema(): void {
super._addDefaultMetaSchema()
if (!this.opts.meta) return
const metaSchema = this.opts.$data
? this.$dataMetaSchema(draft7MetaSchema, META_SUPPORT_DATA)
: draft7MetaSchema
const metaSchema =
this.opts.$data ? this.$dataMetaSchema(draft7MetaSchema, META_SUPPORT_DATA) : draft7MetaSchema
this.addMetaSchema(metaSchema, META_SCHEMA_ID, false)
this.refs["http://json-schema.org/schema"] = META_SCHEMA_ID
}
Expand Down
10 changes: 7 additions & 3 deletions lib/compile/codegen/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,17 @@ function mergeExprItems(a: CodeItem, b: CodeItem): CodeItem | undefined {
}

export function strConcat(c1: Code, c2: Code): Code {
return c2.emptyStr() ? c1 : c1.emptyStr() ? c2 : str`${c1}${c2}`
return (
c2.emptyStr() ? c1
: c1.emptyStr() ? c2
: str`${c1}${c2}`
)
}

// TODO do not allow arrays here
function interpolate(x?: string | string[] | number | boolean | null): SafeExpr | string {
return typeof x == "number" || typeof x == "boolean" || x === null
? x
return typeof x == "number" || typeof x == "boolean" || x === null ?
x
: safeStringify(Array.isArray(x) ? x.join(",") : x)
}

Expand Down
35 changes: 29 additions & 6 deletions lib/compile/codegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ abstract class Node {
}

class Def extends Node {
constructor(private readonly varKind: Name, private readonly name: Name, private rhs?: SafeExpr) {
constructor(
private readonly varKind: Name,
private readonly name: Name,
private rhs?: SafeExpr
) {
super()
}

Expand All @@ -63,7 +67,11 @@ class Def extends Node {
}

class Assign extends Node {
constructor(readonly lhs: Code, public rhs: SafeExpr, private readonly sideEffects?: boolean) {
constructor(
readonly lhs: Code,
public rhs: SafeExpr,
private readonly sideEffects?: boolean
) {
super()
}

Expand All @@ -84,7 +92,12 @@ class Assign extends Node {
}

class AssignOp extends Assign {
constructor(lhs: Code, private readonly op: Code, rhs: SafeExpr, sideEffects?: boolean) {
constructor(
lhs: Code,
private readonly op: Code,
rhs: SafeExpr,
sideEffects?: boolean
) {
super(lhs, rhs, sideEffects)
}

Expand Down Expand Up @@ -211,7 +224,10 @@ class Else extends BlockNode {
class If extends BlockNode {
static readonly kind = "if"
else?: If | Else
constructor(private condition: Code | boolean, nodes?: ChildNode[]) {
constructor(
private condition: Code | boolean,
nodes?: ChildNode[]
) {
super(nodes)
}

Expand Down Expand Up @@ -331,7 +347,11 @@ class ForIter extends For {

class Func extends BlockNode {
static readonly kind = "func"
constructor(public name: Name, public args: Code, public async?: boolean) {
constructor(
public name: Name,
public args: Code,
public async?: boolean
) {
super()
}

Expand Down Expand Up @@ -824,7 +844,10 @@ export function or(...args: Code[]): Code {
type MAppend = (x: Code, y: Code) => Code

function mappend(op: Code): MAppend {
return (x, y) => (x === nil ? y : y === nil ? x : _`${par(x)} ${op} ${par(y)}`)
return (x, y) =>
x === nil ? y
: y === nil ? x
: _`${par(x)} ${op} ${par(y)}`
}

function par(x: Code): Code {
Expand Down
11 changes: 5 additions & 6 deletions lib/compile/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export const keywordError: KeywordErrorDefinition = {

export const keyword$DataError: KeywordErrorDefinition = {
message: ({keyword, schemaType}) =>
schemaType
? str`"${keyword}" keyword must be ${schemaType} ($data)`
: str`"${keyword}" keyword is invalid ($data)`,
schemaType ?
str`"${keyword}" keyword must be ${schemaType} ($data)`
: str`"${keyword}" keyword is invalid ($data)`,
}

export interface ErrorPaths {
Expand Down Expand Up @@ -142,9 +142,8 @@ function errorObject(
}

function errorInstancePath({errorPath}: SchemaCxt, {instancePath}: ErrorPaths): [Name, Code] {
const instPath = instancePath
? str`${errorPath}${getErrorPath(instancePath, Type.Str)}`
: errorPath
const instPath =
instancePath ? str`${errorPath}${getErrorPath(instancePath, Type.Str)}` : errorPath
return [N.instancePath, strConcat(N.instancePath, instPath)]
}

Expand Down
6 changes: 3 additions & 3 deletions lib/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ export function compileSchema(this: Ajv, sch: SchemaEnv): SchemaEnv {
definedProperties: new Set<string>(),
topSchemaRef: gen.scopeValue(
"schema",
this.opts.code.source === true
? {ref: sch.schema, code: stringify(sch.schema)}
: {ref: sch.schema}
this.opts.code.source === true ?
{ref: sch.schema, code: stringify(sch.schema)}
: {ref: sch.schema}
),
validateName,
ValidationError: _ValidationError,
Expand Down
13 changes: 7 additions & 6 deletions lib/compile/jtd/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,9 @@ function parseType(cxt: ParseCxt): void {
const vts = useFunc(gen, validTimestamp)
const {allowDate, parseDate} = self.opts
const notValid = allowDate ? _`!${vts}(${data}, true)` : _`!${vts}(${data})`
const fail: Code = parseDate
? or(notValid, _`(${data} = new Date(${data}), false)`, _`isNaN(${data}.valueOf())`)
const fail: Code =
parseDate ?
or(notValid, _`(${data} = new Date(${data}), false)`, _`isNaN(${data}.valueOf())`)
: notValid
gen.if(fail, () => parsingError(cxt, str`invalid timestamp`))
break
Expand Down Expand Up @@ -350,8 +351,8 @@ function parseRef(cxt: ParseCxt): void {
}

function getParser(gen: CodeGen, sch: SchemaEnv): Code {
return sch.parse
? gen.scopeValue("parse", {ref: sch.parse})
return sch.parse ?
gen.scopeValue("parse", {ref: sch.parse})
: _`${gen.scopeValue("wrapper", {ref: sch})}.parse`
}

Expand Down Expand Up @@ -395,8 +396,8 @@ function skipWhitespace({gen, char: c}: ParseCxt): void {
}

function jsonSlice(len: number | Name): Code {
return len === 1
? _`${N.json}[${N.jsonPos}]`
return len === 1 ?
_`${N.json}[${N.jsonPos}]`
: _`${N.json}.slice(${N.jsonPos}, ${N.jsonPos}+${len})`
}

Expand Down
4 changes: 2 additions & 2 deletions lib/compile/jtd/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ function serializeRef(cxt: SerializeCxt): void {
}

function getSerialize(gen: CodeGen, sch: SchemaEnv): Code {
return sch.serialize
? gen.scopeValue("serialize", {ref: sch.serialize})
return sch.serialize ?
gen.scopeValue("serialize", {ref: sch.serialize})
: _`${gen.scopeValue("wrapper", {ref: sch})}.serialize`
}

Expand Down
24 changes: 11 additions & 13 deletions lib/compile/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,11 @@ function makeMergeEvaluated<T extends SomeEvaluated>({
}: MakeMergeFuncArgs<T>): MergeEvaluatedFunc<T> {
return (gen, from, to, toName) => {
const res =
to === undefined
? from
: to instanceof Name
? (from instanceof Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to)
: from instanceof Name
? (mergeToName(gen, to, from), from)
: mergeValues(from, to)
to === undefined ? from
: to instanceof Name ?
(from instanceof Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to)
: from instanceof Name ? (mergeToName(gen, to, from), from)
: mergeValues(from, to)
return toName === Name && !(res instanceof Name) ? resultToName(gen, res) : res
}
}
Expand Down Expand Up @@ -190,13 +188,13 @@ export function getErrorPath(
// let path
if (dataProp instanceof Name) {
const isNumber = dataPropType === Type.Num
return jsPropertySyntax
? isNumber
? _`"[" + ${dataProp} + "]"`
return (
jsPropertySyntax ?
isNumber ? _`"[" + ${dataProp} + "]"`
: _`"['" + ${dataProp} + "']"`
: isNumber
? _`"/" + ${dataProp}`
: _`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")` // TODO maybe use global escapePointer
: isNumber ? _`"/" + ${dataProp}`
: _`"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`
) // TODO maybe use global escapePointer
}
return jsPropertySyntax ? getProperty(dataProp).toString() : "/" + escapeJsonPointer(dataProp)
}
Expand Down
9 changes: 6 additions & 3 deletions lib/compile/validate/dataType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export function getSchemaTypes(schema: AnySchemaObject): JSONType[] {
}

export function getJSONTypes(ts: unknown | unknown[]): JSONType[] {
const types: unknown[] = Array.isArray(ts) ? ts : ts ? [ts] : []
const types: unknown[] =
Array.isArray(ts) ? ts
: ts ? [ts]
: []
if (types.every(isJSONType)) return types
throw new Error("type must be JSONType or JSONType[]: " + types.join(","))
}
Expand All @@ -54,8 +57,8 @@ export function coerceAndCheckDataType(it: SchemaObjCxt, types: JSONType[]): boo

const COERCIBLE: Set<JSONType> = new Set(["string", "number", "integer", "boolean", "null"])
function coerceToTypes(types: JSONType[], coerceTypes?: boolean | "array"): JSONType[] {
return coerceTypes
? types.filter((t) => COERCIBLE.has(t) || (coerceTypes === "array" && t === "array"))
return coerceTypes ?
types.filter((t) => COERCIBLE.has(t) || (coerceTypes === "array" && t === "array"))
: []
}

Expand Down
8 changes: 3 additions & 5 deletions lib/compile/validate/keyword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,9 @@ export function validSchemaType(
return (
!schemaType.length ||
schemaType.some((st) =>
st === "array"
? Array.isArray(schema)
: st === "object"
? schema && typeof schema == "object" && !Array.isArray(schema)
: typeof schema == st || (allowUndefined && typeof schema == "undefined")
st === "array" ? Array.isArray(schema)
: st === "object" ? schema && typeof schema == "object" && !Array.isArray(schema)
: typeof schema == st || (allowUndefined && typeof schema == "undefined")
)
)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/compile/validate/subschema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export function getSubschema(

if (keyword !== undefined) {
const sch = it.schema[keyword]
return schemaProp === undefined
? {
return schemaProp === undefined ?
{
schema: sch,
schemaPath: _`${it.schemaPath}${getProperty(keyword)}`,
errSchemaPath: `${it.errSchemaPath}/${keyword}`,
Expand Down
6 changes: 3 additions & 3 deletions lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,9 @@ export default class Ajv {
}
eachItem(
keyword,
definition.type.length === 0
? (k) => addRule.call(this, k, definition)
: (k) => definition.type.forEach((t) => addRule.call(this, k, definition, t))
definition.type.length === 0 ?
(k) => addRule.call(this, k, definition)
: (k) => definition.type.forEach((t) => addRule.call(this, k, definition, t))
)
return this
}
Expand Down
14 changes: 6 additions & 8 deletions lib/runtime/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ export default function quote(s: string): string {
rxEscapable.lastIndex = 0
return (
'"' +
(rxEscapable.test(s)
? s.replace(rxEscapable, (a) => {
const c = escaped[a]
return typeof c === "string"
? c
: "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
})
: s) +
(rxEscapable.test(s) ?
s.replace(rxEscapable, (a) => {
const c = escaped[a]
return typeof c === "string" ? c : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4)
})
: s) +
'"'
)
}
Expand Down
13 changes: 7 additions & 6 deletions lib/standalone/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ function standaloneCode(
throw new Error("moduleCode: ajv instance must have code.source option")
}
const {_n} = ajv.scope.opts
return typeof refsOrFunc == "function"
? funcExportCode(refsOrFunc.source)
: refsOrFunc !== undefined
? multiExportsCode<string>(refsOrFunc, getValidate)
return (
typeof refsOrFunc == "function" ? funcExportCode(refsOrFunc.source)
: refsOrFunc !== undefined ? multiExportsCode<string>(refsOrFunc, getValidate)
: multiExportsCode<SchemaEnv>(ajv.schemas, (sch) =>
sch.meta ? undefined : ajv.compile(sch.schema)
)
)

function getValidate(id: string): AnyValidateFunction {
const v = ajv.getSchema(id)
Expand Down Expand Up @@ -47,8 +47,9 @@ function standaloneCode(
const v = getValidateFunc(schemas[name] as T)
if (v) {
const vCode = validateCode(usedValues, v.source)
const exportSyntax = ajv.opts.code.esm
? _`export const ${getEsmExportName(name)}`
const exportSyntax =
ajv.opts.code.esm ?
_`export const ${getEsmExportName(name)}`
: _`exports${getProperty(name)}`
code = _`${code}${_n}${exportSyntax} = ${v.source?.validateName};${_n}${vCode}`
}
Expand Down
9 changes: 6 additions & 3 deletions lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ export interface DataValidateFunction {
}

export interface SchemaValidateFunction {
(schema: any, data: any, parentSchema?: AnySchemaObject, dataCxt?: DataValidationCxt):
| boolean
| Promise<any>
(
schema: any,
data: any,
parentSchema?: AnySchemaObject,
dataCxt?: DataValidationCxt
): boolean | Promise<any>
errors?: Partial<ErrorObject>[]
}

Expand Down
Loading
Loading