From e4f963ae15cd66729e24255ebc87b2cf459ab4ce Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Sat, 24 Feb 2024 12:16:27 +0200 Subject: [PATCH] style: Apply updated Prettier rules --- docs/06_custom_tags.md | 20 ++++++++++---------- src/compose/compose-collection.ts | 12 ++++++------ src/compose/compose-scalar.ts | 4 ++-- src/compose/resolve-flow-collection.ts | 11 +++++++++-- src/doc/createNode.ts | 8 ++++---- src/nodes/Node.ts | 16 ++++++++-------- src/schema/Schema.ts | 8 ++++---- src/schema/core/float.ts | 4 ++-- src/schema/yaml-1.1/float.ts | 4 ++-- src/stringify/stringify.ts | 4 ++-- src/stringify/stringifyComment.ts | 4 ++-- src/stringify/stringifyString.ts | 8 ++++---- tests/doc/stringify.ts | 6 ++++-- 13 files changed, 59 insertions(+), 50 deletions(-) diff --git a/docs/06_custom_tags.md b/docs/06_custom_tags.md index 9bae8d09..c36d9477 100644 --- a/docs/06_custom_tags.md +++ b/docs/06_custom_tags.md @@ -118,16 +118,16 @@ class YAMLError extends YAMLMap { name === 'EvalError' ? EvalError : name === 'RangeError' - ? RangeError - : name === 'ReferenceError' - ? ReferenceError - : name === 'SyntaxError' - ? SyntaxError - : name === 'TypeError' - ? TypeError - : name === 'URIError' - ? URIError - : Error + ? RangeError + : name === 'ReferenceError' + ? ReferenceError + : name === 'SyntaxError' + ? SyntaxError + : name === 'TypeError' + ? TypeError + : name === 'URIError' + ? URIError + : Error if (Cls.name !== name) { Object.defineProperty(er, 'name', { value: name, diff --git a/src/compose/compose-collection.ts b/src/compose/compose-collection.ts index 3cd8e756..7b18756f 100644 --- a/src/compose/compose-collection.ts +++ b/src/compose/compose-collection.ts @@ -28,8 +28,8 @@ function resolveCollection( token.type === 'block-map' ? resolveBlockMap(CN, ctx, token, onError, tag) : token.type === 'block-seq' - ? resolveBlockSeq(CN, ctx, token, onError, tag) - : resolveFlowCollection(CN, ctx, token, onError, tag) + ? resolveBlockSeq(CN, ctx, token, onError, tag) + : resolveFlowCollection(CN, ctx, token, onError, tag) const Coll = coll.constructor as typeof YAMLMap | typeof YAMLSeq @@ -60,10 +60,10 @@ export function composeCollection( token.type === 'block-map' ? 'map' : token.type === 'block-seq' - ? 'seq' - : token.start.source === '{' - ? 'map' - : 'seq' + ? 'seq' + : token.start.source === '{' + ? 'map' + : 'seq' // shortcut: check if it's a generic YAMLMap or YAMLSeq // before jumping into the custom tag logic. diff --git a/src/compose/compose-scalar.ts b/src/compose/compose-scalar.ts index 726f777e..5b6b210e 100644 --- a/src/compose/compose-scalar.ts +++ b/src/compose/compose-scalar.ts @@ -28,8 +28,8 @@ export function composeScalar( tagToken && tagName ? findScalarTagByName(ctx.schema, value, tagName, tagToken, onError) : token.type === 'scalar' - ? findScalarTagByTest(ctx, value, token, onError) - : ctx.schema[SCALAR] + ? findScalarTagByTest(ctx, value, token, onError) + : ctx.schema[SCALAR] let scalar: Scalar try { diff --git a/src/compose/resolve-flow-collection.ts b/src/compose/resolve-flow-collection.ts index 5b418d72..93d30ef0 100644 --- a/src/compose/resolve-flow-collection.ts +++ b/src/compose/resolve-flow-collection.ts @@ -169,8 +169,15 @@ export function resolveFlowCollection( const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found - ? composeEmptyNode(ctx, valueProps.end, sep, null, valueProps, onError) - : null + ? composeEmptyNode( + ctx, + valueProps.end, + sep, + null, + valueProps, + onError + ) + : null if (valueNode) { if (isBlock(value)) onError(valueNode.range, 'BLOCK_IN_FLOW', blockMsg) } else if (valueProps.comment) { diff --git a/src/doc/createNode.ts b/src/doc/createNode.ts index ba415a7a..c80805d2 100644 --- a/src/doc/createNode.ts +++ b/src/doc/createNode.ts @@ -89,8 +89,8 @@ export function createNode( value instanceof Map ? schema[MAP] : Symbol.iterator in Object(value) - ? schema[SEQ] - : schema[MAP] + ? schema[SEQ] + : schema[MAP] } if (onTagObj) { onTagObj(tagObj) @@ -100,8 +100,8 @@ export function createNode( const node = tagObj?.createNode ? tagObj.createNode(ctx.schema, value, ctx) : typeof tagObj?.nodeClass?.from === 'function' - ? tagObj.nodeClass.from(ctx.schema, value, ctx) - : new Scalar(value) + ? tagObj.nodeClass.from(ctx.schema, value, ctx) + : new Scalar(value) if (tagName) node.tag = tagName else if (!tagObj.default) node.tag = tagObj.tag diff --git a/src/nodes/Node.ts b/src/nodes/Node.ts index 00595a2b..d590012c 100644 --- a/src/nodes/Node.ts +++ b/src/nodes/Node.ts @@ -26,14 +26,14 @@ export type NodeType = T extends | undefined ? Scalar : T extends Date - ? Scalar - : T extends Array - ? YAMLSeq> - : T extends { [key: string]: any } - ? YAMLMap, NodeType> - : T extends { [key: number]: any } // Merge with previous once supported in all TS versions - ? YAMLMap, NodeType> - : Node + ? Scalar + : T extends Array + ? YAMLSeq> + : T extends { [key: string]: any } + ? YAMLMap, NodeType> + : T extends { [key: number]: any } // Merge with previous once supported in all TS versions + ? YAMLMap, NodeType> + : Node export type ParsedNode = | Alias.Parsed diff --git a/src/schema/Schema.ts b/src/schema/Schema.ts index 74ad2af0..4c9f240c 100644 --- a/src/schema/Schema.ts +++ b/src/schema/Schema.ts @@ -36,8 +36,8 @@ export class Schema { this.compat = Array.isArray(compat) ? getTags(compat, 'compat') : compat - ? getTags(null, compat) - : null + ? getTags(null, compat) + : null this.merge = !!merge this.name = (typeof schema === 'string' && schema) || 'core' this.knownTags = resolveKnownTags ? coreKnownTags : {} @@ -53,8 +53,8 @@ export class Schema { typeof sortMapEntries === 'function' ? sortMapEntries : sortMapEntries === true - ? sortMapEntriesByKey - : null + ? sortMapEntriesByKey + : null } clone(): Schema { diff --git a/src/schema/core/float.ts b/src/schema/core/float.ts index a40e40b8..eaac883b 100644 --- a/src/schema/core/float.ts +++ b/src/schema/core/float.ts @@ -11,8 +11,8 @@ export const floatNaN: ScalarTag = { str.slice(-3).toLowerCase() === 'nan' ? NaN : str[0] === '-' - ? Number.NEGATIVE_INFINITY - : Number.POSITIVE_INFINITY, + ? Number.NEGATIVE_INFINITY + : Number.POSITIVE_INFINITY, stringify: stringifyNumber } diff --git a/src/schema/yaml-1.1/float.ts b/src/schema/yaml-1.1/float.ts index eaf7f70a..19e54a5b 100644 --- a/src/schema/yaml-1.1/float.ts +++ b/src/schema/yaml-1.1/float.ts @@ -11,8 +11,8 @@ export const floatNaN: ScalarTag = { str.slice(-3).toLowerCase() === 'nan' ? NaN : str[0] === '-' - ? Number.NEGATIVE_INFINITY - : Number.POSITIVE_INFINITY, + ? Number.NEGATIVE_INFINITY + : Number.POSITIVE_INFINITY, stringify: stringifyNumber } diff --git a/src/stringify/stringify.ts b/src/stringify/stringify.ts index 7a67f915..c05e8858 100644 --- a/src/stringify/stringify.ts +++ b/src/stringify/stringify.ts @@ -165,8 +165,8 @@ export function stringify( typeof tagObj.stringify === 'function' ? tagObj.stringify(node as Scalar, ctx, onComment, onChompKeep) : isScalar(node) - ? stringifyString(node, ctx, onComment, onChompKeep) - : node.toString(ctx, onComment, onChompKeep) + ? stringifyString(node, ctx, onComment, onChompKeep) + : node.toString(ctx, onComment, onChompKeep) if (!props) return str return isScalar(node) || str[0] === '{' || str[0] === '[' ? `${props} ${str}` diff --git a/src/stringify/stringifyComment.ts b/src/stringify/stringifyComment.ts index 75fb5dd7..969118a7 100644 --- a/src/stringify/stringifyComment.ts +++ b/src/stringify/stringifyComment.ts @@ -17,5 +17,5 @@ export const lineComment = (str: string, indent: string, comment: string) => str.endsWith('\n') ? indentComment(comment, indent) : comment.includes('\n') - ? '\n' + indentComment(comment, indent) - : (str.endsWith(' ') ? '' : ' ') + comment + ? '\n' + indentComment(comment, indent) + : (str.endsWith(' ') ? '' : ' ') + comment diff --git a/src/stringify/stringifyString.ts b/src/stringify/stringifyString.ts index 9caab598..401143cd 100644 --- a/src/stringify/stringifyString.ts +++ b/src/stringify/stringifyString.ts @@ -197,10 +197,10 @@ function blockString( blockQuote === 'literal' ? true : blockQuote === 'folded' || type === Scalar.BLOCK_FOLDED - ? false - : type === Scalar.BLOCK_LITERAL - ? true - : !lineLengthOverLimit(value, lineWidth, indent.length) + ? false + : type === Scalar.BLOCK_LITERAL + ? true + : !lineLengthOverLimit(value, lineWidth, indent.length) if (!value) return literal ? '|\n' : '>\n' // determine chomping from whitespace at value end diff --git a/tests/doc/stringify.ts b/tests/doc/stringify.ts index c7b7bf28..5e3f7b68 100644 --- a/tests/doc/stringify.ts +++ b/tests/doc/stringify.ts @@ -874,7 +874,7 @@ describe('lineWidth', () => { ) test('limit to 80 with overlong flow collection', () => { - expect(doc.toString({lineWidth: 80})).toBe(`[ + expect(doc.toString({ lineWidth: 80 })).toBe(`[ 'Sed', 'ut', 'perspiciatis', @@ -894,7 +894,9 @@ describe('lineWidth', () => { }) test('limit > flow collection length', () => { - expect(doc.toString({lineWidth: 162})).toBe("[ 'Sed', 'ut', 'perspiciatis', 'unde', 'omnis', 'iste', 'natus', 'error', 'sit', 'voluptatem', 'accusantium', 'doloremque', 'laudantium,', 'totam' ]\n") + expect(doc.toString({ lineWidth: 162 })).toBe( + "[ 'Sed', 'ut', 'perspiciatis', 'unde', 'omnis', 'iste', 'natus', 'error', 'sit', 'voluptatem', 'accusantium', 'doloremque', 'laudantium,', 'totam' ]\n" + ) }) })