MCPcopy Create free account
hub / github.com/Effect-TS/effect / parseCoreJSDoc

Function parseCoreJSDoc

packages/tools/jsdocs/src/Jsdocs.ts:1047–1090  ·  view source on GitHub ↗
(lines: Array<string>, tags: Array<JSDocTag>)

Source from the content-addressed store, hash-verified

1045}
1046
1047function parseCoreJSDoc(lines: Array<string>, tags: Array<JSDocTag>): Result<ParsedCoreJSDoc, JSDocParseError> {
1048 const diagnostics: Array<JSDocDiagnostic> = []
1049 const firstTagLine = tags[0]?.line ?? lines.length
1050 const content = lines.slice(0, firstTagLine)
1051
1052 if (lines.length === 0) {
1053 diagnostics.push(diagnostic("missing-description", "JSDoc must include a short description"))
1054 }
1055 if (content.at(-1)?.trim() === "" && tags.length > 0) {
1056 // exactly one blank before tags is validated by ensuring the last content line is blank and the previous is not blank
1057 if (content.length < 2 || content[content.length - 2]?.trim() === "") {
1058 diagnostics.push(
1059 diagnostic("invalid-spacing", "JSDoc tags must be separated from description content by exactly one blank line")
1060 )
1061 }
1062 } else if (tags.length > 0 && content.length > 0) {
1063 diagnostics.push(
1064 diagnostic("invalid-spacing", "JSDoc tags must be separated from description content by exactly one blank line")
1065 )
1066 }
1067
1068 if (content[0]?.trim() === "") {
1069 diagnostics.push(diagnostic("leading-blank", "JSDoc must not start with a blank line"))
1070 }
1071 const contentWithoutTagBlank = tags.length > 0 && content.at(-1)?.trim() === "" ? content.slice(0, -1) : content
1072 if (contentWithoutTagBlank.at(-1)?.trim() === "") {
1073 diagnostics.push(diagnostic("trailing-blank", "JSDoc description must not end with a blank line"))
1074 }
1075
1076 const parsedContent = parseDescriptionContent(contentWithoutTagBlank)
1077 diagnostics.push(...parsedContent.diagnostics)
1078
1079 if (diagnostics.length > 0 || parsedContent.value === undefined) {
1080 return { _tag: "Failure", error: { diagnostics: uniqueDiagnostics(diagnostics) } }
1081 }
1082 return {
1083 _tag: "Success",
1084 value: {
1085 description: parsedContent.value.description,
1086 examples: parsedContent.value.examples,
1087 tags
1088 }
1089 }
1090}
1091
1092function uniqueDiagnostics(
1093 diagnostics: ReadonlyArray<JSDocDiagnostic>

Callers 1

parseJSDocBlockFunction · 0.85

Calls 7

diagnosticFunction · 0.85
parseDescriptionContentFunction · 0.85
uniqueDiagnosticsFunction · 0.85
sliceMethod · 0.80
trimMethod · 0.80
pushMethod · 0.65
atMethod · 0.65

Tested by

no test coverage detected