@effected/yaml 0.18.0 → 0.19.1
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 +4 -4
- package/Yaml.js +52 -12
- package/YamlDiagnostic.js +8 -2
- package/YamlDocument.js +31 -0
- package/YamlEdit.js +8 -3
- package/YamlFormat.js +55 -13
- package/YamlLint.js +0 -0
- package/YamlLintRule.js +2 -2
- package/YamlToken.js +9 -5
- package/YamlVisitor.js +22 -1
- package/index.d.ts +224 -40
- package/internal/composer/block.js +2 -3
- package/internal/composer/comments.js +1 -1
- package/internal/composer/document.js +5 -7
- package/internal/composer/scalars.js +1 -1
- package/internal/composer/state.js +1 -1
- package/internal/diagnostics.js +2 -3
- package/internal/rules/quoted-strings.js +1 -1
- package/internal/stringifier.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
Zero-dependency YAML 1.2 parsing, editing, formatting and linting expressed as Effect schemas and pure functions. Parse a single document or a multi-document stream into plain values or an offset-preserving AST, resolve anchors and aliases, read and preserve per-node comments, strip comments, compute byte-minimal edits, format, modify by path, walk a document as a `Stream` of AST events or positioned tokens, lint it against a rule catalog with surgical autofix — inferring the lint config from files you already have — and decode straight into a validated domain schema.
|
|
9
9
|
|
|
10
|
-
> **Pre
|
|
11
|
-
>
|
|
12
|
-
> `1.0.0`
|
|
13
|
-
>
|
|
10
|
+
> **Pre-`1.0.0`.** This package is part of the `@effected/*` kit, built on stable
|
|
11
|
+
> Effect v4 (`effect` `^4.0.0`) and still in `0.x` development. Stable Effect
|
|
12
|
+
> makes a kit `1.0.0` possible, not automatic. To keep your `effect` and
|
|
13
|
+
> `@effect/*` versions on the line the kit is built and tested against, install
|
|
14
14
|
> [`@effected/pnpm-plugin-effect`](https://www.npmjs.com/package/@effected/pnpm-plugin-effect).
|
|
15
15
|
>
|
|
16
16
|
> **Stability: unstable.** This package's API surface is not yet considered
|
package/Yaml.js
CHANGED
|
@@ -40,8 +40,7 @@ var YamlParseOptions = class extends Schema.Class("YamlParseOptions")({
|
|
|
40
40
|
* `false`.
|
|
41
41
|
*
|
|
42
42
|
* `lineWidth` controls column-based scalar folding. The default `0` (and any
|
|
43
|
-
* value `<= 0`) never wraps
|
|
44
|
-
* no-fold behavior; a positive value folds long plain, double-quoted and
|
|
43
|
+
* value `<= 0`) never wraps; a positive value folds long plain, double-quoted and
|
|
45
44
|
* block-folded (`>`) scalars at approximately that column, inserting only
|
|
46
45
|
* semantically transparent line breaks. Block-literal (`|`) content is never
|
|
47
46
|
* folded — literal blocks preserve their bytes by definition. Folding is a
|
|
@@ -49,15 +48,14 @@ var YamlParseOptions = class extends Schema.Class("YamlParseOptions")({
|
|
|
49
48
|
* helpers accept these options but do not fold (see `lineWidth`).
|
|
50
49
|
*
|
|
51
50
|
* `indentSequences` controls the presentation of block sequences nested under
|
|
52
|
-
* a mapping key: `false` (the default) emits them at the key's column
|
|
53
|
-
*
|
|
51
|
+
* a mapping key: `false` (the default) emits them at the key's column, while
|
|
52
|
+
* `true` indents them one level,
|
|
54
53
|
* matching the `yaml` npm package's default output. Top-level sequences stay
|
|
55
54
|
* at column zero in both modes.
|
|
56
55
|
*
|
|
57
56
|
* `quoteStyle` selects the quote character used when a `plain`-styled scalar
|
|
58
57
|
* (the `defaultScalarStyle` default) turns out to require quoting: `"single"`
|
|
59
|
-
* (the default) emits `'@parcel/watcher'`
|
|
60
|
-
* form — while `"double"` emits `"@parcel/watcher"`, matching the `yaml` npm
|
|
58
|
+
* (the default) emits `'@parcel/watcher'`, while `"double"` emits `"@parcel/watcher"`, matching the `yaml` npm
|
|
61
59
|
* package's `singleQuote: false` output. It is a fallback selector only:
|
|
62
60
|
* scalars that need no quoting stay plain, and an explicit
|
|
63
61
|
* `defaultScalarStyle` of `"single-quoted"` or `"double-quoted"` still wins.
|
|
@@ -106,7 +104,7 @@ var YamlStringifyOptions = class extends Schema.Class("YamlStringifyOptions")({
|
|
|
106
104
|
indentSequences: Schema.optionalKey(Schema.Boolean),
|
|
107
105
|
/**
|
|
108
106
|
* Quote style used when a `plain`-styled scalar requires quoting. Default
|
|
109
|
-
* `"single"
|
|
107
|
+
* `"single"`. `"double"` renders
|
|
110
108
|
* the same scalars double-quoted instead, matching the `yaml` npm
|
|
111
109
|
* package's `singleQuote: false` output.
|
|
112
110
|
*
|
|
@@ -118,7 +116,7 @@ var YamlStringifyOptions = class extends Schema.Class("YamlStringifyOptions")({
|
|
|
118
116
|
/**
|
|
119
117
|
* Additionally quote plain scalars a foreign resolution dialect would
|
|
120
118
|
* coerce to a non-string. Absent (the default) adds no quoting beyond the
|
|
121
|
-
* YAML 1.2 Core Schema rules
|
|
119
|
+
* YAML 1.2 Core Schema rules.
|
|
122
120
|
*
|
|
123
121
|
* `"yaml-1.1"` quotes every plain scalar a YAML 1.1 parser (js-yaml,
|
|
124
122
|
* PyYAML, libyaml, and the `yaml` npm package's YAML 1.1 schema, whose
|
|
@@ -153,6 +151,13 @@ var YamlStringifyOptions = class extends Schema.Class("YamlStringifyOptions")({
|
|
|
153
151
|
* `code` field: read the code from the diagnostics —
|
|
154
152
|
* `error.diagnostics[0].code` is the primary failure.
|
|
155
153
|
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* The `message` renders each diagnostic's position 1-based
|
|
156
|
+
* (`line + 1:character + 1`) for human readers — a CLI printing this string
|
|
157
|
+
* shows the line/column a person counts in their editor. The structured
|
|
158
|
+
* {@link YamlDiagnostic} `line`/`character` fields stay 0-based (LSP
|
|
159
|
+
* convention); the offset applies to the rendered message only.
|
|
160
|
+
*
|
|
156
161
|
* @public
|
|
157
162
|
*/
|
|
158
163
|
var YamlParseError = class extends Schema.TaggedError()("YamlParseError", {
|
|
@@ -161,7 +166,7 @@ var YamlParseError = class extends Schema.TaggedError()("YamlParseError", {
|
|
|
161
166
|
}) {
|
|
162
167
|
get message() {
|
|
163
168
|
const count = this.diagnostics.length;
|
|
164
|
-
const summary = this.diagnostics.map((d) => `${d.code} at ${d.line}:${d.character}`).join("; ");
|
|
169
|
+
const summary = this.diagnostics.map((d) => `${d.code} at ${d.line + 1}:${d.character + 1}`).join("; ");
|
|
165
170
|
return `YAML parse failed with ${count} error${count === 1 ? "" : "s"}: ${summary}`;
|
|
166
171
|
}
|
|
167
172
|
};
|
|
@@ -315,7 +320,7 @@ const stringifyResultImpl = (value, options) => {
|
|
|
315
320
|
/**
|
|
316
321
|
* Collect the raw diagnostics that make a composed document a parse failure:
|
|
317
322
|
* every fatal-code error, plus DuplicateKey warnings promoted to errors when
|
|
318
|
-
* `uniqueKeys` is in force
|
|
323
|
+
* `uniqueKeys` is in force. Order preserved:
|
|
319
324
|
* fatals first, then promotions.
|
|
320
325
|
*/
|
|
321
326
|
const failureRecords = (doc, uniqueKeys) => {
|
|
@@ -370,6 +375,12 @@ var Yaml = class Yaml {
|
|
|
370
375
|
*
|
|
371
376
|
* Defined in terms of {@link Yaml.parseResult} — synchronous callers can
|
|
372
377
|
* use that variant directly.
|
|
378
|
+
*
|
|
379
|
+
* @param text - The YAML source to parse.
|
|
380
|
+
* @param options - Optional {@link YamlParseOptions}; defaults apply for
|
|
381
|
+
* omitted fields.
|
|
382
|
+
* @returns An `Effect` that succeeds with the decoded value, or fails with
|
|
383
|
+
* the aggregate {@link YamlParseError}.
|
|
373
384
|
*/
|
|
374
385
|
static parse = Effect.fn("Yaml.parse")((text, options) => Effect.fromResult(Yaml.parseResult(text, options)));
|
|
375
386
|
/**
|
|
@@ -384,6 +395,12 @@ var Yaml = class Yaml {
|
|
|
384
395
|
*
|
|
385
396
|
* Defined in terms of {@link Yaml.parseAllResult} — synchronous callers
|
|
386
397
|
* can use that variant directly.
|
|
398
|
+
*
|
|
399
|
+
* @param text - The YAML stream to parse.
|
|
400
|
+
* @param options - Optional {@link YamlParseOptions}; defaults apply for
|
|
401
|
+
* omitted fields.
|
|
402
|
+
* @returns An `Effect` that succeeds with one value per document, or fails
|
|
403
|
+
* with the aggregate {@link YamlParseError}.
|
|
387
404
|
*/
|
|
388
405
|
static parseAll = Effect.fn("Yaml.parseAll")((text, options) => Effect.fromResult(Yaml.parseAllResult(text, options)));
|
|
389
406
|
/**
|
|
@@ -401,6 +418,12 @@ var Yaml = class Yaml {
|
|
|
401
418
|
* `"<<"` key on a plain JavaScript object is an ordinary string key that
|
|
402
419
|
* never carried merge semantics, so emitting it plain would silently turn
|
|
403
420
|
* ordinary data into a merge directive.
|
|
421
|
+
*
|
|
422
|
+
* @param value - The plain JavaScript value to stringify.
|
|
423
|
+
* @param options - Optional {@link YamlStringifyOptions}; defaults apply for
|
|
424
|
+
* omitted fields.
|
|
425
|
+
* @returns An `Effect` that succeeds with the YAML text, or fails with
|
|
426
|
+
* {@link YamlStringifyError}.
|
|
404
427
|
*/
|
|
405
428
|
static stringify = Effect.fn("Yaml.stringify")(function* (value, options) {
|
|
406
429
|
return yield* stringifyOrFail(value, options);
|
|
@@ -516,6 +539,11 @@ var Yaml = class Yaml {
|
|
|
516
539
|
* `replaceCh` (e.g. `" "`), each comment character is replaced instead,
|
|
517
540
|
* keeping all offsets stable. Quote-aware: `#` inside quoted scalars is
|
|
518
541
|
* content, not a comment. Pure and total.
|
|
542
|
+
*
|
|
543
|
+
* @param text - The YAML source to strip.
|
|
544
|
+
* @param replaceCh - Optional single character replacing each stripped
|
|
545
|
+
* comment character (offset-preserving).
|
|
546
|
+
* @returns The text without comments.
|
|
519
547
|
*/
|
|
520
548
|
static stripComments(text, replaceCh) {
|
|
521
549
|
let result = "";
|
|
@@ -565,6 +593,10 @@ var Yaml = class Yaml {
|
|
|
565
593
|
* significant. Malformed input is never equal to anything — parse errors
|
|
566
594
|
* (or duplicate keys) on either side yield `false` rather than comparing
|
|
567
595
|
* recovery-parser artifacts. Pure and total.
|
|
596
|
+
*
|
|
597
|
+
* @param a - The first YAML source.
|
|
598
|
+
* @param b - The second YAML source.
|
|
599
|
+
* @returns `true` when `a` and `b` decode to structurally equal values.
|
|
568
600
|
*/
|
|
569
601
|
static equals(a, b) {
|
|
570
602
|
const va = parseForEquality(a);
|
|
@@ -576,6 +608,11 @@ var Yaml = class Yaml {
|
|
|
576
608
|
* Compare a YAML string against an existing JavaScript value with the
|
|
577
609
|
* same semantics as {@link Yaml.equals}: malformed `text` yields `false`.
|
|
578
610
|
* Pure and total.
|
|
611
|
+
*
|
|
612
|
+
* @param text - The YAML source to decode and compare.
|
|
613
|
+
* @param value - The plain JavaScript value to compare against.
|
|
614
|
+
* @returns `true` when `text` decodes to a value structurally equal to
|
|
615
|
+
* `value`.
|
|
579
616
|
*/
|
|
580
617
|
static equalsValue(text, value) {
|
|
581
618
|
const v = parseForEquality(text);
|
|
@@ -628,11 +665,14 @@ var Yaml = class Yaml {
|
|
|
628
665
|
/**
|
|
629
666
|
* Compose {@link Yaml.fromString} with a target schema, yielding a
|
|
630
667
|
* `Schema<A, string>` that decodes YAML straight into a validated domain
|
|
631
|
-
* value
|
|
632
|
-
* target's decoding/encoding service requirements flow through.
|
|
668
|
+
* value. The target's decoding/encoding service requirements flow through.
|
|
633
669
|
*
|
|
634
670
|
* Schema-producing: bind the result to a `const` on hot paths (see
|
|
635
671
|
* {@link Yaml.fromString}).
|
|
672
|
+
*
|
|
673
|
+
* @param target - The domain schema decoded values must satisfy.
|
|
674
|
+
* @param options - Optional {@link YamlParseOptions} applied on decode.
|
|
675
|
+
* @returns A `Schema.Codec<T, string>` decoding YAML text straight into `T`.
|
|
636
676
|
*/
|
|
637
677
|
static schema(target, options) {
|
|
638
678
|
return Yaml.fromString(options).pipe(Schema.decodeTo(target));
|
package/YamlDiagnostic.js
CHANGED
|
@@ -70,8 +70,10 @@ var YamlDiagnostic = class YamlDiagnostic extends Schema.Class("YamlDiagnostic")
|
|
|
70
70
|
/**
|
|
71
71
|
* The single fatal-code predicate: whether diagnostics with this code
|
|
72
72
|
* abort a parse (vs. being recoverable warnings-as-data). Declared once,
|
|
73
|
-
* as a property of the code
|
|
74
|
-
*
|
|
73
|
+
* as a property of the code.
|
|
74
|
+
*
|
|
75
|
+
* @param code - The diagnostic code to classify.
|
|
76
|
+
* @returns `true` when diagnostics with `code` abort a parse.
|
|
75
77
|
*/
|
|
76
78
|
static isFatal(code) {
|
|
77
79
|
return isFatalCode(code);
|
|
@@ -80,6 +82,10 @@ var YamlDiagnostic = class YamlDiagnostic extends Schema.Class("YamlDiagnostic")
|
|
|
80
82
|
* Materialize a raw engine diagnostic record into a `YamlDiagnostic`,
|
|
81
83
|
* deriving `line`/`character` from `offset` against the source `text`.
|
|
82
84
|
* Advanced — the parse/stringify entry points call this for you.
|
|
85
|
+
*
|
|
86
|
+
* @param raw - The engine record: `code`, `message`, `offset` and `length`.
|
|
87
|
+
* @param text - The source text the record's `offset` indexes into.
|
|
88
|
+
* @returns The diagnostic with `line` and `character` filled in.
|
|
83
89
|
*/
|
|
84
90
|
static fromRaw(raw, text) {
|
|
85
91
|
const { line, character } = lineChar(text, raw.offset);
|
package/YamlDocument.js
CHANGED
|
@@ -34,6 +34,17 @@ var YamlDirective = class extends Schema.Class("YamlDirective")({
|
|
|
34
34
|
* Construct via `YamlDocument.parse` / `parseAll`; `YamlDocument.make` is for
|
|
35
35
|
* synthetic documents.
|
|
36
36
|
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { YamlDocument } from "@effected/yaml";
|
|
40
|
+
* import { Effect } from "effect";
|
|
41
|
+
*
|
|
42
|
+
* const program = Effect.gen(function* () {
|
|
43
|
+
* const doc = yield* YamlDocument.parse("# header\nname: Alice\n");
|
|
44
|
+
* return doc.errors.length; // 0 — no recovered errors
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
37
48
|
* @public
|
|
38
49
|
*/
|
|
39
50
|
var YamlDocument = class YamlDocument extends Schema.Class("YamlDocument")({
|
|
@@ -52,6 +63,12 @@ var YamlDocument = class YamlDocument extends Schema.Class("YamlDocument")({
|
|
|
52
63
|
* recovered diagnostics. Fails with the aggregate {@link YamlParseError}
|
|
53
64
|
* when any fatal-code diagnostic is present; non-fatal diagnostics are
|
|
54
65
|
* data on the returned document.
|
|
66
|
+
*
|
|
67
|
+
* @param text - The YAML source to parse.
|
|
68
|
+
* @param options - Optional {@link YamlParseOptions}; defaults apply for
|
|
69
|
+
* omitted fields.
|
|
70
|
+
* @returns An `Effect` that succeeds with the {@link YamlDocument}, or fails
|
|
71
|
+
* with {@link YamlParseError}.
|
|
55
72
|
*/
|
|
56
73
|
static parse = Effect.fn("YamlDocument.parse")(function* (text, options) {
|
|
57
74
|
const raw = composeFirstDocument(text, toParseInput(options));
|
|
@@ -66,6 +83,12 @@ var YamlDocument = class YamlDocument extends Schema.Class("YamlDocument")({
|
|
|
66
83
|
* Parse a multi-document YAML stream into one {@link YamlDocument} per
|
|
67
84
|
* document. Any fatal diagnostic in any document — or a stream-level
|
|
68
85
|
* directive-placement error — fails the whole Effect.
|
|
86
|
+
*
|
|
87
|
+
* @param text - The YAML stream to parse.
|
|
88
|
+
* @param options - Optional {@link YamlParseOptions}; defaults apply for
|
|
89
|
+
* omitted fields.
|
|
90
|
+
* @returns An `Effect` that succeeds with one {@link YamlDocument} per
|
|
91
|
+
* document, or fails with {@link YamlParseError}.
|
|
69
92
|
*/
|
|
70
93
|
static parseAll = Effect.fn("YamlDocument.parseAll")(function* (text, options) {
|
|
71
94
|
const { documents, streamErrors } = composeAllDocuments(text, toParseInput(options));
|
|
@@ -84,6 +107,9 @@ var YamlDocument = class YamlDocument extends Schema.Class("YamlDocument")({
|
|
|
84
107
|
* Schema-producing: each call returns a fresh schema whose derivation
|
|
85
108
|
* caches are not shared across calls; bind the result to a `const` on hot
|
|
86
109
|
* paths.
|
|
110
|
+
*
|
|
111
|
+
* @param options - Optional {@link YamlParseOptions} applied on decode.
|
|
112
|
+
* @returns A `Schema.Codec<YamlDocument, string>`.
|
|
87
113
|
*/
|
|
88
114
|
static schema(options) {
|
|
89
115
|
return Schema.String.pipe(Schema.decodeTo(Schema.instanceOf(YamlDocument), SchemaTransformation.transformEffect({
|
|
@@ -109,6 +135,11 @@ var YamlDocument = class YamlDocument extends Schema.Class("YamlDocument")({
|
|
|
109
135
|
* option. Callers that need folding should render the plain value
|
|
110
136
|
* instead — `Yaml.stringify(doc.toValue(), options)` — at the cost of
|
|
111
137
|
* the document-level framing and styles this path preserves.
|
|
138
|
+
*
|
|
139
|
+
* @param options - Optional {@link YamlStringifyOptions}; defaults apply for
|
|
140
|
+
* omitted fields.
|
|
141
|
+
* @returns An `Effect` that succeeds with the YAML text, or fails with
|
|
142
|
+
* {@link YamlStringifyError}.
|
|
112
143
|
*/
|
|
113
144
|
stringify(options) {
|
|
114
145
|
return Effect.try({
|
package/YamlEdit.js
CHANGED
|
@@ -17,9 +17,10 @@ var YamlRange = class extends Schema.Class("YamlRange")({
|
|
|
17
17
|
* `content`. Set `length` to `0` to insert, `content` to `""` to delete.
|
|
18
18
|
*
|
|
19
19
|
* @remarks
|
|
20
|
-
* Structurally identical to
|
|
21
|
-
*
|
|
22
|
-
* can be written once over "a document codec's
|
|
20
|
+
* Structurally identical to the edit shape of `@effected/jsonc`,
|
|
21
|
+
* `@effected/toml` and `@effected/markdown` (same field names, types and
|
|
22
|
+
* semantics), so consumer code can be written once over "a document codec's
|
|
23
|
+
* Edit/Range/Path".
|
|
23
24
|
*
|
|
24
25
|
* @public
|
|
25
26
|
*/
|
|
@@ -33,6 +34,10 @@ var YamlEdit = class extends Schema.Class("YamlEdit")({
|
|
|
33
34
|
* reverse-offset order so earlier offsets stay valid; the input `edits`
|
|
34
35
|
* array is not mutated. Overlapping edits are a programmer error and throw
|
|
35
36
|
* as a defect — `YamlFormat` never produces them.
|
|
37
|
+
*
|
|
38
|
+
* @param text - The source text to edit.
|
|
39
|
+
* @param edits - The edits to apply, in any order.
|
|
40
|
+
* @returns The edited text.
|
|
36
41
|
*/
|
|
37
42
|
static applyAll(text, edits) {
|
|
38
43
|
const sorted = [...edits].sort((a, b) => b.offset - a.offset);
|
package/YamlFormat.js
CHANGED
|
@@ -15,8 +15,8 @@ import { Effect, Schema } from "effect";
|
|
|
15
15
|
* field (derived, not hand-duplicated — including `indentSequences`,
|
|
16
16
|
* `quoteStyle` and `quoteCompat`) plus
|
|
17
17
|
* `preserveComments` (default `true`), `range` (restrict edits to a
|
|
18
|
-
* region;
|
|
19
|
-
* field) and `requoteScalars` (default `false`).
|
|
18
|
+
* region; the positional `range` argument of {@link YamlFormat.format} takes
|
|
19
|
+
* precedence over this field) and `requoteScalars` (default `false`).
|
|
20
20
|
*
|
|
21
21
|
* `requoteScalars` makes `quoteStyle` apply to scalars **already quoted in
|
|
22
22
|
* the source** on the format path — by default formatting preserves an
|
|
@@ -259,7 +259,7 @@ function formatStream(text, documents, streamErrors, options) {
|
|
|
259
259
|
* Before this was recursive, a mapping or sequence value fell through to the
|
|
260
260
|
* node stringifier's `String(value)` fallback and landed in the document as
|
|
261
261
|
* the literal text `[object Object]` — a silent corruption that only surfaced
|
|
262
|
-
* on the next read
|
|
262
|
+
* on the next read.
|
|
263
263
|
*
|
|
264
264
|
* The two conditions with no finite rendering fail typed rather than hanging
|
|
265
265
|
* or overflowing the stack: a cycle raises `CircularReference` and a graph
|
|
@@ -472,7 +472,7 @@ function findExistingTarget(contents, path) {
|
|
|
472
472
|
* resolved type — as does any plain target, so the stringifier's own
|
|
473
473
|
* plain-safety rules decide whether the text needs quotes — under the
|
|
474
474
|
* target's own context, so a flow indicator inside a value spliced into a
|
|
475
|
-
* flow collection is quoted rather than corrupting the collection
|
|
475
|
+
* flow collection is quoted rather than corrupting the collection. A
|
|
476
476
|
* rendering that spans lines (folding, block styles) bails out: the fast
|
|
477
477
|
* path never introduces a line break inside the spliced region.
|
|
478
478
|
*/
|
|
@@ -515,7 +515,7 @@ function regionalRenderPreservesValue(rendered, value, inFlow) {
|
|
|
515
515
|
return Object.is(node.value, value);
|
|
516
516
|
}
|
|
517
517
|
/**
|
|
518
|
-
* Attempt the region-confined scalar splice for `modify
|
|
518
|
+
* Attempt the region-confined scalar splice for `modify`: replace
|
|
519
519
|
* only the target scalar's byte range, re-emitting its original quote
|
|
520
520
|
* character and leaving line endings (and every other byte) elsewhere
|
|
521
521
|
* untouched. Returns the single edit, an empty array for a no-op
|
|
@@ -547,7 +547,22 @@ function tryRegionalScalarEdit(text, doc, path, value, options) {
|
|
|
547
547
|
}];
|
|
548
548
|
}
|
|
549
549
|
/**
|
|
550
|
-
*
|
|
550
|
+
* Formats YAML text and modifies values at a path as byte-minimal edits that
|
|
551
|
+
* preserve comments and layout elsewhere. Not instantiable.
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* ```ts
|
|
555
|
+
* import { YamlFormat } from "@effected/yaml";
|
|
556
|
+
* import { Effect } from "effect";
|
|
557
|
+
*
|
|
558
|
+
* const formatted = YamlFormat.formatToString("a: 1\nb:\n - x\n - y # c\n");
|
|
559
|
+
* // => "a: 1\nb:\n- x\n- y # c\n"
|
|
560
|
+
*
|
|
561
|
+
* const program = Effect.gen(function* () {
|
|
562
|
+
* return yield* YamlFormat.modifyToString("port: 3000 # dev\n", ["port"], 8080);
|
|
563
|
+
* // => "port: 8080 # dev\n"
|
|
564
|
+
* });
|
|
565
|
+
* ```
|
|
551
566
|
*
|
|
552
567
|
* @remarks
|
|
553
568
|
* `format`/`formatToString` are pure and total (edit computation never fails
|
|
@@ -573,8 +588,8 @@ function tryRegionalScalarEdit(text, doc, path, value, options) {
|
|
|
573
588
|
* (`!e!foo`) turns a valid file into one no parser can read. So
|
|
574
589
|
* `format`/`formatToString` leave such input byte-identical (no edits), and
|
|
575
590
|
* `modify`/`modifyToString` fail typed with a `DirectiveCarryingDocument`
|
|
576
|
-
* diagnostic. Directive re-emission is unimplemented,
|
|
577
|
-
*
|
|
591
|
+
* diagnostic. Directive re-emission is unimplemented, and the refusal is what
|
|
592
|
+
* stops the corruption.
|
|
578
593
|
*
|
|
579
594
|
* @public
|
|
580
595
|
*/
|
|
@@ -604,6 +619,12 @@ var YamlFormat = class YamlFormat {
|
|
|
604
619
|
* directives is left untouched. Detection is directive-token-level: a
|
|
605
620
|
* literal `%TAG` inside a scalar is content and formats normally.
|
|
606
621
|
*
|
|
622
|
+
* @param text - The YAML source to format.
|
|
623
|
+
* @param range - Optional sub-range; only edits fully within it are returned.
|
|
624
|
+
* @param options - Optional {@link YamlFormattingOptions}.
|
|
625
|
+
* @returns The edits that bring `text` to canonical shape; apply them with
|
|
626
|
+
* `YamlEdit.applyAll`. Empty when the input cannot be formatted faithfully.
|
|
627
|
+
*
|
|
607
628
|
* @remarks
|
|
608
629
|
* The positional `range` argument takes precedence over
|
|
609
630
|
* `options?.range` when both are given; either accepts a plain
|
|
@@ -646,6 +667,12 @@ var YamlFormat = class YamlFormat {
|
|
|
646
667
|
* document — single or in a stream — carrying `%YAML`/`%TAG` directives)
|
|
647
668
|
* is returned byte-identical — never a truncated first document, never a
|
|
648
669
|
* document re-emitted without the directive its tags depend on.
|
|
670
|
+
*
|
|
671
|
+
* @param text - The YAML source to format.
|
|
672
|
+
* @param range - Optional sub-range; only edits fully within it are applied.
|
|
673
|
+
* @param options - Optional {@link YamlFormattingOptions}.
|
|
674
|
+
* @returns The formatted text, or `text` unchanged when it cannot be
|
|
675
|
+
* formatted faithfully.
|
|
649
676
|
*/
|
|
650
677
|
static formatToString(text, range, options) {
|
|
651
678
|
return YamlEdit.applyAll(text, YamlFormat.format(text, range, options));
|
|
@@ -661,15 +688,12 @@ var YamlFormat = class YamlFormat {
|
|
|
661
688
|
* sequence and any other non-null object as a block mapping over its own
|
|
662
689
|
* enumerable string keys, recursively — the same lowering
|
|
663
690
|
* {@link Yaml.stringify} applies to the same value, so `modify` and
|
|
664
|
-
* `stringify` agree on what a given JavaScript value means.
|
|
665
|
-
* 0.14.0 only scalars were lowered and a mapping or sequence value was
|
|
666
|
-
* coerced through `String(value)`, writing the literal text
|
|
667
|
-
* `[object Object]` into the document — see #642.) For a synthesized
|
|
691
|
+
* `stringify` agree on what a given JavaScript value means. For a synthesized
|
|
668
692
|
* subtree (an object/array value) only the surrounding document is
|
|
669
693
|
* preserved byte-for-byte; the subtree carries no comments and takes the
|
|
670
694
|
* stringifier's styles.
|
|
671
695
|
*
|
|
672
|
-
* **Scalar replacement is region-confined and quote-preserving
|
|
696
|
+
* **Scalar replacement is region-confined and quote-preserving.**
|
|
673
697
|
* When the path resolves to an existing single-line `plain`,
|
|
674
698
|
* `single-quoted`, or `double-quoted` scalar with no tag or anchor, and
|
|
675
699
|
* the replacement is a string, number, or boolean, `modify` splices
|
|
@@ -710,6 +734,15 @@ var YamlFormat = class YamlFormat {
|
|
|
710
734
|
* directive re-emission is unimplemented, not undesired. A literal
|
|
711
735
|
* `%TAG` inside a scalar is content and does not trigger the refusal.
|
|
712
736
|
*
|
|
737
|
+
* @param text - The YAML source to modify.
|
|
738
|
+
* @param path - The location to insert, replace or remove.
|
|
739
|
+
* @param value - The JavaScript value to write; `undefined` removes the
|
|
740
|
+
* target instead.
|
|
741
|
+
* @param options - Optional {@link YamlStringifyOptions} for the
|
|
742
|
+
* re-stringify step.
|
|
743
|
+
* @returns An `Effect` that succeeds with the edits to apply (via
|
|
744
|
+
* `YamlEdit.applyAll`), or fails with {@link YamlModificationError}.
|
|
745
|
+
*
|
|
713
746
|
* @remarks
|
|
714
747
|
* `options` is a bare {@link YamlStringifyOptions} — it controls only the
|
|
715
748
|
* internal re-stringify step, not a range (there is no range to restrict
|
|
@@ -770,6 +803,15 @@ var YamlFormat = class YamlFormat {
|
|
|
770
803
|
* error channel, including the single-document contract's
|
|
771
804
|
* `MultiDocumentStream` refusal and the `DirectiveCarryingDocument`
|
|
772
805
|
* refusal of `%YAML`/`%TAG`-carrying documents.
|
|
806
|
+
*
|
|
807
|
+
* @param text - The YAML source to modify.
|
|
808
|
+
* @param path - The location to insert, replace or remove.
|
|
809
|
+
* @param value - The JavaScript value to write; `undefined` removes the
|
|
810
|
+
* target instead.
|
|
811
|
+
* @param options - Optional {@link YamlStringifyOptions} for the
|
|
812
|
+
* re-stringify step.
|
|
813
|
+
* @returns An `Effect` that succeeds with the modified text, or fails with
|
|
814
|
+
* {@link YamlModificationError}.
|
|
773
815
|
*/
|
|
774
816
|
static modifyToString = Effect.fn("YamlFormat.modifyToString")(function* (text, path, value, options) {
|
|
775
817
|
const edits = yield* YamlFormat.modify(text, path, value, options);
|
package/YamlLint.js
CHANGED
|
Binary file
|
package/YamlLintRule.js
CHANGED
|
@@ -32,7 +32,7 @@ var YamlLintDiagnostic = class extends Schema.Class("YamlLintDiagnostic")({
|
|
|
32
32
|
fix: Schema.optionalKey(YamlEdit)
|
|
33
33
|
}) {};
|
|
34
34
|
/**
|
|
35
|
-
* One categorical style observation
|
|
35
|
+
* One categorical style observation: a single occurrence of a style
|
|
36
36
|
* choice in the source, voting a `value` for an inference `dimension`.
|
|
37
37
|
*
|
|
38
38
|
* The `dimension` IS the rule's option key and the `value` IS that option's
|
|
@@ -64,7 +64,7 @@ var StyleVote = class extends Schema.TaggedClass()("StyleVote", {
|
|
|
64
64
|
character: Schema.Number
|
|
65
65
|
}) {};
|
|
66
66
|
/**
|
|
67
|
-
* One measured style floor
|
|
67
|
+
* One measured style floor: a value the source PROVES is at least
|
|
68
68
|
* `value`, without proving what the configured limit should be — the longest
|
|
69
69
|
* observed line proves `line-length.max` is at least that long, not what it
|
|
70
70
|
* is. Floors are carried in the evidence for callers that want them and are
|
package/YamlToken.js
CHANGED
|
@@ -82,7 +82,9 @@ const promoteAll = (text, tokens) => {
|
|
|
82
82
|
});
|
|
83
83
|
};
|
|
84
84
|
/**
|
|
85
|
-
*
|
|
85
|
+
* Tokenizes YAML text into positioned tokens, as a complete array or a lazy
|
|
86
|
+
* `Stream`, for lint- and editor-class consumers. Never fails on malformed
|
|
87
|
+
* input: lexical errors arrive as `"error"`-kind tokens. Not instantiable.
|
|
86
88
|
*
|
|
87
89
|
* @public
|
|
88
90
|
*/
|
|
@@ -91,12 +93,11 @@ var YamlTokens = class YamlTokens {
|
|
|
91
93
|
/**
|
|
92
94
|
* Tokenize YAML text into the full positioned token array — the sync
|
|
93
95
|
* `Result` primitive (tokenizing is a pure batch transform; the
|
|
94
|
-
* {@link YamlTokens.stream} form is derived from this one
|
|
95
|
-
* sync-primitive policy).
|
|
96
|
+
* {@link YamlTokens.stream} form is derived from this one).
|
|
96
97
|
*
|
|
97
98
|
* @remarks
|
|
98
|
-
* The failure channel is **reserved**
|
|
99
|
-
*
|
|
99
|
+
* The failure channel is **reserved** for input-hardening guards and never
|
|
100
|
+
* fires today: the lexer is total, and lexical errors surface as
|
|
100
101
|
* `"error"`-kind tokens **in the success array** so that linting can run
|
|
101
102
|
* on malformed input — the `parse-validity` lint rule exists precisely for
|
|
102
103
|
* documents that do not parse. Do not "fix" this method to fail on
|
|
@@ -112,6 +113,9 @@ var YamlTokens = class YamlTokens {
|
|
|
112
113
|
* result.success.map((t) => t.kind); // ["scalar", "block-map-start", ...]
|
|
113
114
|
* }
|
|
114
115
|
* ```
|
|
116
|
+
*
|
|
117
|
+
* @param text - The YAML source to tokenize.
|
|
118
|
+
* @returns A `Result` succeeding with every token in source order.
|
|
115
119
|
*/
|
|
116
120
|
static tokenize(text) {
|
|
117
121
|
return Result.succeed(promoteAll(text, lexAll(text)));
|
package/YamlVisitor.js
CHANGED
|
@@ -13,7 +13,23 @@ import { Data, Stream } from "effect";
|
|
|
13
13
|
*/
|
|
14
14
|
const YamlVisitorEvent = Data.taggedEnum();
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Walks YAML text as a lazy `Stream` of typed events — documents, collections,
|
|
17
|
+
* pairs, scalars, aliases, comments, directives and recovered errors — in
|
|
18
|
+
* document order. Not instantiable.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { YamlVisitor, YamlVisitorEvent } from "@effected/yaml";
|
|
23
|
+
* import { Effect, Stream } from "effect";
|
|
24
|
+
*
|
|
25
|
+
* // Mapping keys are scalar events too, so keys and values interleave.
|
|
26
|
+
* const scalars = YamlVisitor.visit("a: 1\nb:\n - x\n").pipe(
|
|
27
|
+
* Stream.filter(YamlVisitorEvent.$is("Scalar")),
|
|
28
|
+
* Stream.map((event) => event.value),
|
|
29
|
+
* Stream.runCollect,
|
|
30
|
+
* );
|
|
31
|
+
* // Effect.runSync(scalars) // => ["a", 1, "b", "x"]
|
|
32
|
+
* ```
|
|
17
33
|
*
|
|
18
34
|
* @public
|
|
19
35
|
*/
|
|
@@ -31,6 +47,11 @@ var YamlVisitor = class {
|
|
|
31
47
|
* (fatal or not, including an exceeded `maxAliasCount`, recorded as
|
|
32
48
|
* `AliasCountExceeded`) surface as `Error` events inside the stream rather
|
|
33
49
|
* than failing it.
|
|
50
|
+
*
|
|
51
|
+
* @param text - The YAML source to visit.
|
|
52
|
+
* @param options - Optional {@link YamlParseOptions} controlling composition.
|
|
53
|
+
* @returns A lazy `Stream` of `YamlVisitorEvent`, infallible at the type
|
|
54
|
+
* level.
|
|
34
55
|
*/
|
|
35
56
|
static visit(text, options) {
|
|
36
57
|
return Stream.fromIterable(visitGen(text, options));
|
package/index.d.ts
CHANGED
|
@@ -99,14 +99,20 @@ export declare class YamlDiagnostic extends YamlDiagnostic_base {
|
|
|
99
99
|
/**
|
|
100
100
|
* The single fatal-code predicate: whether diagnostics with this code
|
|
101
101
|
* abort a parse (vs. being recoverable warnings-as-data). Declared once,
|
|
102
|
-
* as a property of the code
|
|
103
|
-
*
|
|
102
|
+
* as a property of the code.
|
|
103
|
+
*
|
|
104
|
+
* @param code - The diagnostic code to classify.
|
|
105
|
+
* @returns `true` when diagnostics with `code` abort a parse.
|
|
104
106
|
*/
|
|
105
107
|
static isFatal(code: YamlErrorCode): boolean;
|
|
106
108
|
/**
|
|
107
109
|
* Materialize a raw engine diagnostic record into a `YamlDiagnostic`,
|
|
108
110
|
* deriving `line`/`character` from `offset` against the source `text`.
|
|
109
111
|
* Advanced — the parse/stringify entry points call this for you.
|
|
112
|
+
*
|
|
113
|
+
* @param raw - The engine record: `code`, `message`, `offset` and `length`.
|
|
114
|
+
* @param text - The source text the record's `offset` indexes into.
|
|
115
|
+
* @returns The diagnostic with `line` and `character` filled in.
|
|
110
116
|
*/
|
|
111
117
|
static fromRaw(raw: {
|
|
112
118
|
readonly code: YamlErrorCode;
|
|
@@ -166,7 +172,7 @@ declare const YamlStringifyOptions_base: Schema.Class<YamlStringifyOptions, Sche
|
|
|
166
172
|
readonly indentSequences: Schema.optionalKey<Schema.Boolean>;
|
|
167
173
|
/**
|
|
168
174
|
* Quote style used when a `plain`-styled scalar requires quoting. Default
|
|
169
|
-
* `"single"
|
|
175
|
+
* `"single"`. `"double"` renders
|
|
170
176
|
* the same scalars double-quoted instead, matching the `yaml` npm
|
|
171
177
|
* package's `singleQuote: false` output.
|
|
172
178
|
*
|
|
@@ -178,7 +184,7 @@ declare const YamlStringifyOptions_base: Schema.Class<YamlStringifyOptions, Sche
|
|
|
178
184
|
/**
|
|
179
185
|
* Additionally quote plain scalars a foreign resolution dialect would
|
|
180
186
|
* coerce to a non-string. Absent (the default) adds no quoting beyond the
|
|
181
|
-
* YAML 1.2 Core Schema rules
|
|
187
|
+
* YAML 1.2 Core Schema rules.
|
|
182
188
|
*
|
|
183
189
|
* `"yaml-1.1"` quotes every plain scalar a YAML 1.1 parser (js-yaml,
|
|
184
190
|
* PyYAML, libyaml, and the `yaml` npm package's YAML 1.1 schema, whose
|
|
@@ -214,8 +220,7 @@ declare const YamlStringifyOptions_base: Schema.Class<YamlStringifyOptions, Sche
|
|
|
214
220
|
* `false`.
|
|
215
221
|
*
|
|
216
222
|
* `lineWidth` controls column-based scalar folding. The default `0` (and any
|
|
217
|
-
* value `<= 0`) never wraps
|
|
218
|
-
* no-fold behavior; a positive value folds long plain, double-quoted and
|
|
223
|
+
* value `<= 0`) never wraps; a positive value folds long plain, double-quoted and
|
|
219
224
|
* block-folded (`>`) scalars at approximately that column, inserting only
|
|
220
225
|
* semantically transparent line breaks. Block-literal (`|`) content is never
|
|
221
226
|
* folded — literal blocks preserve their bytes by definition. Folding is a
|
|
@@ -223,15 +228,14 @@ declare const YamlStringifyOptions_base: Schema.Class<YamlStringifyOptions, Sche
|
|
|
223
228
|
* helpers accept these options but do not fold (see `lineWidth`).
|
|
224
229
|
*
|
|
225
230
|
* `indentSequences` controls the presentation of block sequences nested under
|
|
226
|
-
* a mapping key: `false` (the default) emits them at the key's column
|
|
227
|
-
*
|
|
231
|
+
* a mapping key: `false` (the default) emits them at the key's column, while
|
|
232
|
+
* `true` indents them one level,
|
|
228
233
|
* matching the `yaml` npm package's default output. Top-level sequences stay
|
|
229
234
|
* at column zero in both modes.
|
|
230
235
|
*
|
|
231
236
|
* `quoteStyle` selects the quote character used when a `plain`-styled scalar
|
|
232
237
|
* (the `defaultScalarStyle` default) turns out to require quoting: `"single"`
|
|
233
|
-
* (the default) emits `'@parcel/watcher'`
|
|
234
|
-
* form — while `"double"` emits `"@parcel/watcher"`, matching the `yaml` npm
|
|
238
|
+
* (the default) emits `'@parcel/watcher'`, while `"double"` emits `"@parcel/watcher"`, matching the `yaml` npm
|
|
235
239
|
* package's `singleQuote: false` output. It is a fallback selector only:
|
|
236
240
|
* scalars that need no quoting stay plain, and an explicit
|
|
237
241
|
* `defaultScalarStyle` of `"single-quoted"` or `"double-quoted"` still wins.
|
|
@@ -270,6 +274,13 @@ declare const YamlParseError_base: Schema.Class<YamlParseError, Schema.TaggedStr
|
|
|
270
274
|
* `code` field: read the code from the diagnostics —
|
|
271
275
|
* `error.diagnostics[0].code` is the primary failure.
|
|
272
276
|
*
|
|
277
|
+
* @remarks
|
|
278
|
+
* The `message` renders each diagnostic's position 1-based
|
|
279
|
+
* (`line + 1:character + 1`) for human readers — a CLI printing this string
|
|
280
|
+
* shows the line/column a person counts in their editor. The structured
|
|
281
|
+
* {@link YamlDiagnostic} `line`/`character` fields stay 0-based (LSP
|
|
282
|
+
* convention); the offset applies to the rendered message only.
|
|
283
|
+
*
|
|
273
284
|
* @public
|
|
274
285
|
*/
|
|
275
286
|
export declare class YamlParseError extends YamlParseError_base {
|
|
@@ -346,6 +357,12 @@ export declare class Yaml {
|
|
|
346
357
|
*
|
|
347
358
|
* Defined in terms of {@link Yaml.parseResult} — synchronous callers can
|
|
348
359
|
* use that variant directly.
|
|
360
|
+
*
|
|
361
|
+
* @param text - The YAML source to parse.
|
|
362
|
+
* @param options - Optional {@link YamlParseOptions}; defaults apply for
|
|
363
|
+
* omitted fields.
|
|
364
|
+
* @returns An `Effect` that succeeds with the decoded value, or fails with
|
|
365
|
+
* the aggregate {@link YamlParseError}.
|
|
349
366
|
*/
|
|
350
367
|
static readonly parse: (text: string, options?: YamlParseOptions | undefined) => Effect.Effect<unknown, YamlParseError, never>;
|
|
351
368
|
/**
|
|
@@ -360,6 +377,12 @@ export declare class Yaml {
|
|
|
360
377
|
*
|
|
361
378
|
* Defined in terms of {@link Yaml.parseAllResult} — synchronous callers
|
|
362
379
|
* can use that variant directly.
|
|
380
|
+
*
|
|
381
|
+
* @param text - The YAML stream to parse.
|
|
382
|
+
* @param options - Optional {@link YamlParseOptions}; defaults apply for
|
|
383
|
+
* omitted fields.
|
|
384
|
+
* @returns An `Effect` that succeeds with one value per document, or fails
|
|
385
|
+
* with the aggregate {@link YamlParseError}.
|
|
363
386
|
*/
|
|
364
387
|
static readonly parseAll: (text: string, options?: YamlParseOptions | undefined) => Effect.Effect<readonly unknown[], YamlParseError, never>;
|
|
365
388
|
/**
|
|
@@ -377,6 +400,12 @@ export declare class Yaml {
|
|
|
377
400
|
* `"<<"` key on a plain JavaScript object is an ordinary string key that
|
|
378
401
|
* never carried merge semantics, so emitting it plain would silently turn
|
|
379
402
|
* ordinary data into a merge directive.
|
|
403
|
+
*
|
|
404
|
+
* @param value - The plain JavaScript value to stringify.
|
|
405
|
+
* @param options - Optional {@link YamlStringifyOptions}; defaults apply for
|
|
406
|
+
* omitted fields.
|
|
407
|
+
* @returns An `Effect` that succeeds with the YAML text, or fails with
|
|
408
|
+
* {@link YamlStringifyError}.
|
|
380
409
|
*/
|
|
381
410
|
static readonly stringify: (value: unknown, options?: YamlStringifyOptions | undefined) => Effect.Effect<string, YamlStringifyError, never>;
|
|
382
411
|
/**
|
|
@@ -484,6 +513,11 @@ export declare class Yaml {
|
|
|
484
513
|
* `replaceCh` (e.g. `" "`), each comment character is replaced instead,
|
|
485
514
|
* keeping all offsets stable. Quote-aware: `#` inside quoted scalars is
|
|
486
515
|
* content, not a comment. Pure and total.
|
|
516
|
+
*
|
|
517
|
+
* @param text - The YAML source to strip.
|
|
518
|
+
* @param replaceCh - Optional single character replacing each stripped
|
|
519
|
+
* comment character (offset-preserving).
|
|
520
|
+
* @returns The text without comments.
|
|
487
521
|
*/
|
|
488
522
|
static stripComments(text: string, replaceCh?: string): string;
|
|
489
523
|
/**
|
|
@@ -492,12 +526,21 @@ export declare class Yaml {
|
|
|
492
526
|
* significant. Malformed input is never equal to anything — parse errors
|
|
493
527
|
* (or duplicate keys) on either side yield `false` rather than comparing
|
|
494
528
|
* recovery-parser artifacts. Pure and total.
|
|
529
|
+
*
|
|
530
|
+
* @param a - The first YAML source.
|
|
531
|
+
* @param b - The second YAML source.
|
|
532
|
+
* @returns `true` when `a` and `b` decode to structurally equal values.
|
|
495
533
|
*/
|
|
496
534
|
static equals(a: string, b: string): boolean;
|
|
497
535
|
/**
|
|
498
536
|
* Compare a YAML string against an existing JavaScript value with the
|
|
499
537
|
* same semantics as {@link Yaml.equals}: malformed `text` yields `false`.
|
|
500
538
|
* Pure and total.
|
|
539
|
+
*
|
|
540
|
+
* @param text - The YAML source to decode and compare.
|
|
541
|
+
* @param value - The plain JavaScript value to compare against.
|
|
542
|
+
* @returns `true` when `text` decodes to a value structurally equal to
|
|
543
|
+
* `value`.
|
|
501
544
|
*/
|
|
502
545
|
static equalsValue(text: string, value: unknown): boolean;
|
|
503
546
|
/**
|
|
@@ -528,11 +571,14 @@ export declare class Yaml {
|
|
|
528
571
|
/**
|
|
529
572
|
* Compose {@link Yaml.fromString} with a target schema, yielding a
|
|
530
573
|
* `Schema<A, string>` that decodes YAML straight into a validated domain
|
|
531
|
-
* value
|
|
532
|
-
* target's decoding/encoding service requirements flow through.
|
|
574
|
+
* value. The target's decoding/encoding service requirements flow through.
|
|
533
575
|
*
|
|
534
576
|
* Schema-producing: bind the result to a `const` on hot paths (see
|
|
535
577
|
* {@link Yaml.fromString}).
|
|
578
|
+
*
|
|
579
|
+
* @param target - The domain schema decoded values must satisfy.
|
|
580
|
+
* @param options - Optional {@link YamlParseOptions} applied on decode.
|
|
581
|
+
* @returns A `Schema.Codec<T, string>` decoding YAML text straight into `T`.
|
|
536
582
|
*/
|
|
537
583
|
static schema<T, E, RD = never, RE = never>(target: Schema.Codec<T, E, RD, RE>, options?: YamlParseOptions): Schema.Codec<T, string, RD, RE>;
|
|
538
584
|
/**
|
|
@@ -612,9 +658,10 @@ declare const YamlEdit_base: Schema.Class<YamlEdit, Schema.Struct<{
|
|
|
612
658
|
* `content`. Set `length` to `0` to insert, `content` to `""` to delete.
|
|
613
659
|
*
|
|
614
660
|
* @remarks
|
|
615
|
-
* Structurally identical to
|
|
616
|
-
*
|
|
617
|
-
* can be written once over "a document codec's
|
|
661
|
+
* Structurally identical to the edit shape of `@effected/jsonc`,
|
|
662
|
+
* `@effected/toml` and `@effected/markdown` (same field names, types and
|
|
663
|
+
* semantics), so consumer code can be written once over "a document codec's
|
|
664
|
+
* Edit/Range/Path".
|
|
618
665
|
*
|
|
619
666
|
* @public
|
|
620
667
|
*/
|
|
@@ -624,6 +671,10 @@ export declare class YamlEdit extends YamlEdit_base {
|
|
|
624
671
|
* reverse-offset order so earlier offsets stay valid; the input `edits`
|
|
625
672
|
* array is not mutated. Overlapping edits are a programmer error and throw
|
|
626
673
|
* as a defect — `YamlFormat` never produces them.
|
|
674
|
+
*
|
|
675
|
+
* @param text - The source text to edit.
|
|
676
|
+
* @param edits - The edits to apply, in any order.
|
|
677
|
+
* @returns The edited text.
|
|
627
678
|
*/
|
|
628
679
|
static applyAll(text: string, edits: ReadonlyArray<YamlEdit>): string;
|
|
629
680
|
}
|
|
@@ -980,6 +1031,17 @@ declare const YamlDocument_base: Schema.Class<YamlDocument, Schema.Struct<{
|
|
|
980
1031
|
* Construct via `YamlDocument.parse` / `parseAll`; `YamlDocument.make` is for
|
|
981
1032
|
* synthetic documents.
|
|
982
1033
|
*
|
|
1034
|
+
* @example
|
|
1035
|
+
* ```ts
|
|
1036
|
+
* import { YamlDocument } from "@effected/yaml";
|
|
1037
|
+
* import { Effect } from "effect";
|
|
1038
|
+
*
|
|
1039
|
+
* const program = Effect.gen(function* () {
|
|
1040
|
+
* const doc = yield* YamlDocument.parse("# header\nname: Alice\n");
|
|
1041
|
+
* return doc.errors.length; // 0 — no recovered errors
|
|
1042
|
+
* });
|
|
1043
|
+
* ```
|
|
1044
|
+
*
|
|
983
1045
|
* @public
|
|
984
1046
|
*/
|
|
985
1047
|
export declare class YamlDocument extends YamlDocument_base {
|
|
@@ -988,12 +1050,24 @@ export declare class YamlDocument extends YamlDocument_base {
|
|
|
988
1050
|
* recovered diagnostics. Fails with the aggregate {@link YamlParseError}
|
|
989
1051
|
* when any fatal-code diagnostic is present; non-fatal diagnostics are
|
|
990
1052
|
* data on the returned document.
|
|
1053
|
+
*
|
|
1054
|
+
* @param text - The YAML source to parse.
|
|
1055
|
+
* @param options - Optional {@link YamlParseOptions}; defaults apply for
|
|
1056
|
+
* omitted fields.
|
|
1057
|
+
* @returns An `Effect` that succeeds with the {@link YamlDocument}, or fails
|
|
1058
|
+
* with {@link YamlParseError}.
|
|
991
1059
|
*/
|
|
992
1060
|
static readonly parse: (text: string, options?: YamlParseOptions | undefined) => Effect.Effect<YamlDocument, YamlParseError, never>;
|
|
993
1061
|
/**
|
|
994
1062
|
* Parse a multi-document YAML stream into one {@link YamlDocument} per
|
|
995
1063
|
* document. Any fatal diagnostic in any document — or a stream-level
|
|
996
1064
|
* directive-placement error — fails the whole Effect.
|
|
1065
|
+
*
|
|
1066
|
+
* @param text - The YAML stream to parse.
|
|
1067
|
+
* @param options - Optional {@link YamlParseOptions}; defaults apply for
|
|
1068
|
+
* omitted fields.
|
|
1069
|
+
* @returns An `Effect` that succeeds with one {@link YamlDocument} per
|
|
1070
|
+
* document, or fails with {@link YamlParseError}.
|
|
997
1071
|
*/
|
|
998
1072
|
static readonly parseAll: (text: string, options?: YamlParseOptions | undefined) => Effect.Effect<readonly YamlDocument[], YamlParseError, never>;
|
|
999
1073
|
/**
|
|
@@ -1004,6 +1078,9 @@ export declare class YamlDocument extends YamlDocument_base {
|
|
|
1004
1078
|
* Schema-producing: each call returns a fresh schema whose derivation
|
|
1005
1079
|
* caches are not shared across calls; bind the result to a `const` on hot
|
|
1006
1080
|
* paths.
|
|
1081
|
+
*
|
|
1082
|
+
* @param options - Optional {@link YamlParseOptions} applied on decode.
|
|
1083
|
+
* @returns A `Schema.Codec<YamlDocument, string>`.
|
|
1007
1084
|
*/
|
|
1008
1085
|
static schema(options?: YamlParseOptions): Schema.Codec<YamlDocument, string>;
|
|
1009
1086
|
/**
|
|
@@ -1024,6 +1101,11 @@ export declare class YamlDocument extends YamlDocument_base {
|
|
|
1024
1101
|
* option. Callers that need folding should render the plain value
|
|
1025
1102
|
* instead — `Yaml.stringify(doc.toValue(), options)` — at the cost of
|
|
1026
1103
|
* the document-level framing and styles this path preserves.
|
|
1104
|
+
*
|
|
1105
|
+
* @param options - Optional {@link YamlStringifyOptions}; defaults apply for
|
|
1106
|
+
* omitted fields.
|
|
1107
|
+
* @returns An `Effect` that succeeds with the YAML text, or fails with
|
|
1108
|
+
* {@link YamlStringifyError}.
|
|
1027
1109
|
*/
|
|
1028
1110
|
stringify(options?: YamlStringifyOptions): Effect.Effect<string, YamlStringifyError>;
|
|
1029
1111
|
/**
|
|
@@ -1066,8 +1148,8 @@ declare const YamlFormattingOptions_base: Schema.Class<YamlFormattingOptions, Sc
|
|
|
1066
1148
|
* field (derived, not hand-duplicated — including `indentSequences`,
|
|
1067
1149
|
* `quoteStyle` and `quoteCompat`) plus
|
|
1068
1150
|
* `preserveComments` (default `true`), `range` (restrict edits to a
|
|
1069
|
-
* region;
|
|
1070
|
-
* field) and `requoteScalars` (default `false`).
|
|
1151
|
+
* region; the positional `range` argument of {@link YamlFormat.format} takes
|
|
1152
|
+
* precedence over this field) and `requoteScalars` (default `false`).
|
|
1071
1153
|
*
|
|
1072
1154
|
* `requoteScalars` makes `quoteStyle` apply to scalars **already quoted in
|
|
1073
1155
|
* the source** on the format path — by default formatting preserves an
|
|
@@ -1126,7 +1208,22 @@ export declare class YamlModificationError extends YamlModificationError_base {
|
|
|
1126
1208
|
get message(): string;
|
|
1127
1209
|
}
|
|
1128
1210
|
/**
|
|
1129
|
-
*
|
|
1211
|
+
* Formats YAML text and modifies values at a path as byte-minimal edits that
|
|
1212
|
+
* preserve comments and layout elsewhere. Not instantiable.
|
|
1213
|
+
*
|
|
1214
|
+
* @example
|
|
1215
|
+
* ```ts
|
|
1216
|
+
* import { YamlFormat } from "@effected/yaml";
|
|
1217
|
+
* import { Effect } from "effect";
|
|
1218
|
+
*
|
|
1219
|
+
* const formatted = YamlFormat.formatToString("a: 1\nb:\n - x\n - y # c\n");
|
|
1220
|
+
* // => "a: 1\nb:\n- x\n- y # c\n"
|
|
1221
|
+
*
|
|
1222
|
+
* const program = Effect.gen(function* () {
|
|
1223
|
+
* return yield* YamlFormat.modifyToString("port: 3000 # dev\n", ["port"], 8080);
|
|
1224
|
+
* // => "port: 8080 # dev\n"
|
|
1225
|
+
* });
|
|
1226
|
+
* ```
|
|
1130
1227
|
*
|
|
1131
1228
|
* @remarks
|
|
1132
1229
|
* `format`/`formatToString` are pure and total (edit computation never fails
|
|
@@ -1152,8 +1249,8 @@ export declare class YamlModificationError extends YamlModificationError_base {
|
|
|
1152
1249
|
* (`!e!foo`) turns a valid file into one no parser can read. So
|
|
1153
1250
|
* `format`/`formatToString` leave such input byte-identical (no edits), and
|
|
1154
1251
|
* `modify`/`modifyToString` fail typed with a `DirectiveCarryingDocument`
|
|
1155
|
-
* diagnostic. Directive re-emission is unimplemented,
|
|
1156
|
-
*
|
|
1252
|
+
* diagnostic. Directive re-emission is unimplemented, and the refusal is what
|
|
1253
|
+
* stops the corruption.
|
|
1157
1254
|
*
|
|
1158
1255
|
* @public
|
|
1159
1256
|
*/
|
|
@@ -1183,6 +1280,12 @@ export declare class YamlFormat {
|
|
|
1183
1280
|
* directives is left untouched. Detection is directive-token-level: a
|
|
1184
1281
|
* literal `%TAG` inside a scalar is content and formats normally.
|
|
1185
1282
|
*
|
|
1283
|
+
* @param text - The YAML source to format.
|
|
1284
|
+
* @param range - Optional sub-range; only edits fully within it are returned.
|
|
1285
|
+
* @param options - Optional {@link YamlFormattingOptions}.
|
|
1286
|
+
* @returns The edits that bring `text` to canonical shape; apply them with
|
|
1287
|
+
* `YamlEdit.applyAll`. Empty when the input cannot be formatted faithfully.
|
|
1288
|
+
*
|
|
1186
1289
|
* @remarks
|
|
1187
1290
|
* The positional `range` argument takes precedence over
|
|
1188
1291
|
* `options?.range` when both are given; either accepts a plain
|
|
@@ -1214,6 +1317,12 @@ export declare class YamlFormat {
|
|
|
1214
1317
|
* document — single or in a stream — carrying `%YAML`/`%TAG` directives)
|
|
1215
1318
|
* is returned byte-identical — never a truncated first document, never a
|
|
1216
1319
|
* document re-emitted without the directive its tags depend on.
|
|
1320
|
+
*
|
|
1321
|
+
* @param text - The YAML source to format.
|
|
1322
|
+
* @param range - Optional sub-range; only edits fully within it are applied.
|
|
1323
|
+
* @param options - Optional {@link YamlFormattingOptions}.
|
|
1324
|
+
* @returns The formatted text, or `text` unchanged when it cannot be
|
|
1325
|
+
* formatted faithfully.
|
|
1217
1326
|
*/
|
|
1218
1327
|
static formatToString(text: string, range?: YamlRangeLike, options?: YamlFormattingOptions): string;
|
|
1219
1328
|
/**
|
|
@@ -1227,15 +1336,12 @@ export declare class YamlFormat {
|
|
|
1227
1336
|
* sequence and any other non-null object as a block mapping over its own
|
|
1228
1337
|
* enumerable string keys, recursively — the same lowering
|
|
1229
1338
|
* {@link Yaml.stringify} applies to the same value, so `modify` and
|
|
1230
|
-
* `stringify` agree on what a given JavaScript value means.
|
|
1231
|
-
* 0.14.0 only scalars were lowered and a mapping or sequence value was
|
|
1232
|
-
* coerced through `String(value)`, writing the literal text
|
|
1233
|
-
* `[object Object]` into the document — see #642.) For a synthesized
|
|
1339
|
+
* `stringify` agree on what a given JavaScript value means. For a synthesized
|
|
1234
1340
|
* subtree (an object/array value) only the surrounding document is
|
|
1235
1341
|
* preserved byte-for-byte; the subtree carries no comments and takes the
|
|
1236
1342
|
* stringifier's styles.
|
|
1237
1343
|
*
|
|
1238
|
-
* **Scalar replacement is region-confined and quote-preserving
|
|
1344
|
+
* **Scalar replacement is region-confined and quote-preserving.**
|
|
1239
1345
|
* When the path resolves to an existing single-line `plain`,
|
|
1240
1346
|
* `single-quoted`, or `double-quoted` scalar with no tag or anchor, and
|
|
1241
1347
|
* the replacement is a string, number, or boolean, `modify` splices
|
|
@@ -1276,6 +1382,15 @@ export declare class YamlFormat {
|
|
|
1276
1382
|
* directive re-emission is unimplemented, not undesired. A literal
|
|
1277
1383
|
* `%TAG` inside a scalar is content and does not trigger the refusal.
|
|
1278
1384
|
*
|
|
1385
|
+
* @param text - The YAML source to modify.
|
|
1386
|
+
* @param path - The location to insert, replace or remove.
|
|
1387
|
+
* @param value - The JavaScript value to write; `undefined` removes the
|
|
1388
|
+
* target instead.
|
|
1389
|
+
* @param options - Optional {@link YamlStringifyOptions} for the
|
|
1390
|
+
* re-stringify step.
|
|
1391
|
+
* @returns An `Effect` that succeeds with the edits to apply (via
|
|
1392
|
+
* `YamlEdit.applyAll`), or fails with {@link YamlModificationError}.
|
|
1393
|
+
*
|
|
1279
1394
|
* @remarks
|
|
1280
1395
|
* `options` is a bare {@link YamlStringifyOptions} — it controls only the
|
|
1281
1396
|
* internal re-stringify step, not a range (there is no range to restrict
|
|
@@ -1288,6 +1403,15 @@ export declare class YamlFormat {
|
|
|
1288
1403
|
* error channel, including the single-document contract's
|
|
1289
1404
|
* `MultiDocumentStream` refusal and the `DirectiveCarryingDocument`
|
|
1290
1405
|
* refusal of `%YAML`/`%TAG`-carrying documents.
|
|
1406
|
+
*
|
|
1407
|
+
* @param text - The YAML source to modify.
|
|
1408
|
+
* @param path - The location to insert, replace or remove.
|
|
1409
|
+
* @param value - The JavaScript value to write; `undefined` removes the
|
|
1410
|
+
* target instead.
|
|
1411
|
+
* @param options - Optional {@link YamlStringifyOptions} for the
|
|
1412
|
+
* re-stringify step.
|
|
1413
|
+
* @returns An `Effect` that succeeds with the modified text, or fails with
|
|
1414
|
+
* {@link YamlModificationError}.
|
|
1291
1415
|
*/
|
|
1292
1416
|
static readonly modifyToString: (text: string, path: YamlPath, value: unknown, options?: YamlStringifyOptions | undefined) => Effect.Effect<string, YamlModificationError, never>;
|
|
1293
1417
|
}
|
|
@@ -1327,7 +1451,9 @@ declare const YamlToken_base: Schema.Class<YamlToken, Schema.Struct<{
|
|
|
1327
1451
|
*/
|
|
1328
1452
|
export declare class YamlToken extends YamlToken_base {}
|
|
1329
1453
|
/**
|
|
1330
|
-
*
|
|
1454
|
+
* Tokenizes YAML text into positioned tokens, as a complete array or a lazy
|
|
1455
|
+
* `Stream`, for lint- and editor-class consumers. Never fails on malformed
|
|
1456
|
+
* input: lexical errors arrive as `"error"`-kind tokens. Not instantiable.
|
|
1331
1457
|
*
|
|
1332
1458
|
* @public
|
|
1333
1459
|
*/
|
|
@@ -1336,12 +1462,11 @@ export declare class YamlTokens {
|
|
|
1336
1462
|
/**
|
|
1337
1463
|
* Tokenize YAML text into the full positioned token array — the sync
|
|
1338
1464
|
* `Result` primitive (tokenizing is a pure batch transform; the
|
|
1339
|
-
* {@link YamlTokens.stream} form is derived from this one
|
|
1340
|
-
* sync-primitive policy).
|
|
1465
|
+
* {@link YamlTokens.stream} form is derived from this one).
|
|
1341
1466
|
*
|
|
1342
1467
|
* @remarks
|
|
1343
|
-
* The failure channel is **reserved**
|
|
1344
|
-
*
|
|
1468
|
+
* The failure channel is **reserved** for input-hardening guards and never
|
|
1469
|
+
* fires today: the lexer is total, and lexical errors surface as
|
|
1345
1470
|
* `"error"`-kind tokens **in the success array** so that linting can run
|
|
1346
1471
|
* on malformed input — the `parse-validity` lint rule exists precisely for
|
|
1347
1472
|
* documents that do not parse. Do not "fix" this method to fail on
|
|
@@ -1357,6 +1482,9 @@ export declare class YamlTokens {
|
|
|
1357
1482
|
* result.success.map((t) => t.kind); // ["scalar", "block-map-start", ...]
|
|
1358
1483
|
* }
|
|
1359
1484
|
* ```
|
|
1485
|
+
*
|
|
1486
|
+
* @param text - The YAML source to tokenize.
|
|
1487
|
+
* @returns A `Result` succeeding with every token in source order.
|
|
1360
1488
|
*/
|
|
1361
1489
|
static tokenize(text: string): Result.Result<ReadonlyArray<YamlToken>, YamlParseError>;
|
|
1362
1490
|
/**
|
|
@@ -1453,7 +1581,7 @@ declare const StyleVote_base: Schema.Class<StyleVote, Schema.TaggedStruct<"Style
|
|
|
1453
1581
|
readonly character: Schema.Number;
|
|
1454
1582
|
}>, {}>;
|
|
1455
1583
|
/**
|
|
1456
|
-
* One categorical style observation
|
|
1584
|
+
* One categorical style observation: a single occurrence of a style
|
|
1457
1585
|
* choice in the source, voting a `value` for an inference `dimension`.
|
|
1458
1586
|
*
|
|
1459
1587
|
* The `dimension` IS the rule's option key and the `value` IS that option's
|
|
@@ -1478,7 +1606,7 @@ declare const StyleFloor_base: Schema.Class<StyleFloor, Schema.TaggedStruct<"Sty
|
|
|
1478
1606
|
readonly value: Schema.Number;
|
|
1479
1607
|
}>, {}>;
|
|
1480
1608
|
/**
|
|
1481
|
-
* One measured style floor
|
|
1609
|
+
* One measured style floor: a value the source PROVES is at least
|
|
1482
1610
|
* `value`, without proving what the configured limit should be — the longest
|
|
1483
1611
|
* observed line proves `line-length.max` is at least that long, not what it
|
|
1484
1612
|
* is. Floors are carried in the evidence for callers that want them and are
|
|
@@ -1508,7 +1636,7 @@ type StyleObservation = StyleVote | StyleFloor;
|
|
|
1508
1636
|
* rules receive options already validated against their exported options
|
|
1509
1637
|
* schema, custom rules validate their own.
|
|
1510
1638
|
*
|
|
1511
|
-
* `infer` is the optional config-inference hook
|
|
1639
|
+
* `infer` is the optional config-inference hook: it reports the style
|
|
1512
1640
|
* the source already follows as per-occurrence {@link StyleObservation}s, so
|
|
1513
1641
|
* detection logic lives beside the check logic that polices the same
|
|
1514
1642
|
* dimension (and shares its fixtures). Rules with no detectable style — the
|
|
@@ -1560,9 +1688,8 @@ declare const YamlLintConfig_base: Schema.Class<YamlLintConfig, Schema.Struct<{
|
|
|
1560
1688
|
*/
|
|
1561
1689
|
export declare class YamlLintConfig extends YamlLintConfig_base {
|
|
1562
1690
|
/**
|
|
1563
|
-
* The default preset
|
|
1564
|
-
* `quoted-strings` rule defaults to DOUBLE quotes here
|
|
1565
|
-
* call the design pins).
|
|
1691
|
+
* The default preset: the built-in rules at their default settings. The
|
|
1692
|
+
* `quoted-strings` rule defaults to DOUBLE quotes here.
|
|
1566
1693
|
*/
|
|
1567
1694
|
static readonly default: YamlLintConfig;
|
|
1568
1695
|
/** The relaxed preset: style rules demoted to warnings. */
|
|
@@ -1606,7 +1733,7 @@ declare const StyleEvidence_base: Schema.Class<StyleEvidence, Schema.Struct<{
|
|
|
1606
1733
|
readonly floors: Schema.$Array<typeof StyleFloorTally>;
|
|
1607
1734
|
}>, {}>;
|
|
1608
1735
|
/**
|
|
1609
|
-
* Per-dimension style evidence
|
|
1736
|
+
* Per-dimension style evidence: what the observed sources say about
|
|
1610
1737
|
* each inferable `(rule, dimension)` — vote histograms with first-seen
|
|
1611
1738
|
* positions, and measured floors.
|
|
1612
1739
|
*
|
|
@@ -1664,6 +1791,11 @@ declare const YamlStyleConflictError_base: Schema.Class<YamlStyleConflictError,
|
|
|
1664
1791
|
* rule). Unobserved dimensions never conflict: they fall back to the base
|
|
1665
1792
|
* config's defaults.
|
|
1666
1793
|
*
|
|
1794
|
+
* @remarks
|
|
1795
|
+
* The `message` renders each candidate's first-seen position 1-based
|
|
1796
|
+
* (`line + 1:character + 1`) for human readers; the structured
|
|
1797
|
+
* {@link StyleVoteTally} `line`/`character` fields stay 0-based.
|
|
1798
|
+
*
|
|
1667
1799
|
* @public
|
|
1668
1800
|
*/
|
|
1669
1801
|
export declare class YamlStyleConflictError extends YamlStyleConflictError_base {
|
|
@@ -1681,7 +1813,25 @@ interface YamlLintInference {
|
|
|
1681
1813
|
readonly residual: ReadonlyArray<YamlLintDiagnostic>;
|
|
1682
1814
|
}
|
|
1683
1815
|
/**
|
|
1684
|
-
*
|
|
1816
|
+
* Lints YAML text against a rule set, applies the rules' non-overlapping
|
|
1817
|
+
* fixes, and infers a lint config from the style a corpus already follows.
|
|
1818
|
+
* Not instantiable.
|
|
1819
|
+
*
|
|
1820
|
+
* @example
|
|
1821
|
+
* ```ts
|
|
1822
|
+
* import { YamlLint, YamlLintConfig } from "@effected/yaml";
|
|
1823
|
+
* import { Result } from "effect";
|
|
1824
|
+
*
|
|
1825
|
+
* const text = "a: 1\nb: 2 \n";
|
|
1826
|
+
*
|
|
1827
|
+
* const diagnostics = YamlLint.run(text, YamlLint.builtins, YamlLintConfig.default);
|
|
1828
|
+
* // => a colon-spacing finding on line 0 and a trailing-spaces finding on line 1 (zero-based)
|
|
1829
|
+
*
|
|
1830
|
+
* const fixed = YamlLint.fix(text, YamlLint.builtins, YamlLintConfig.default);
|
|
1831
|
+
* if (Result.isSuccess(fixed)) {
|
|
1832
|
+
* fixed.success; // "a: 1\nb: 2\n"
|
|
1833
|
+
* }
|
|
1834
|
+
* ```
|
|
1685
1835
|
*
|
|
1686
1836
|
* @remarks
|
|
1687
1837
|
* Pure and synchronous throughout — the lint engine is the pure half only:
|
|
@@ -1712,6 +1862,12 @@ export declare class YamlLint {
|
|
|
1712
1862
|
* literal, else `"error"`) overrides what the rule emitted, again except
|
|
1713
1863
|
* for `parse-validity`, whose bridged engine diagnostics keep the
|
|
1714
1864
|
* engine's own grading.
|
|
1865
|
+
*
|
|
1866
|
+
* @param text - The YAML source to lint.
|
|
1867
|
+
* @param rules - The rules to run, e.g. {@link YamlLint.builtins}.
|
|
1868
|
+
* @param config - The {@link YamlLintConfig} choosing each rule's severity
|
|
1869
|
+
* and options.
|
|
1870
|
+
* @returns Every finding, sorted by position.
|
|
1715
1871
|
*/
|
|
1716
1872
|
static run(text: string, rules: ReadonlyArray<YamlRule>, config: YamlLintConfig): ReadonlyArray<YamlLintDiagnostic>;
|
|
1717
1873
|
/**
|
|
@@ -1726,10 +1882,17 @@ export declare class YamlLint {
|
|
|
1726
1882
|
* fixes overlap — or start at the same offset — the earlier one in
|
|
1727
1883
|
* {@link YamlLint.run} order (position, then rule id) wins and the later
|
|
1728
1884
|
* is dropped (its diagnostic remains reported by {@link YamlLint.run}).
|
|
1885
|
+
*
|
|
1886
|
+
* @param text - The YAML source to fix.
|
|
1887
|
+
* @param rules - The rules to run, e.g. {@link YamlLint.builtins}.
|
|
1888
|
+
* @param config - The {@link YamlLintConfig} choosing each rule's severity
|
|
1889
|
+
* and options.
|
|
1890
|
+
* @returns A `Result` succeeding with the fixed text, or failing with
|
|
1891
|
+
* {@link YamlParseError}.
|
|
1729
1892
|
*/
|
|
1730
1893
|
static fix(text: string, rules: ReadonlyArray<YamlRule>, config: YamlLintConfig): Result.Result<string, YamlParseError>;
|
|
1731
1894
|
/**
|
|
1732
|
-
* Observe the style `text` already follows
|
|
1895
|
+
* Observe the style `text` already follows: run every rule's
|
|
1733
1896
|
* optional `infer` hook over one eagerly-built context and merge the
|
|
1734
1897
|
* observations into canonical {@link StyleEvidence}. Pure and total —
|
|
1735
1898
|
* strings in, evidence out; observing N files is N `observe` calls merged
|
|
@@ -2356,7 +2519,23 @@ export declare const YamlVisitorEvent: {
|
|
|
2356
2519
|
}, "_tag">;
|
|
2357
2520
|
};
|
|
2358
2521
|
/**
|
|
2359
|
-
*
|
|
2522
|
+
* Walks YAML text as a lazy `Stream` of typed events — documents, collections,
|
|
2523
|
+
* pairs, scalars, aliases, comments, directives and recovered errors — in
|
|
2524
|
+
* document order. Not instantiable.
|
|
2525
|
+
*
|
|
2526
|
+
* @example
|
|
2527
|
+
* ```ts
|
|
2528
|
+
* import { YamlVisitor, YamlVisitorEvent } from "@effected/yaml";
|
|
2529
|
+
* import { Effect, Stream } from "effect";
|
|
2530
|
+
*
|
|
2531
|
+
* // Mapping keys are scalar events too, so keys and values interleave.
|
|
2532
|
+
* const scalars = YamlVisitor.visit("a: 1\nb:\n - x\n").pipe(
|
|
2533
|
+
* Stream.filter(YamlVisitorEvent.$is("Scalar")),
|
|
2534
|
+
* Stream.map((event) => event.value),
|
|
2535
|
+
* Stream.runCollect,
|
|
2536
|
+
* );
|
|
2537
|
+
* // Effect.runSync(scalars) // => ["a", 1, "b", "x"]
|
|
2538
|
+
* ```
|
|
2360
2539
|
*
|
|
2361
2540
|
* @public
|
|
2362
2541
|
*/
|
|
@@ -2374,6 +2553,11 @@ export declare class YamlVisitor {
|
|
|
2374
2553
|
* (fatal or not, including an exceeded `maxAliasCount`, recorded as
|
|
2375
2554
|
* `AliasCountExceeded`) surface as `Error` events inside the stream rather
|
|
2376
2555
|
* than failing it.
|
|
2556
|
+
*
|
|
2557
|
+
* @param text - The YAML source to visit.
|
|
2558
|
+
* @param options - Optional {@link YamlParseOptions} controlling composition.
|
|
2559
|
+
* @returns A lazy `Stream` of `YamlVisitorEvent`, infallible at the type
|
|
2560
|
+
* level.
|
|
2377
2561
|
*/
|
|
2378
2562
|
static visit(text: string, options?: YamlParseOptions): Stream.Stream<YamlVisitorEvent>;
|
|
2379
2563
|
}
|
|
@@ -66,8 +66,7 @@ function composeBlockMapInner(blockMapCst, state, externalFirstKey, meta) {
|
|
|
66
66
|
* scope re-attributes it (see `EscapedComment` in `comments.ts`: "it belongs to
|
|
67
67
|
* an outer scope"). The span was the one place that disagreed, reporting an
|
|
68
68
|
* `offset`/`length` whose end lay past a comment the node does not own — so a
|
|
69
|
-
* caller splicing text at the end of the collection inserted AFTER the comment
|
|
70
|
-
* (#642's sibling, #643).
|
|
69
|
+
* caller splicing text at the end of the collection inserted AFTER the comment.
|
|
71
70
|
*
|
|
72
71
|
* The disowned set is the input rather than a re-derived column test, so the
|
|
73
72
|
* span and the comment model cannot drift apart: whatever the partition threw
|
|
@@ -534,7 +533,7 @@ function flattenBlockMapChildren(children, state, externalKeyColumn, externalKey
|
|
|
534
533
|
* Pattern: node, value-sep (no node) produces a key:null pair.
|
|
535
534
|
* Pattern: value-sep, node produces a null:value pair.
|
|
536
535
|
*
|
|
537
|
-
* Comment attribution
|
|
536
|
+
* Comment attribution: a comment on the same line as the end of the
|
|
538
537
|
* previous pair attaches to it as the trailing `comment`; an own-line
|
|
539
538
|
* comment attaches FORWARD to the next pair as `commentBefore` (consecutive
|
|
540
539
|
* lines join with `\n`); a blank line before a pair (or before its
|
|
@@ -152,7 +152,7 @@ function joinComments(a, b) {
|
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
154
154
|
* Zero-based column of `offset` within its line. A byte-order mark at the
|
|
155
|
-
* line start occupies no column — the lexer's convention
|
|
155
|
+
* line start occupies no column — the lexer's convention — so a
|
|
156
156
|
* BOM-prefixed root mapping's content column is `0`, not `1`, and its
|
|
157
157
|
* terminal own-line comment is not mistaken for one escaping a nested map.
|
|
158
158
|
*/
|
|
@@ -678,9 +678,9 @@ const EMPTY_DOCUMENT = {
|
|
|
678
678
|
hasDocumentStartTab: false
|
|
679
679
|
};
|
|
680
680
|
/**
|
|
681
|
-
* Compose the first document of `text` with full error recovery
|
|
682
|
-
*
|
|
683
|
-
*
|
|
681
|
+
* Compose the first document of `text` with full error recovery, with no
|
|
682
|
+
* fatal-code filtering (the facade applies `isFatalCode` to the returned
|
|
683
|
+
* diagnostics).
|
|
684
684
|
* Cross-document directive-placement errors are validated into the same
|
|
685
685
|
* state and therefore appear in the returned document's `errors`.
|
|
686
686
|
*/
|
|
@@ -710,12 +710,10 @@ function composeFirstDocumentCounted(text, options) {
|
|
|
710
710
|
};
|
|
711
711
|
}
|
|
712
712
|
/**
|
|
713
|
-
* Compose every document of `text` with full error recovery
|
|
714
|
-
* `parseAllDocuments` semantics minus the Effect wrapper and minus
|
|
713
|
+
* Compose every document of `text` with full error recovery, with no
|
|
715
714
|
* fatal-code filtering. Each document is composed with a fresh state; the
|
|
716
715
|
* cross-document directive validation runs in its own state whose errors
|
|
717
|
-
* are returned unfiltered as `streamErrors` (
|
|
718
|
-
* `InvalidDirective` before failing — the facade applies that filter).
|
|
716
|
+
* are returned unfiltered as `streamErrors` (the facade applies its filter).
|
|
719
717
|
*/
|
|
720
718
|
function composeAllDocuments(text, options) {
|
|
721
719
|
const cstNodes = parseCSTAll(text);
|
|
@@ -123,7 +123,7 @@ function getBlockIndent(node) {
|
|
|
123
123
|
* a `#` comment — body lines absorb `#` as content — and the lexer packs the
|
|
124
124
|
* whole scalar (header comment included) into one CST token, so the comment
|
|
125
125
|
* never surfaces as a sibling comment token for the ordinary attribution
|
|
126
|
-
* pass
|
|
126
|
+
* pass.
|
|
127
127
|
*/
|
|
128
128
|
function blockScalarHeaderComment(cst) {
|
|
129
129
|
const src = cst.source.trimStart();
|
|
@@ -11,7 +11,7 @@ function getLineStarts(text) {
|
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Zero-based line and column of `offset`. A byte-order mark at the line start
|
|
14
|
-
* occupies no column, matching the lexer and `columnAt
|
|
14
|
+
* occupies no column, matching the lexer and `columnAt`, so a
|
|
15
15
|
* diagnostic's `character` behind a BOM equals the BOM-less document's.
|
|
16
16
|
*/
|
|
17
17
|
function lineCol(text, offset) {
|
package/internal/diagnostics.js
CHANGED
|
@@ -72,9 +72,8 @@ const YAML_MODIFY_ERROR_CODES = [
|
|
|
72
72
|
];
|
|
73
73
|
/**
|
|
74
74
|
* The single source of truth for which diagnostic codes are fatal to a
|
|
75
|
-
* parse (vs. recoverable warnings-as-data)
|
|
76
|
-
*
|
|
77
|
-
* property of the code, declared once.
|
|
75
|
+
* parse (vs. recoverable warnings-as-data): fatality is a property of the
|
|
76
|
+
* code, declared once.
|
|
78
77
|
*/
|
|
79
78
|
const FATAL_CODES = /* @__PURE__ */ new Set([
|
|
80
79
|
"UndefinedAlias",
|
|
@@ -17,7 +17,7 @@ const quotedStringsOptions = Schema.Struct({
|
|
|
17
17
|
});
|
|
18
18
|
/**
|
|
19
19
|
* A value-preserving requote/wrap edit, or undefined when none is safe.
|
|
20
|
-
* Delegates to the shared helper's CONSERVATIVE mode
|
|
20
|
+
* Delegates to the shared helper's CONSERVATIVE mode — the shipped
|
|
21
21
|
* fix behavior stays exactly as released; the escaping-capable mode belongs
|
|
22
22
|
* to the format path's opt-in `requoteScalars`, not the lint fix.
|
|
23
23
|
*/
|
package/internal/stringifier.js
CHANGED
|
@@ -138,7 +138,7 @@ function wouldBeResolved11(s) {
|
|
|
138
138
|
* `,[]{}` are plain-unsafe anywhere in the scalar (YAML 1.2 §7.3.3,
|
|
139
139
|
* `ns-plain-safe(flow-in)` excludes `c-flow-indicator`), where block context
|
|
140
140
|
* lets them through. Without it a plain `p, q` rendered into `[x, y]` reads
|
|
141
|
-
* back as three items
|
|
141
|
+
* back as three items.
|
|
142
142
|
*/
|
|
143
143
|
function requiresQuoting(s, ignoreType = false, quoteCompat, inFlow = false) {
|
|
144
144
|
if (s === "") return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effected/yaml",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Zero-dependency YAML parsing, editing, formatting and linting as Effect schemas.",
|
|
6
6
|
"keywords": [
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"./package.json": "./package.json"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"effect": "4.0.0
|
|
44
|
+
"effect": "^4.0.0"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=24.11.0"
|