@effected/yaml 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -7
- package/Yaml.js +80 -32
- package/YamlDocument.js +23 -2
- package/YamlFormat.js +162 -21
- package/YamlLint.js +239 -0
- package/YamlLintRule.js +36 -0
- package/YamlNode.js +43 -4
- package/YamlToken.js +139 -0
- package/YamlVisitor.js +52 -16
- package/index.d.ts +446 -12
- package/index.js +4 -1
- package/internal/composer/anchors.js +2 -27
- package/internal/composer/block.js +291 -67
- package/internal/composer/comments.js +217 -0
- package/internal/composer/document.js +141 -14
- package/internal/composer/flow.js +103 -10
- package/internal/composer/scalars.js +48 -11
- package/internal/composer/state.js +16 -2
- package/internal/cst-parser.js +2 -1
- package/internal/diagnostics.js +12 -3
- package/internal/fold.js +22 -10
- package/internal/rules/catalog.js +39 -0
- package/internal/rules/colon-spacing.js +77 -0
- package/internal/rules/comments-spacing.js +68 -0
- package/internal/rules/document-end.js +65 -0
- package/internal/rules/document-start.js +64 -0
- package/internal/rules/empty-lines.js +70 -0
- package/internal/rules/eof-newline.js +33 -0
- package/internal/rules/hyphen-spacing.js +52 -0
- package/internal/rules/indentation.js +103 -0
- package/internal/rules/key-duplicates.js +49 -0
- package/internal/rules/line-length.js +36 -0
- package/internal/rules/parse-validity.js +33 -0
- package/internal/rules/quoted-strings.js +81 -0
- package/internal/rules/trailing-spaces.js +39 -0
- package/internal/rules/truthy.js +84 -0
- package/internal/rules/util.js +92 -0
- package/internal/stringifier.js +342 -54
- package/package.json +3 -2
package/index.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ type YamlStringifyErrorCode = typeof YamlStringifyErrorCode.Type;
|
|
|
54
54
|
*
|
|
55
55
|
* @public
|
|
56
56
|
*/
|
|
57
|
-
declare const YamlModifyErrorCode: Schema.Literals<readonly ["EmptyDocument", "PathNotFound", "InvalidIndex", "NotNavigable"]>;
|
|
57
|
+
declare const YamlModifyErrorCode: Schema.Literals<readonly ["EmptyDocument", "PathNotFound", "InvalidIndex", "NotNavigable", "MultiDocumentStream", "DirectiveCarryingDocument"]>;
|
|
58
58
|
/**
|
|
59
59
|
* The union of all modify-stage error code string literals.
|
|
60
60
|
*
|
|
@@ -67,7 +67,7 @@ type YamlModifyErrorCode = typeof YamlModifyErrorCode.Type;
|
|
|
67
67
|
*
|
|
68
68
|
* @public
|
|
69
69
|
*/
|
|
70
|
-
declare const YamlErrorCode: Schema.Union<readonly [Schema.Literals<readonly ["UnexpectedCharacter", "UnterminatedString", "InvalidEscapeSequence", "InvalidUnicode", "UnterminatedBlockScalar", "UnterminatedFlowCollection", "InvalidDirective", "InvalidTagHandle", "InvalidAnchorName", "UnexpectedByteOrderMark"]>, Schema.Literals<readonly ["InvalidIndentation", "DuplicateKey", "UnexpectedToken", "MissingValue", "MissingKey", "TabIndentation", "InvalidBlockStructure", "MalformedFlowCollection", "NestingDepthExceeded"]>, Schema.Literals<readonly ["UndefinedAlias", "DuplicateAnchor", "CircularAlias", "UnresolvedTag", "InvalidTagValue", "AliasCountExceeded", "InvalidDirective"]>, Schema.Literals<readonly ["CircularReference"]>, Schema.Literals<readonly ["EmptyDocument", "PathNotFound", "InvalidIndex", "NotNavigable"]>]>;
|
|
70
|
+
declare const YamlErrorCode: Schema.Union<readonly [Schema.Literals<readonly ["UnexpectedCharacter", "UnterminatedString", "InvalidEscapeSequence", "InvalidUnicode", "UnterminatedBlockScalar", "UnterminatedFlowCollection", "InvalidDirective", "InvalidTagHandle", "InvalidAnchorName", "UnexpectedByteOrderMark"]>, Schema.Literals<readonly ["InvalidIndentation", "DuplicateKey", "UnexpectedToken", "MissingValue", "MissingKey", "TabIndentation", "InvalidBlockStructure", "MalformedFlowCollection", "NestingDepthExceeded"]>, Schema.Literals<readonly ["UndefinedAlias", "DuplicateAnchor", "CircularAlias", "UnresolvedTag", "InvalidTagValue", "AliasCountExceeded", "InvalidDirective"]>, Schema.Literals<readonly ["CircularReference"]>, Schema.Literals<readonly ["EmptyDocument", "PathNotFound", "InvalidIndex", "NotNavigable", "MultiDocumentStream", "DirectiveCarryingDocument"]>]>;
|
|
71
71
|
/**
|
|
72
72
|
* The union of all YAML error code string literals.
|
|
73
73
|
*
|
|
@@ -75,7 +75,7 @@ declare const YamlErrorCode: Schema.Union<readonly [Schema.Literals<readonly ["U
|
|
|
75
75
|
*/
|
|
76
76
|
type YamlErrorCode = typeof YamlErrorCode.Type;
|
|
77
77
|
declare const YamlDiagnostic_base: Schema.Class<YamlDiagnostic, Schema.Struct<{
|
|
78
|
-
readonly code: Schema.Union<readonly [Schema.Literals<readonly ["UnexpectedCharacter", "UnterminatedString", "InvalidEscapeSequence", "InvalidUnicode", "UnterminatedBlockScalar", "UnterminatedFlowCollection", "InvalidDirective", "InvalidTagHandle", "InvalidAnchorName", "UnexpectedByteOrderMark"]>, Schema.Literals<readonly ["InvalidIndentation", "DuplicateKey", "UnexpectedToken", "MissingValue", "MissingKey", "TabIndentation", "InvalidBlockStructure", "MalformedFlowCollection", "NestingDepthExceeded"]>, Schema.Literals<readonly ["UndefinedAlias", "DuplicateAnchor", "CircularAlias", "UnresolvedTag", "InvalidTagValue", "AliasCountExceeded", "InvalidDirective"]>, Schema.Literals<readonly ["CircularReference"]>, Schema.Literals<readonly ["EmptyDocument", "PathNotFound", "InvalidIndex", "NotNavigable"]>]>;
|
|
78
|
+
readonly code: Schema.Union<readonly [Schema.Literals<readonly ["UnexpectedCharacter", "UnterminatedString", "InvalidEscapeSequence", "InvalidUnicode", "UnterminatedBlockScalar", "UnterminatedFlowCollection", "InvalidDirective", "InvalidTagHandle", "InvalidAnchorName", "UnexpectedByteOrderMark"]>, Schema.Literals<readonly ["InvalidIndentation", "DuplicateKey", "UnexpectedToken", "MissingValue", "MissingKey", "TabIndentation", "InvalidBlockStructure", "MalformedFlowCollection", "NestingDepthExceeded"]>, Schema.Literals<readonly ["UndefinedAlias", "DuplicateAnchor", "CircularAlias", "UnresolvedTag", "InvalidTagValue", "AliasCountExceeded", "InvalidDirective"]>, Schema.Literals<readonly ["CircularReference"]>, Schema.Literals<readonly ["EmptyDocument", "PathNotFound", "InvalidIndex", "NotNavigable", "MultiDocumentStream", "DirectiveCarryingDocument"]>]>;
|
|
79
79
|
readonly message: Schema.String;
|
|
80
80
|
readonly offset: Schema.Number;
|
|
81
81
|
readonly length: Schema.Number;
|
|
@@ -238,7 +238,9 @@ declare const YamlParseError_base: Schema.Class<YamlParseError, Schema.TaggedStr
|
|
|
238
238
|
* Error-recovery parse failure: aggregates every fatal {@link YamlDiagnostic}
|
|
239
239
|
* encountered, so a single failure reports the whole batch. Raised by
|
|
240
240
|
* {@link Yaml.parse}, {@link Yaml.parseAll}, `YamlDocument.parse`/`parseAll`
|
|
241
|
-
* and the decode direction of the schema factories.
|
|
241
|
+
* and the decode direction of the schema factories. The error itself has no
|
|
242
|
+
* `code` field: read the code from the diagnostics —
|
|
243
|
+
* `error.diagnostics[0].code` is the primary failure.
|
|
242
244
|
*
|
|
243
245
|
* @public
|
|
244
246
|
*/
|
|
@@ -253,7 +255,8 @@ declare const YamlStringifyError_base: Schema.Class<YamlStringifyError, Schema.T
|
|
|
253
255
|
* Stringification failure (the circular-reference guard), carrying structured
|
|
254
256
|
* {@link YamlDiagnostic} entries and the offending value. Raised by
|
|
255
257
|
* {@link Yaml.stringify}, `YamlDocument#stringify` and the encode direction of
|
|
256
|
-
* the schema factories.
|
|
258
|
+
* the schema factories. The error itself has no `code` field: read the code
|
|
259
|
+
* from the diagnostics — `error.diagnostics[0].code` is the primary failure.
|
|
257
260
|
*
|
|
258
261
|
* @public
|
|
259
262
|
*/
|
|
@@ -326,6 +329,9 @@ declare class Yaml {
|
|
|
326
329
|
* A "billion laughs" alias-expansion blow-up in any document also fails
|
|
327
330
|
* through {@link YamlParseError} with an `AliasCountExceeded` diagnostic,
|
|
328
331
|
* never as an unhandled defect.
|
|
332
|
+
*
|
|
333
|
+
* Defined in terms of {@link Yaml.parseAllResult} — synchronous callers
|
|
334
|
+
* can use that variant directly.
|
|
329
335
|
*/
|
|
330
336
|
static readonly parseAll: (text: string, options?: YamlParseOptions | undefined) => Effect.Effect<readonly unknown[], YamlParseError, never>;
|
|
331
337
|
/**
|
|
@@ -378,6 +384,46 @@ declare class Yaml {
|
|
|
378
384
|
* @public
|
|
379
385
|
*/
|
|
380
386
|
static parseResult(text: string, options?: YamlParseOptions): Result.Result<unknown, YamlParseError>;
|
|
387
|
+
/**
|
|
388
|
+
* Synchronous multi-document parse, returning a `Result` instead of an
|
|
389
|
+
* `Effect` — the {@link Yaml.parseResult} counterpart to
|
|
390
|
+
* {@link Yaml.parseAll}. Empty input succeeds with `[null]` (the engine
|
|
391
|
+
* reads `""` as one empty document, exactly as {@link Yaml.parse} yields
|
|
392
|
+
* `null` for it); a single-document stream succeeds with a one-element
|
|
393
|
+
* array whose value is exactly what {@link Yaml.parseResult} yields.
|
|
394
|
+
*
|
|
395
|
+
* @remarks
|
|
396
|
+
* This is the package's single multi-document parse path.
|
|
397
|
+
* {@link Yaml.parseAll} is defined in terms of it (`Effect.fromResult`
|
|
398
|
+
* behind the named span), so the two variants cannot diverge. Anchors are
|
|
399
|
+
* document-scoped: each document's aliases resolve against its own anchor
|
|
400
|
+
* map, never a neighbor's.
|
|
401
|
+
*
|
|
402
|
+
* Fails with the aggregate {@link YamlParseError} when **any** document in
|
|
403
|
+
* the stream carries a fatal diagnostic (or a stream-level
|
|
404
|
+
* directive-placement error), which makes it a whole-stream validity
|
|
405
|
+
* check: a `Success` means every document parsed clean. Preserves the
|
|
406
|
+
* package contract — malformed and adversarial input (including a
|
|
407
|
+
* "billion laughs" alias bomb in any document) fails typed, never as a
|
|
408
|
+
* defect; the method never throws.
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* ```ts
|
|
412
|
+
* import { Yaml } from "@effected/yaml";
|
|
413
|
+
* import { Result } from "effect";
|
|
414
|
+
*
|
|
415
|
+
* // Whole-stream validity check: fails if ANY document is invalid.
|
|
416
|
+
* const result = Yaml.parseAllResult("a: 1\n---\nb: 2\n");
|
|
417
|
+
* if (Result.isSuccess(result)) {
|
|
418
|
+
* result.success; // [{ a: 1 }, { b: 2 }]
|
|
419
|
+
* } else {
|
|
420
|
+
* result.failure; // YamlParseError aggregating every fatal diagnostic
|
|
421
|
+
* }
|
|
422
|
+
* ```
|
|
423
|
+
*
|
|
424
|
+
* @public
|
|
425
|
+
*/
|
|
426
|
+
static parseAllResult(text: string, options?: YamlParseOptions): Result.Result<ReadonlyArray<unknown>, YamlParseError>;
|
|
381
427
|
/**
|
|
382
428
|
* Synchronous stringify, returning a `Result` instead of an `Effect`.
|
|
383
429
|
* The pure counterpart to {@link Yaml.stringify} for config-time callers
|
|
@@ -613,8 +659,11 @@ declare const YamlScalar_base: Schema.Class<YamlScalar, Schema.TaggedStruct<"Yam
|
|
|
613
659
|
readonly tag: Schema.optionalKey<Schema.String>;
|
|
614
660
|
readonly style: Schema.Literals<readonly ["plain", "single-quoted", "double-quoted", "block-literal", "block-folded"]>;
|
|
615
661
|
readonly anchor: Schema.optionalKey<Schema.String>;
|
|
662
|
+
readonly commentBefore: Schema.optionalKey<Schema.String>;
|
|
616
663
|
readonly comment: Schema.optionalKey<Schema.String>;
|
|
664
|
+
readonly spaceBefore: Schema.optionalKey<Schema.Boolean>;
|
|
617
665
|
readonly chomp: Schema.optionalKey<Schema.Literals<readonly ["strip", "clip", "keep"]>>;
|
|
666
|
+
readonly blockIndent: Schema.optionalKey<Schema.Number>;
|
|
618
667
|
readonly raw: Schema.optionalKey<Schema.String>;
|
|
619
668
|
readonly sourceMultiline: Schema.optionalKey<Schema.Boolean>;
|
|
620
669
|
readonly offset: Schema.Number;
|
|
@@ -629,9 +678,17 @@ declare const YamlScalar_base: Schema.Class<YamlScalar, Schema.TaggedStruct<"Yam
|
|
|
629
678
|
* - `style` — the scalar presentation style in the source document.
|
|
630
679
|
* - `tag` — optional explicit YAML tag (e.g. `!!str`, `!!int`).
|
|
631
680
|
* - `anchor` — optional anchor name for aliasing.
|
|
632
|
-
* - `
|
|
681
|
+
* - `commentBefore` — own-line comment text directly above the node
|
|
682
|
+
* (multiple consecutive comment lines join with `\n`).
|
|
683
|
+
* - `comment` — trailing comment text on the node's line (strictly trailing;
|
|
684
|
+
* own-line comments live on `commentBefore`).
|
|
685
|
+
* - `spaceBefore` — `true` when a blank line precedes the node (and its
|
|
686
|
+
* `commentBefore` block, when present) in the source.
|
|
633
687
|
* - `chomp` — block-scalar chomping indicator, when the scalar is a block
|
|
634
688
|
* scalar.
|
|
689
|
+
* - `blockIndent` — the EXPLICIT indentation-indicator digit from a block
|
|
690
|
+
* scalar's header (`|2`, `>1+`), when the source spelled one; absent when
|
|
691
|
+
* the header let the reader auto-detect the indent.
|
|
635
692
|
* - `raw` — the raw source text, preserved when it differs from the resolved
|
|
636
693
|
* value in a way stringification needs to know about.
|
|
637
694
|
* - `sourceMultiline` — `true` when the source span covers two or more lines;
|
|
@@ -670,11 +727,18 @@ declare const YamlAlias_base: Schema.Class<YamlAlias, Schema.TaggedStruct<"YamlA
|
|
|
670
727
|
readonly name: Schema.String;
|
|
671
728
|
readonly offset: Schema.Number;
|
|
672
729
|
readonly length: Schema.Number;
|
|
730
|
+
readonly commentBefore: Schema.optionalKey<Schema.String>;
|
|
731
|
+
readonly comment: Schema.optionalKey<Schema.String>;
|
|
732
|
+
readonly spaceBefore: Schema.optionalKey<Schema.Boolean>;
|
|
673
733
|
}>, {}>;
|
|
674
734
|
/**
|
|
675
735
|
* A YAML alias AST node, referencing a previously defined anchor by name
|
|
676
736
|
* (without the leading `*`).
|
|
677
737
|
*
|
|
738
|
+
* Carries the same comment triple as every other node class — see
|
|
739
|
+
* {@link YamlScalar} for the field semantics. An alias is a node like any
|
|
740
|
+
* other and a comment can legally sit above or after one.
|
|
741
|
+
*
|
|
678
742
|
* @public
|
|
679
743
|
*/
|
|
680
744
|
declare class YamlAlias extends YamlAlias_base {
|
|
@@ -740,12 +804,18 @@ type YamlNode = YamlScalar | YamlMap | YamlSeq | YamlAlias;
|
|
|
740
804
|
declare const YamlPair_base: Schema.Class<YamlPair, Schema.TaggedStruct<"YamlPair", {
|
|
741
805
|
readonly key: Schema.suspend<Schema.Codec<YamlAlias | YamlMap | YamlScalar | YamlSeq, YamlAliasEncoded | YamlMapEncoded | YamlScalarEncoded | YamlSeqEncoded, never, never>>;
|
|
742
806
|
readonly value: Schema.NullOr<Schema.suspend<Schema.Codec<YamlAlias | YamlMap | YamlScalar | YamlSeq, YamlAliasEncoded | YamlMapEncoded | YamlScalarEncoded | YamlSeqEncoded, never, never>>>;
|
|
743
|
-
readonly comment: Schema.optionalKey<Schema.String>;
|
|
744
807
|
}>, {}>;
|
|
745
808
|
/**
|
|
746
809
|
* A YAML key-value pair AST node, representing one entry within a mapping.
|
|
747
810
|
* `value` is `null` when absent (e.g. `key:` with no value).
|
|
748
811
|
*
|
|
812
|
+
* A pair carries **no comment fields**. Comments belong to the pair's `key`
|
|
813
|
+
* and `value` nodes, which have one comment slot each: an own-line comment
|
|
814
|
+
* above the entry leads the `key`, and a trailing comment on the entry's line
|
|
815
|
+
* follows the `value`. Two slots rather than one is what lets `a: # kc` keep
|
|
816
|
+
* its comment where the author wrote it instead of relocating it onto the
|
|
817
|
+
* value's line.
|
|
818
|
+
*
|
|
749
819
|
* @public
|
|
750
820
|
*/
|
|
751
821
|
declare class YamlPair extends YamlPair_base {}
|
|
@@ -754,7 +824,9 @@ declare const YamlMap_base: Schema.Class<YamlMap, Schema.TaggedStruct<"YamlMap",
|
|
|
754
824
|
readonly tag: Schema.optionalKey<Schema.String>;
|
|
755
825
|
readonly anchor: Schema.optionalKey<Schema.String>;
|
|
756
826
|
readonly style: Schema.Literals<readonly ["block", "flow"]>;
|
|
827
|
+
readonly commentBefore: Schema.optionalKey<Schema.String>;
|
|
757
828
|
readonly comment: Schema.optionalKey<Schema.String>;
|
|
829
|
+
readonly spaceBefore: Schema.optionalKey<Schema.Boolean>;
|
|
758
830
|
readonly sourceMultiline: Schema.optionalKey<Schema.Boolean>;
|
|
759
831
|
readonly offset: Schema.Number;
|
|
760
832
|
readonly length: Schema.Number;
|
|
@@ -764,6 +836,11 @@ declare const YamlMap_base: Schema.Class<YamlMap, Schema.TaggedStruct<"YamlMap",
|
|
|
764
836
|
* entries.
|
|
765
837
|
*
|
|
766
838
|
* - `style` — the presentation style: `"block"` or `"flow"`.
|
|
839
|
+
* - `commentBefore` — own-line comment text directly above the mapping.
|
|
840
|
+
* - `comment` — trailing comment text: own-line comment lines after the
|
|
841
|
+
* mapping's last entry (still at the mapping's item indent), or a same-line
|
|
842
|
+
* trailing comment for a flow mapping.
|
|
843
|
+
* - `spaceBefore` — `true` when a blank line precedes the mapping.
|
|
767
844
|
* - `sourceMultiline` — `true` when the source span covers two or more lines;
|
|
768
845
|
* used by the canonical stringifier. Absent on synthetic nodes.
|
|
769
846
|
*
|
|
@@ -784,7 +861,9 @@ declare const YamlSeq_base: Schema.Class<YamlSeq, Schema.TaggedStruct<"YamlSeq",
|
|
|
784
861
|
readonly tag: Schema.optionalKey<Schema.String>;
|
|
785
862
|
readonly anchor: Schema.optionalKey<Schema.String>;
|
|
786
863
|
readonly style: Schema.Literals<readonly ["block", "flow"]>;
|
|
864
|
+
readonly commentBefore: Schema.optionalKey<Schema.String>;
|
|
787
865
|
readonly comment: Schema.optionalKey<Schema.String>;
|
|
866
|
+
readonly spaceBefore: Schema.optionalKey<Schema.Boolean>;
|
|
788
867
|
readonly sourceMultiline: Schema.optionalKey<Schema.Boolean>;
|
|
789
868
|
readonly offset: Schema.Number;
|
|
790
869
|
readonly length: Schema.Number;
|
|
@@ -793,6 +872,12 @@ declare const YamlSeq_base: Schema.Class<YamlSeq, Schema.TaggedStruct<"YamlSeq",
|
|
|
793
872
|
* A YAML sequence AST node, representing an ordered list of
|
|
794
873
|
* {@link (YamlNode:type)} values.
|
|
795
874
|
*
|
|
875
|
+
* - `commentBefore` — own-line comment text directly above the sequence.
|
|
876
|
+
* - `comment` — trailing comment text: own-line comment lines after the
|
|
877
|
+
* sequence's last item (still at the sequence's item indent), or a
|
|
878
|
+
* same-line trailing comment for a flow sequence.
|
|
879
|
+
* - `spaceBefore` — `true` when a blank line precedes the sequence.
|
|
880
|
+
*
|
|
796
881
|
* @public
|
|
797
882
|
*/
|
|
798
883
|
declare class YamlSeq extends YamlSeq_base {
|
|
@@ -825,6 +910,7 @@ declare const YamlDocument_base: Schema.Class<YamlDocument, Schema.Struct<{
|
|
|
825
910
|
readonly errors: Schema.$Array<typeof YamlDiagnostic>;
|
|
826
911
|
readonly warnings: Schema.$Array<typeof YamlDiagnostic>;
|
|
827
912
|
readonly directives: Schema.$Array<typeof YamlDirective>;
|
|
913
|
+
readonly commentBefore: Schema.optionalKey<Schema.String>;
|
|
828
914
|
readonly comment: Schema.optionalKey<Schema.String>;
|
|
829
915
|
readonly hasDocumentStart: Schema.optionalKey<Schema.Boolean>;
|
|
830
916
|
readonly hasDocumentEnd: Schema.optionalKey<Schema.Boolean>;
|
|
@@ -833,9 +919,15 @@ declare const YamlDocument_base: Schema.Class<YamlDocument, Schema.Struct<{
|
|
|
833
919
|
/**
|
|
834
920
|
* A parsed YAML document: the root {@link (YamlNode:type)} (or `null` when
|
|
835
921
|
* empty), recovered `errors` and `warnings` as {@link YamlDiagnostic} data,
|
|
836
|
-
* the {@link YamlDirective} list,
|
|
922
|
+
* the {@link YamlDirective} list, the optional document-level comments and the
|
|
837
923
|
* `---`/`...` framing flags (absent flags read as `false`).
|
|
838
924
|
*
|
|
925
|
+
* `commentBefore` is a header block sitting AHEAD of a `---` marker; `comment`
|
|
926
|
+
* is the trailing block after the content or the `...` marker. A header with
|
|
927
|
+
* no marker, or one after the marker, belongs to the content rather than the
|
|
928
|
+
* document — it leads the root node, or the first entry when there is no
|
|
929
|
+
* marker to separate it from the item stream.
|
|
930
|
+
*
|
|
839
931
|
* Construct via `YamlDocument.parse` / `parseAll`; `YamlDocument.make` is for
|
|
840
932
|
* synthetic documents.
|
|
841
933
|
*
|
|
@@ -950,9 +1042,16 @@ declare const YamlModificationError_base: Schema.Class<YamlModificationError, Sc
|
|
|
950
1042
|
}>, import("effect/Cause").YieldableError>;
|
|
951
1043
|
/**
|
|
952
1044
|
* Raised when `YamlFormat.modify` cannot navigate the requested path against
|
|
953
|
-
* the composed AST (a structural mismatch)
|
|
1045
|
+
* the composed AST (a structural mismatch), the source fails to parse, the
|
|
1046
|
+
* source is a multi-document stream (`MultiDocumentStream` — a path names no
|
|
1047
|
+
* particular document of a stream, so modify refuses rather than guessing),
|
|
1048
|
+
* or the document carries `%YAML`/`%TAG` directives
|
|
1049
|
+
* (`DirectiveCarryingDocument` — modify does not re-emit directive lines, and
|
|
1050
|
+
* dropping a `%TAG` would orphan the shorthand tags that depend on it).
|
|
954
1051
|
* Carries structured {@link YamlDiagnostic} entries — never a collapsed
|
|
955
|
-
* `reason` string (the structure-preserving-errors house rule).
|
|
1052
|
+
* `reason` string (the structure-preserving-errors house rule). The error
|
|
1053
|
+
* itself has no `code` field: read the code from the diagnostics —
|
|
1054
|
+
* `error.diagnostics[0].code` is the primary failure.
|
|
956
1055
|
*
|
|
957
1056
|
* @public
|
|
958
1057
|
*/
|
|
@@ -971,6 +1070,24 @@ declare class YamlModificationError extends YamlModificationError_base {
|
|
|
971
1070
|
* `diagnostics: ReadonlyArray<YamlDiagnostic>`, never a collapsed `reason`
|
|
972
1071
|
* string.
|
|
973
1072
|
*
|
|
1073
|
+
* `format`/`formatToString` handle multi-document streams whole — every
|
|
1074
|
+
* document is re-emitted in order with its own framing, never a silently
|
|
1075
|
+
* truncated stream. `modify`/`modifyToString` are **single-document**: a
|
|
1076
|
+
* {@link YamlPath} carries no document index, so which document of a stream
|
|
1077
|
+
* a path names is a rule the format does not define, and a multi-document
|
|
1078
|
+
* stream fails typed with a `MultiDocumentStream` diagnostic rather than
|
|
1079
|
+
* guessing. Parse a stream with {@link Yaml.parseAll} /
|
|
1080
|
+
* `Yaml.parseAllResult`.
|
|
1081
|
+
*
|
|
1082
|
+
* **Directive-carrying input is refused on every path.** The stringifier does
|
|
1083
|
+
* not re-emit `%YAML`/`%TAG` directive lines, and re-emitting a document
|
|
1084
|
+
* without its `%TAG` while keeping the shorthand tags that depend on it
|
|
1085
|
+
* (`!e!foo`) turns a valid file into one no parser can read. So
|
|
1086
|
+
* `format`/`formatToString` leave such input byte-identical (no edits), and
|
|
1087
|
+
* `modify`/`modifyToString` fail typed with a `DirectiveCarryingDocument`
|
|
1088
|
+
* diagnostic. Directive re-emission is unimplemented, not undesired — the
|
|
1089
|
+
* refusal is the floor that stops corruption until it lands.
|
|
1090
|
+
*
|
|
974
1091
|
* @public
|
|
975
1092
|
*/
|
|
976
1093
|
declare class YamlFormat {
|
|
@@ -981,6 +1098,24 @@ declare class YamlFormat {
|
|
|
981
1098
|
* Pure and total: malformed input (a fatal parse error) yields `[]` rather
|
|
982
1099
|
* than corrupting the document.
|
|
983
1100
|
*
|
|
1101
|
+
* **Multi-document streams format whole.** Input containing more than one
|
|
1102
|
+
* document (a `---`-separated stream — a Kubernetes manifest, a pnpm 11
|
|
1103
|
+
* `pnpm-lock.yaml` with a config-dependency preamble) formats every
|
|
1104
|
+
* document in order, re-emitting each document's own framing (`---`,
|
|
1105
|
+
* `...`, comment blocks); no document is ever dropped. Document detection
|
|
1106
|
+
* is CST-level, so a `---` inside a block scalar or quoted string is
|
|
1107
|
+
* content, not a document boundary. Two multi-document shapes yield `[]`
|
|
1108
|
+
* (untouched) because they cannot be re-emitted faithfully: a stream with
|
|
1109
|
+
* a fatal diagnostic in any document (the same posture as single-document
|
|
1110
|
+
* input) and a stream carrying `%YAML`/`%TAG` directives.
|
|
1111
|
+
*
|
|
1112
|
+
* **Directive-carrying documents yield `[]` on the single-document path
|
|
1113
|
+
* too.** Directive lines are not re-emitted, and dropping a `%TAG` while
|
|
1114
|
+
* keeping the shorthand tags that depend on it would turn a valid document
|
|
1115
|
+
* into an unparseable one — so a document carrying `%YAML`/`%TAG`
|
|
1116
|
+
* directives is left untouched. Detection is directive-token-level: a
|
|
1117
|
+
* literal `%TAG` inside a scalar is content and formats normally.
|
|
1118
|
+
*
|
|
984
1119
|
* @remarks
|
|
985
1120
|
* The positional `range` argument takes precedence over
|
|
986
1121
|
* `options?.range` when both are given; either accepts a plain
|
|
@@ -999,6 +1134,13 @@ declare class YamlFormat {
|
|
|
999
1134
|
/**
|
|
1000
1135
|
* Format `text` and apply the resulting edits in one step
|
|
1001
1136
|
* (`YamlEdit.applyAll ∘ format`). Pure and total.
|
|
1137
|
+
*
|
|
1138
|
+
* Inherits the {@link YamlFormat.format} contract: a multi-document stream
|
|
1139
|
+
* is formatted whole — every document re-emitted in order — and input
|
|
1140
|
+
* that cannot be formatted faithfully (a fatal parse error, or any
|
|
1141
|
+
* document — single or in a stream — carrying `%YAML`/`%TAG` directives)
|
|
1142
|
+
* is returned byte-identical — never a truncated first document, never a
|
|
1143
|
+
* document re-emitted without the directive its tags depend on.
|
|
1002
1144
|
*/
|
|
1003
1145
|
static formatToString(text: string, range?: YamlRangeLike, options?: YamlFormattingOptions): string;
|
|
1004
1146
|
/**
|
|
@@ -1010,6 +1152,23 @@ declare class YamlFormat {
|
|
|
1010
1152
|
* {@link YamlModificationError} on a fatal parse error or a structural
|
|
1011
1153
|
* navigation mismatch.
|
|
1012
1154
|
*
|
|
1155
|
+
* **Single-document contract.** A `path` carries no document index, so on
|
|
1156
|
+
* a multi-document stream there is no rule for which document it names —
|
|
1157
|
+
* `modify` fails with {@link YamlModificationError} carrying a
|
|
1158
|
+
* `MultiDocumentStream` diagnostic rather than guessing document 1 (and
|
|
1159
|
+
* unlike {@link YamlFormat.format}, which formats a stream whole because
|
|
1160
|
+
* formatting needs no target). Detection is CST-level: a `---` inside a
|
|
1161
|
+
* block scalar or quoted string is content, not a document boundary.
|
|
1162
|
+
*
|
|
1163
|
+
* **Directive-carrying documents are refused.** A document carrying
|
|
1164
|
+
* `%YAML`/`%TAG` directives fails with {@link YamlModificationError}
|
|
1165
|
+
* carrying a `DirectiveCarryingDocument` diagnostic: modify re-emits the
|
|
1166
|
+
* whole document and does not re-emit directive lines, so applying it
|
|
1167
|
+
* would drop the `%TAG` while keeping the shorthand tags that depend on
|
|
1168
|
+
* it — unparseable output. A typed refusal beats silent corruption;
|
|
1169
|
+
* directive re-emission is unimplemented, not undesired. A literal
|
|
1170
|
+
* `%TAG` inside a scalar is content and does not trigger the refusal.
|
|
1171
|
+
*
|
|
1013
1172
|
* @remarks
|
|
1014
1173
|
* `options` is a bare {@link YamlStringifyOptions} — it controls only the
|
|
1015
1174
|
* internal re-stringify step, not a range (there is no range to restrict
|
|
@@ -1018,11 +1177,278 @@ declare class YamlFormat {
|
|
|
1018
1177
|
static readonly modify: (text: string, path: YamlPath, value: unknown, options?: YamlStringifyOptions | undefined) => Effect.Effect<readonly YamlEdit[], YamlModificationError, never>;
|
|
1019
1178
|
/**
|
|
1020
1179
|
* Modify `text` and apply the resulting edits in one step
|
|
1021
|
-
* (`YamlEdit.applyAll ∘ modify`).
|
|
1180
|
+
* (`YamlEdit.applyAll ∘ modify`). Inherits the {@link YamlFormat.modify}
|
|
1181
|
+
* error channel, including the single-document contract's
|
|
1182
|
+
* `MultiDocumentStream` refusal and the `DirectiveCarryingDocument`
|
|
1183
|
+
* refusal of `%YAML`/`%TAG`-carrying documents.
|
|
1022
1184
|
*/
|
|
1023
1185
|
static readonly modifyToString: (text: string, path: YamlPath, value: unknown, options?: YamlStringifyOptions | undefined) => Effect.Effect<string, YamlModificationError, never>;
|
|
1024
1186
|
}
|
|
1025
1187
|
//#endregion
|
|
1188
|
+
//#region src/YamlToken.d.ts
|
|
1189
|
+
/**
|
|
1190
|
+
* The 22 lexical token kinds produced by the YAML tokenizer.
|
|
1191
|
+
*
|
|
1192
|
+
* @public
|
|
1193
|
+
*/
|
|
1194
|
+
declare const YamlTokenKind: Schema.Literals<readonly ["document-start", "document-end", "directive", "tag", "anchor", "alias", "scalar", "block-map-start", "block-map-key", "block-map-value", "block-seq-start", "block-seq-entry", "flow-map-start", "flow-map-end", "flow-seq-start", "flow-seq-end", "flow-separator", "newline", "whitespace", "comment", "byte-order-mark", "error"]>;
|
|
1195
|
+
/**
|
|
1196
|
+
* The union of all lexical token kind string literals.
|
|
1197
|
+
*
|
|
1198
|
+
* @public
|
|
1199
|
+
*/
|
|
1200
|
+
type YamlTokenKind = typeof YamlTokenKind.Type;
|
|
1201
|
+
declare const YamlToken_base: Schema.Class<YamlToken, Schema.Struct<{
|
|
1202
|
+
readonly kind: Schema.Literals<readonly ["document-start", "document-end", "directive", "tag", "anchor", "alias", "scalar", "block-map-start", "block-map-key", "block-map-value", "block-seq-start", "block-seq-entry", "flow-map-start", "flow-map-end", "flow-seq-start", "flow-seq-end", "flow-separator", "newline", "whitespace", "comment", "byte-order-mark", "error"]>;
|
|
1203
|
+
readonly text: Schema.String;
|
|
1204
|
+
readonly offset: Schema.Number;
|
|
1205
|
+
readonly length: Schema.Number;
|
|
1206
|
+
readonly line: Schema.Number;
|
|
1207
|
+
readonly character: Schema.Number;
|
|
1208
|
+
}>, {}>;
|
|
1209
|
+
/**
|
|
1210
|
+
* A single positioned YAML lexical token.
|
|
1211
|
+
*
|
|
1212
|
+
* - `kind` — the {@link (YamlTokenKind:type)}.
|
|
1213
|
+
* - `text` — the raw source slice the token covers; the position-fidelity
|
|
1214
|
+
* invariant is `source.slice(offset, offset + length) === text`.
|
|
1215
|
+
* - `offset` / `length` — the token's span in UTF-16 code units.
|
|
1216
|
+
* - `line` / `character` — the zero-based position of the token's start,
|
|
1217
|
+
* matching the `YamlDiagnostic` position vocabulary.
|
|
1218
|
+
*
|
|
1219
|
+
* @public
|
|
1220
|
+
*/
|
|
1221
|
+
declare class YamlToken extends YamlToken_base {}
|
|
1222
|
+
/**
|
|
1223
|
+
* Tokenizer statics. Not instantiable.
|
|
1224
|
+
*
|
|
1225
|
+
* @public
|
|
1226
|
+
*/
|
|
1227
|
+
declare class YamlTokens {
|
|
1228
|
+
private constructor();
|
|
1229
|
+
/**
|
|
1230
|
+
* Tokenize YAML text into the full positioned token array — the sync
|
|
1231
|
+
* `Result` primitive (tokenizing is a pure batch transform; the
|
|
1232
|
+
* {@link YamlTokens.stream} form is derived from this one, per the kit's
|
|
1233
|
+
* sync-primitive policy).
|
|
1234
|
+
*
|
|
1235
|
+
* @remarks
|
|
1236
|
+
* The failure channel is **reserved** (for future input-hardening guards)
|
|
1237
|
+
* and never fires today: the lexer is total, and lexical errors surface as
|
|
1238
|
+
* `"error"`-kind tokens **in the success array** so that linting can run
|
|
1239
|
+
* on malformed input — the `parse-validity` lint rule exists precisely for
|
|
1240
|
+
* documents that do not parse. Do not "fix" this method to fail on
|
|
1241
|
+
* `"error"` tokens; that would make malformed documents unlintable.
|
|
1242
|
+
*
|
|
1243
|
+
* @example
|
|
1244
|
+
* ```ts
|
|
1245
|
+
* import { YamlTokens } from "@effected/yaml";
|
|
1246
|
+
* import { Result } from "effect";
|
|
1247
|
+
*
|
|
1248
|
+
* const result = YamlTokens.tokenize("a: 1\n");
|
|
1249
|
+
* if (Result.isSuccess(result)) {
|
|
1250
|
+
* result.success.map((t) => t.kind); // ["scalar", "block-map-start", ...]
|
|
1251
|
+
* }
|
|
1252
|
+
* ```
|
|
1253
|
+
*/
|
|
1254
|
+
static tokenize(text: string): Result.Result<ReadonlyArray<YamlToken>, YamlParseError>;
|
|
1255
|
+
/**
|
|
1256
|
+
* Tokenize YAML text as a lazy `Stream` of tokens — the derived form of
|
|
1257
|
+
* {@link YamlTokens.tokenize} for genuinely incremental (SAX-style)
|
|
1258
|
+
* consumers, parallel to `YamlVisitor.visit`.
|
|
1259
|
+
*
|
|
1260
|
+
* @remarks
|
|
1261
|
+
* Derived from the sync primitive, so it shares its contract: lexical
|
|
1262
|
+
* errors arrive as `"error"`-kind tokens in the stream, never as a stream
|
|
1263
|
+
* failure. (The primitive's reserved failure channel would surface as a
|
|
1264
|
+
* defect here; it never fires today.)
|
|
1265
|
+
*/
|
|
1266
|
+
static stream(text: string): Stream.Stream<YamlToken>;
|
|
1267
|
+
}
|
|
1268
|
+
//#endregion
|
|
1269
|
+
//#region src/YamlLintRule.d.ts
|
|
1270
|
+
/**
|
|
1271
|
+
* Lint diagnostic severities. `"off"` is a config-level disable only and
|
|
1272
|
+
* never reaches a diagnostic — a rule set to `"off"` is not run.
|
|
1273
|
+
*
|
|
1274
|
+
* @public
|
|
1275
|
+
*/
|
|
1276
|
+
declare const YamlLintSeverity: Schema.Literals<readonly ["error", "warning"]>;
|
|
1277
|
+
/**
|
|
1278
|
+
* The union of lint severity string literals.
|
|
1279
|
+
*
|
|
1280
|
+
* @public
|
|
1281
|
+
*/
|
|
1282
|
+
type YamlLintSeverity = typeof YamlLintSeverity.Type;
|
|
1283
|
+
declare const YamlLintDiagnostic_base: Schema.Class<YamlLintDiagnostic, Schema.Struct<{
|
|
1284
|
+
readonly rule: Schema.String;
|
|
1285
|
+
readonly severity: Schema.Literals<readonly ["error", "warning"]>;
|
|
1286
|
+
readonly message: Schema.String;
|
|
1287
|
+
readonly offset: Schema.Number;
|
|
1288
|
+
readonly length: Schema.Number;
|
|
1289
|
+
readonly line: Schema.Number;
|
|
1290
|
+
readonly character: Schema.Number;
|
|
1291
|
+
readonly fix: Schema.optionalKey<typeof YamlEdit>;
|
|
1292
|
+
}>, {}>;
|
|
1293
|
+
/**
|
|
1294
|
+
* A single lint finding: the reporting rule, its severity, a positioned span
|
|
1295
|
+
* and optionally a surgical fix.
|
|
1296
|
+
*
|
|
1297
|
+
* Deliberately separate from the engine's `YamlDiagnostic`: that type is the
|
|
1298
|
+
* lexer/parser/composer/stringifier error-code union and the single source
|
|
1299
|
+
* of truth for engine fatality — it carries no severity and no fix, and
|
|
1300
|
+
* lint-layer concerns must not pollute it. The `parse-validity` rule bridges
|
|
1301
|
+
* the two by mapping engine diagnostics into this shape.
|
|
1302
|
+
*
|
|
1303
|
+
* @public
|
|
1304
|
+
*/
|
|
1305
|
+
declare class YamlLintDiagnostic extends YamlLintDiagnostic_base {}
|
|
1306
|
+
/**
|
|
1307
|
+
* One source line of the linted document: its text (without the line
|
|
1308
|
+
* terminator — the `\n`, and for CRLF input the `\r\n` pair), the offset of
|
|
1309
|
+
* its first character, and its zero-based line number.
|
|
1310
|
+
*
|
|
1311
|
+
* @public
|
|
1312
|
+
*/
|
|
1313
|
+
interface LintLine {
|
|
1314
|
+
readonly text: string;
|
|
1315
|
+
readonly offset: number;
|
|
1316
|
+
readonly number: number;
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* The context handed to every rule. The engine tokenizes ONCE and every rule
|
|
1320
|
+
* shares the one materialized `tokens` array — linting is inherently
|
|
1321
|
+
* multi-pass and random-access (layout rules need lookahead and lookbehind),
|
|
1322
|
+
* so the context is eager by nature; the streaming token form exists for
|
|
1323
|
+
* other consumers.
|
|
1324
|
+
*
|
|
1325
|
+
* `text`, `lines` and `tokens` cover the FULL source; `document` is the
|
|
1326
|
+
* FIRST document of the stream (matching `Yaml.parse` — split the stream
|
|
1327
|
+
* `Yaml.parseAll`-style to lint every document). It is always present,
|
|
1328
|
+
* including for input that does not parse: it is built from the engine's
|
|
1329
|
+
* recovered compose, and its `errors`/`warnings` carry what went wrong (the
|
|
1330
|
+
* `parse-validity` rule reports them).
|
|
1331
|
+
*
|
|
1332
|
+
* @public
|
|
1333
|
+
*/
|
|
1334
|
+
interface LintContext {
|
|
1335
|
+
readonly text: string;
|
|
1336
|
+
readonly lines: ReadonlyArray<LintLine>;
|
|
1337
|
+
readonly tokens: ReadonlyArray<YamlToken>;
|
|
1338
|
+
readonly document: YamlDocument;
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* The public rule interface — built-ins and custom rules are the same
|
|
1342
|
+
* shape, and config references either by `id`; there is no privileged
|
|
1343
|
+
* built-in mechanism a custom rule cannot reach.
|
|
1344
|
+
*
|
|
1345
|
+
* `options` is the validated per-rule options object from the config entry
|
|
1346
|
+
* (or `undefined` when the entry was a bare severity literal); built-in
|
|
1347
|
+
* rules receive options already validated against their exported options
|
|
1348
|
+
* schema, custom rules validate their own.
|
|
1349
|
+
*
|
|
1350
|
+
* @public
|
|
1351
|
+
*/
|
|
1352
|
+
interface YamlRule {
|
|
1353
|
+
readonly id: string;
|
|
1354
|
+
readonly check: (ctx: LintContext, options: unknown) => Iterable<YamlLintDiagnostic>;
|
|
1355
|
+
}
|
|
1356
|
+
//#endregion
|
|
1357
|
+
//#region src/YamlLint.d.ts
|
|
1358
|
+
/**
|
|
1359
|
+
* One entry of the config `rules` map: a bare severity literal (the common
|
|
1360
|
+
* case), `"off"` to disable, or a typed per-rule options object (the tuning
|
|
1361
|
+
* case; may carry its own `severity`).
|
|
1362
|
+
*
|
|
1363
|
+
* @public
|
|
1364
|
+
*/
|
|
1365
|
+
declare const YamlLintRuleSetting: Schema.Union<readonly [Schema.Literals<readonly ["error", "warning", "off"]>, Schema.$Record<Schema.String, Schema.Unknown>]>;
|
|
1366
|
+
/**
|
|
1367
|
+
* The union type of one `rules`-map entry.
|
|
1368
|
+
*
|
|
1369
|
+
* @public
|
|
1370
|
+
*/
|
|
1371
|
+
type YamlLintRuleSetting = typeof YamlLintRuleSetting.Type;
|
|
1372
|
+
declare const YamlLintConfig_base: Schema.Class<YamlLintConfig, Schema.Struct<{
|
|
1373
|
+
readonly rules: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Literals<readonly ["error", "warning", "off"]>, Schema.$Record<Schema.String, Schema.Unknown>]>>;
|
|
1374
|
+
}>, {}>;
|
|
1375
|
+
/**
|
|
1376
|
+
* The lint configuration: a `rules` map keying rule ids (built-in or custom)
|
|
1377
|
+
* to a severity literal or a typed per-rule options object.
|
|
1378
|
+
*
|
|
1379
|
+
* Validation is rule-aware for the built-in catalog — a mistyped option on a
|
|
1380
|
+
* built-in rule fails schema validation with a typed error naming the rule,
|
|
1381
|
+
* and any attempt to demote or disable the always-on `parse-validity` rule
|
|
1382
|
+
* is rejected. Custom rule ids are accepted with a bare severity or an
|
|
1383
|
+
* opaque options object the custom rule validates itself.
|
|
1384
|
+
*
|
|
1385
|
+
* Presets ship as the statics {@link YamlLintConfig.default} and
|
|
1386
|
+
* {@link YamlLintConfig.relaxed} — composing one is object spread over a
|
|
1387
|
+
* static, not an `extends` string resolution step (this package owns no
|
|
1388
|
+
* config-file loader).
|
|
1389
|
+
*
|
|
1390
|
+
* @public
|
|
1391
|
+
*/
|
|
1392
|
+
declare class YamlLintConfig extends YamlLintConfig_base {
|
|
1393
|
+
/**
|
|
1394
|
+
* The default preset. Rule entries accrete as built-ins land; the
|
|
1395
|
+
* `quoted-strings` rule defaults to DOUBLE quotes here (the one taste
|
|
1396
|
+
* call the design pins).
|
|
1397
|
+
*/
|
|
1398
|
+
static readonly default: YamlLintConfig;
|
|
1399
|
+
/** The relaxed preset: style rules demoted to warnings. */
|
|
1400
|
+
static readonly relaxed: YamlLintConfig;
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Linting statics. Not instantiable.
|
|
1404
|
+
*
|
|
1405
|
+
* @remarks
|
|
1406
|
+
* Pure and synchronous throughout — the lint engine is the pure half only:
|
|
1407
|
+
* strings in, diagnostics or a fixed string out. File discovery, config-file
|
|
1408
|
+
* loading and autofix-to-disk belong to a consumer's tier, not here.
|
|
1409
|
+
*
|
|
1410
|
+
* @public
|
|
1411
|
+
*/
|
|
1412
|
+
declare class YamlLint {
|
|
1413
|
+
private constructor();
|
|
1414
|
+
/**
|
|
1415
|
+
* The built-in rule catalog. Custom usage is array concatenation:
|
|
1416
|
+
* `YamlLint.run(text, [...YamlLint.builtins, myRule], config)`.
|
|
1417
|
+
*/
|
|
1418
|
+
static readonly builtins: ReadonlyArray<YamlRule>;
|
|
1419
|
+
/**
|
|
1420
|
+
* Run `rules` over `text` under `config`, returning every finding sorted
|
|
1421
|
+
* by position.
|
|
1422
|
+
*
|
|
1423
|
+
* Document-driven rules see the FIRST document of the stream (matching
|
|
1424
|
+
* `Yaml.parse`; split the stream `Yaml.parseAll`-style to lint every
|
|
1425
|
+
* document), while token- and line-driven rules cover the full source —
|
|
1426
|
+
* see {@link LintContext}.
|
|
1427
|
+
*
|
|
1428
|
+
* A rule runs when its config entry is a severity or an options object;
|
|
1429
|
+
* `"off"` and absent entries skip it — except `parse-validity`, which is
|
|
1430
|
+
* always-on. The resolved severity (explicit-in-options, else the bare
|
|
1431
|
+
* literal, else `"error"`) overrides what the rule emitted, again except
|
|
1432
|
+
* for `parse-validity`, whose bridged engine diagnostics keep the
|
|
1433
|
+
* engine's own grading.
|
|
1434
|
+
*/
|
|
1435
|
+
static run(text: string, rules: ReadonlyArray<YamlRule>, config: YamlLintConfig): ReadonlyArray<YamlLintDiagnostic>;
|
|
1436
|
+
/**
|
|
1437
|
+
* Run `rules` and apply every non-overlapping surgical fix, returning the
|
|
1438
|
+
* fixed text. Fails with {@link YamlParseError} when the FIRST document
|
|
1439
|
+
* of the stream has a fatal parse error — a document the engine cannot
|
|
1440
|
+
* compose is not safely fixable. The gate matches `Yaml.parse`'s scope:
|
|
1441
|
+
* later documents of a multi-document stream are not composed (split the
|
|
1442
|
+
* stream `Yaml.parseAll`-style to lint every document), though token- and
|
|
1443
|
+
* line-driven fixes still cover the full source. Fixes route exclusively through `YamlEdit.applyAll` (never a
|
|
1444
|
+
* reformat), so applying them is comment-safe by construction; when two
|
|
1445
|
+
* fixes overlap — or start at the same offset — the earlier one in
|
|
1446
|
+
* {@link YamlLint.run} order (position, then rule id) wins and the later
|
|
1447
|
+
* is dropped (its diagnostic remains reported by {@link YamlLint.run}).
|
|
1448
|
+
*/
|
|
1449
|
+
static fix(text: string, rules: ReadonlyArray<YamlRule>, config: YamlLintConfig): Result.Result<string, YamlParseError>;
|
|
1450
|
+
}
|
|
1451
|
+
//#endregion
|
|
1026
1452
|
//#region src/YamlVisitor.d.ts
|
|
1027
1453
|
/**
|
|
1028
1454
|
* The discriminated union of YAML AST visitor events. Every variant carries
|
|
@@ -1091,6 +1517,8 @@ type YamlVisitorEvent = Data.TaggedEnum<{
|
|
|
1091
1517
|
readonly path: YamlPath;
|
|
1092
1518
|
readonly depth: number;
|
|
1093
1519
|
readonly text: string;
|
|
1520
|
+
/** Where the comment sits relative to its construct: own-line above (`"leading"`) or same-line after (`"trailing"`). */
|
|
1521
|
+
readonly placement: "leading" | "trailing";
|
|
1094
1522
|
};
|
|
1095
1523
|
Directive: {
|
|
1096
1524
|
readonly path: YamlPath;
|
|
@@ -1124,6 +1552,7 @@ declare const YamlVisitorEvent: {
|
|
|
1124
1552
|
readonly path: YamlPath;
|
|
1125
1553
|
readonly depth: number;
|
|
1126
1554
|
readonly text: string;
|
|
1555
|
+
readonly placement: "leading" | "trailing";
|
|
1127
1556
|
}, {
|
|
1128
1557
|
readonly _tag: Tag;
|
|
1129
1558
|
}> | Extract<{
|
|
@@ -1219,6 +1648,7 @@ declare const YamlVisitorEvent: {
|
|
|
1219
1648
|
readonly path: YamlPath;
|
|
1220
1649
|
readonly depth: number;
|
|
1221
1650
|
readonly text: string;
|
|
1651
|
+
readonly placement: "leading" | "trailing";
|
|
1222
1652
|
}) => any;
|
|
1223
1653
|
readonly Directive: (args: {
|
|
1224
1654
|
readonly _tag: "Directive";
|
|
@@ -1299,6 +1729,7 @@ declare const YamlVisitorEvent: {
|
|
|
1299
1729
|
readonly path: YamlPath;
|
|
1300
1730
|
readonly depth: number;
|
|
1301
1731
|
readonly text: string;
|
|
1732
|
+
readonly placement: "leading" | "trailing";
|
|
1302
1733
|
} | {
|
|
1303
1734
|
readonly _tag: "Directive";
|
|
1304
1735
|
readonly path: YamlPath;
|
|
@@ -1371,6 +1802,7 @@ declare const YamlVisitorEvent: {
|
|
|
1371
1802
|
readonly path: YamlPath;
|
|
1372
1803
|
readonly depth: number;
|
|
1373
1804
|
readonly text: string;
|
|
1805
|
+
readonly placement: "leading" | "trailing";
|
|
1374
1806
|
}) => any;
|
|
1375
1807
|
readonly Directive: (args: {
|
|
1376
1808
|
readonly _tag: "Directive";
|
|
@@ -1451,6 +1883,7 @@ declare const YamlVisitorEvent: {
|
|
|
1451
1883
|
readonly path: YamlPath;
|
|
1452
1884
|
readonly depth: number;
|
|
1453
1885
|
readonly text: string;
|
|
1886
|
+
readonly placement: "leading" | "trailing";
|
|
1454
1887
|
} | {
|
|
1455
1888
|
readonly _tag: "Directive";
|
|
1456
1889
|
readonly path: YamlPath;
|
|
@@ -1523,6 +1956,7 @@ declare const YamlVisitorEvent: {
|
|
|
1523
1956
|
readonly path: YamlPath;
|
|
1524
1957
|
readonly depth: number;
|
|
1525
1958
|
readonly text: string;
|
|
1959
|
+
readonly placement: "leading" | "trailing";
|
|
1526
1960
|
}, "_tag">;
|
|
1527
1961
|
readonly Directive: Data.TaggedEnum.ConstructorFrom<{
|
|
1528
1962
|
readonly _tag: "Directive";
|
|
@@ -1617,5 +2051,5 @@ declare class YamlVisitor {
|
|
|
1617
2051
|
static visit(text: string, options?: YamlParseOptions): Stream.Stream<YamlVisitorEvent>;
|
|
1618
2052
|
}
|
|
1619
2053
|
//#endregion
|
|
1620
|
-
export { CollectionStyle, QuoteStyle, ScalarChomp, ScalarStyle, Yaml, YamlAlias, type YamlAliasEncoded, type YamlBoundCodec, YamlComposerErrorCode, YamlDiagnostic, YamlDirective, YamlDocument, YamlEdit, YamlErrorCode, YamlFormat, YamlFormattingOptions, YamlLexErrorCode, YamlMap, type YamlMapEncoded, YamlModificationError, YamlModifyErrorCode, YamlNode, YamlPair, YamlParseError, YamlParseErrorCode, YamlParseOptions, type YamlPath, YamlRange, type YamlRangeLike, YamlScalar, type YamlScalarEncoded, type YamlSegment, YamlSeq, type YamlSeqEncoded, YamlStringifyError, YamlStringifyErrorCode, YamlStringifyOptions, YamlVisitor, YamlVisitorEvent };
|
|
2054
|
+
export { CollectionStyle, type LintContext, type LintLine, QuoteStyle, ScalarChomp, ScalarStyle, Yaml, YamlAlias, type YamlAliasEncoded, type YamlBoundCodec, YamlComposerErrorCode, YamlDiagnostic, YamlDirective, YamlDocument, YamlEdit, YamlErrorCode, YamlFormat, YamlFormattingOptions, YamlLexErrorCode, YamlLint, YamlLintConfig, YamlLintDiagnostic, YamlLintRuleSetting, YamlLintSeverity, YamlMap, type YamlMapEncoded, YamlModificationError, YamlModifyErrorCode, YamlNode, YamlPair, YamlParseError, YamlParseErrorCode, YamlParseOptions, type YamlPath, YamlRange, type YamlRangeLike, type YamlRule, YamlScalar, type YamlScalarEncoded, type YamlSegment, YamlSeq, type YamlSeqEncoded, YamlStringifyError, YamlStringifyErrorCode, YamlStringifyOptions, YamlToken, YamlTokenKind, YamlTokens, YamlVisitor, YamlVisitorEvent };
|
|
1621
2055
|
//# sourceMappingURL=index.d.ts.map
|