Skip to content

Commit

Permalink
style: Apply updated Prettier rules
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Feb 24, 2024
1 parent cdc032e commit e4f963a
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 50 deletions.
20 changes: 10 additions & 10 deletions docs/06_custom_tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions src/compose/compose-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/compose/compose-scalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 9 additions & 2 deletions src/compose/resolve-flow-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/doc/createNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
16 changes: 8 additions & 8 deletions src/nodes/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export type NodeType<T> = T extends
| undefined
? Scalar<T>
: T extends Date
? Scalar<string | Date>
: T extends Array<any>
? YAMLSeq<NodeType<T[number]>>
: T extends { [key: string]: any }
? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>>
: T extends { [key: number]: any } // Merge with previous once supported in all TS versions
? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>>
: Node
? Scalar<string | Date>
: T extends Array<any>
? YAMLSeq<NodeType<T[number]>>
: T extends { [key: string]: any }
? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>>
: T extends { [key: number]: any } // Merge with previous once supported in all TS versions
? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>>
: Node

export type ParsedNode =
| Alias.Parsed
Expand Down
8 changes: 4 additions & 4 deletions src/schema/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 : {}
Expand All @@ -53,8 +53,8 @@ export class Schema {
typeof sortMapEntries === 'function'
? sortMapEntries
: sortMapEntries === true
? sortMapEntriesByKey
: null
? sortMapEntriesByKey
: null
}

clone(): Schema {
Expand Down
4 changes: 2 additions & 2 deletions src/schema/core/float.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions src/schema/yaml-1.1/float.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions src/stringify/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
4 changes: 2 additions & 2 deletions src/stringify/stringifyComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/stringify/stringifyString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/doc/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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"
)
})
})

Expand Down

0 comments on commit e4f963a

Please sign in to comment.