@effected/changesets 0.2.0 → 0.3.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/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { BumpType, ReleaseType } from "./BumpType.js";
2
+ import { Changelog, ChangelogError, ComprehensiveRelease, ModCompWithPackage, NewChangeset, NewChangesetWithCommit, PackageJSON, VersionType } from "./Changelog.js";
2
3
  import { ChangesetConfig } from "./ChangesetConfig.js";
3
4
  import { ChangesetFile, ParsedChangeset } from "./ChangesetFile.js";
4
- import { ChangesetConfigError, ChangesetParseError, UnknownPackageError } from "./errors.js";
5
+ import { ChangesetConfigError, ChangesetParseError, MissingPackageError, SnapshotPreModeError, SnapshotTemplateError, UnknownPackageError } from "./errors.js";
5
6
  import { PendingChangeset, PendingChangesets } from "./PendingChangesets.js";
6
7
  import { PreState } from "./PreState.js";
7
- import { PlannedRelease, ReleasePlan } from "./ReleasePlan.js";
8
+ import { ChangesetMove, ManifestEdit, RangeEdit, ReleaseEdits } from "./ReleaseEdits.js";
9
+ import { PlannedRelease, ReleaseContext, ReleasePlan } from "./ReleasePlan.js";
8
10
 
9
- export { BumpType, ChangesetConfig, ChangesetConfigError, ChangesetFile, ChangesetParseError, ParsedChangeset, PendingChangeset, PendingChangesets, PlannedRelease, PreState, ReleasePlan, ReleaseType, UnknownPackageError };
11
+ export { BumpType, Changelog, ChangelogError, ChangesetConfig, ChangesetConfigError, ChangesetFile, ChangesetMove, ChangesetParseError, ComprehensiveRelease, ManifestEdit, MissingPackageError, ModCompWithPackage, NewChangeset, NewChangesetWithCommit, PackageJSON, ParsedChangeset, PendingChangeset, PendingChangesets, PlannedRelease, PreState, RangeEdit, ReleaseContext, ReleaseEdits, ReleasePlan, ReleaseType, SnapshotPreModeError, SnapshotTemplateError, UnknownPackageError, VersionType };
@@ -0,0 +1,57 @@
1
+ import { Predicate } from "effect";
2
+
3
+ // src/internal/causeMessage.ts
4
+ /** How many nodes of a cause chain the walk reads before stopping, so a cyclic chain cannot spin. */
5
+ const CAUSE_DEPTH = 8;
6
+ /**
7
+ * The message a single node carries: a thrown string, or a non-empty string `message` property. A getter or
8
+ * proxy trap that throws is a node with no message.
9
+ */
10
+ const messageAt = (node) => {
11
+ try {
12
+ const text = Predicate.isString(node) ? node : Predicate.hasProperty(node, "message") && Predicate.isString(node.message) ? node.message : void 0;
13
+ return text === void 0 || text.trim() === "" ? void 0 : text;
14
+ } catch {
15
+ return;
16
+ }
17
+ };
18
+ /** The next link of the chain: a node's `cause`, or `undefined` when it has none or reading it throws. */
19
+ const causeAt = (node) => {
20
+ try {
21
+ return Predicate.hasProperty(node, "cause") ? node.cause : void 0;
22
+ } catch {
23
+ return;
24
+ }
25
+ };
26
+ /**
27
+ * Every distinct non-empty message a preserved cause chain carries, nearest
28
+ * first and joined with `: `, or `undefined` when nothing along it has one.
29
+ *
30
+ * A `Schema.Defect()` field holds whatever was thrown, so the read is guarded
31
+ * rather than assumed: `Predicate.hasProperty` + `Predicate.isString` accepts
32
+ * an `Error`, a cross-realm `Error` that fails `instanceof`, a plain
33
+ * `{ message }` object and a thrown string alike. An empty or whitespace-only
34
+ * message counts as none. The walk follows `cause` links because a wrapper's
35
+ * text is often the generic summary and the driver's text underneath is the
36
+ * actionable detail, yet a wrapper that composes its own context must not
37
+ * lose it either; so nothing is dropped, and a deeper text the nearer one
38
+ * already contains is not repeated. The walk is bounded, so a cycle terminates.
39
+ *
40
+ * It never throws: every property read is guarded, so a `message` getter that throws leaves that link
41
+ * without text, and a `cause` getter that throws ends the walk with what was found so far.
42
+ */
43
+ const causeMessage = (cause) => {
44
+ let message;
45
+ let node = cause;
46
+ for (let depth = 0; depth < CAUSE_DEPTH && node !== void 0 && node !== null; depth++) {
47
+ const text = messageAt(node);
48
+ if (text !== void 0) {
49
+ if (message === void 0 || text.includes(message)) message = text;
50
+ else if (!message.includes(text)) message = `${message}: ${text}`;
51
+ }
52
+ node = causeAt(node);
53
+ }
54
+ return message;
55
+ };
56
+
57
+ export { causeMessage };
@@ -0,0 +1,83 @@
1
+ import { Result } from "effect";
2
+ import { Yaml } from "@effected/yaml";
3
+
4
+ // src/internal/frontMatter.ts
5
+ /**
6
+ * `@changesets/parse`'s `mdRegex`, with its `[^]` written `[\s\S]` (the same
7
+ * class): leading whitespace allowed, not anchored to the start.
8
+ */
9
+ const FENCES = /\s*---([\s\S]*?)\r?\n\s*---(\s*(?:\n|$)[\s\S]*)/;
10
+ const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
11
+ /** Where `name`'s key sits in the block: the first line that starts with it, quoted or not. */
12
+ const keySpan = (source, blockStart, block, name) => {
13
+ const found = new RegExp(`^[ \\t]*(["']?)${escapeRegExp(name)}\\1[ \\t]*:`, "m").exec(block);
14
+ if (found === null) return {
15
+ offset: blockStart,
16
+ length: 0
17
+ };
18
+ const lineStart = blockStart + found.index;
19
+ const lineEnd = source.indexOf("\n", lineStart);
20
+ return {
21
+ offset: lineStart,
22
+ length: (lineEnd === -1 ? source.length : lineEnd) - lineStart
23
+ };
24
+ };
25
+ /**
26
+ * Read a changeset's front matter with `@changesets/parse`'s rules: the
27
+ * trimmed text must be non-empty, its fences must match, the block must be
28
+ * YAML, and a truthy value must be a mapping. A falsy value, such as the
29
+ * empty block `changeset add --empty` writes, has no entries.
30
+ */
31
+ const readFrontMatter = (source) => {
32
+ const whole = {
33
+ offset: 0,
34
+ length: 0
35
+ };
36
+ if (source.trim() === "") return {
37
+ ok: false,
38
+ problem: "empty",
39
+ detail: "The file is empty.",
40
+ at: whole
41
+ };
42
+ const match = FENCES.exec(source);
43
+ if (match === null) return {
44
+ ok: false,
45
+ problem: "missing",
46
+ detail: "No front matter: a changeset starts with a block between two \"---\" lines.",
47
+ at: whole
48
+ };
49
+ const block = match[1] ?? "";
50
+ const blockStart = match.index + match[0].indexOf("---") + 3;
51
+ const fenceSpan = {
52
+ offset: match.index + match[0].indexOf("---"),
53
+ length: 3
54
+ };
55
+ const parsed = Yaml.parseResult(block);
56
+ if (Result.isFailure(parsed)) return {
57
+ ok: false,
58
+ problem: "yaml",
59
+ detail: `The front matter is not valid YAML: ${parsed.failure.message}`,
60
+ at: fenceSpan
61
+ };
62
+ const value = parsed.success;
63
+ if (!value) return {
64
+ ok: true,
65
+ entries: []
66
+ };
67
+ if (typeof value !== "object" || Array.isArray(value)) return {
68
+ ok: false,
69
+ problem: "shape",
70
+ detail: "The front matter must be a mapping of package names to release types.",
71
+ at: fenceSpan
72
+ };
73
+ return {
74
+ ok: true,
75
+ entries: Object.entries(value).map(([name, type]) => ({
76
+ name,
77
+ type,
78
+ at: keySpan(source, blockStart, block, name)
79
+ }))
80
+ };
81
+ };
82
+
83
+ export { readFrontMatter };
@@ -0,0 +1,103 @@
1
+ import { Result } from "effect";
2
+ import { posix } from "node:path";
3
+ import { GlobPattern } from "@effected/glob";
4
+ import { Range, SemVer } from "@effected/semver";
5
+
6
+ // src/internal/versions.ts
7
+ /**
8
+ * Version and range helpers the planner and the release edits share, each
9
+ * reading a version or range as node-semver does.
10
+ *
11
+ * @internal
12
+ */
13
+ const DEPENDENCY_KINDS = [
14
+ "dependencies",
15
+ "devDependencies",
16
+ "peerDependencies",
17
+ "optionalDependencies"
18
+ ];
19
+ /**
20
+ * A package version as node-semver reads one without `loose`: surrounding
21
+ * whitespace and a single leading `v` are dropped, so `v1.0.0` is `1.0.0`. Any
22
+ * other prefix, `=1.2.0` among them, stays and fails to parse.
23
+ */
24
+ const cleanVersion = (version) => {
25
+ const trimmed = version.trim();
26
+ return trimmed.startsWith("v") ? trimmed.slice(1) : trimmed;
27
+ };
28
+ const WORKSPACE = /^workspace:/;
29
+ /** node-semver reads a `v` before a version in a range: `^v1.0.0` is `^1.0.0`. */
30
+ const withoutV = (specifier) => specifier.replace(/(^|[\s^~<>=])v(?=\d)/g, "$1");
31
+ /** A range, also as node-semver reads a `v` before a version in one. */
32
+ const parseRange = (specifier) => {
33
+ if (specifier.includes(":")) return void 0;
34
+ const parsed = Range.parseResult(specifier);
35
+ if (Result.isSuccess(parsed)) return parsed.success;
36
+ return Result.getOrUndefined(Range.parseResult(withoutV(specifier)));
37
+ };
38
+ /** A range's comparator sets as node-semver's `Range#set` holds them, the same `v` read as {@link parseRange}. */
39
+ const writtenSets = (specifier) => {
40
+ if (specifier.includes(":")) return void 0;
41
+ const parsed = Range.writtenSetsResult(specifier);
42
+ if (Result.isSuccess(parsed)) return parsed.success;
43
+ return Result.getOrUndefined(Range.writtenSetsResult(withoutV(specifier)));
44
+ };
45
+ const satisfies = (version, specifier) => {
46
+ const range = parseRange(specifier);
47
+ const parsed = Result.getOrUndefined(SemVer.parseResult(cleanVersion(version)));
48
+ return range !== void 0 && parsed !== void 0 && Range.satisfies(parsed, range);
49
+ };
50
+ /**
51
+ * `semver.inc`'s rule, which `SemVerBump` deliberately does not follow: a bump
52
+ * a prerelease is already heading for completes it rather than incrementing.
53
+ */
54
+ const increment = (version, type) => {
55
+ return version.prerelease.length > 0 && (type === "patch" || version.patch === 0 && (type === "minor" || version.minor === 0)) ? SemVer.truncate(version, "prerelease") : version.bump[type]();
56
+ };
57
+ /** The workspace's names a list of globs selects, `!` negation applying in order, in workspace order. */
58
+ const matchNames = (packages, patterns) => {
59
+ const matchers = patterns.map((source) => {
60
+ const negated = source.startsWith("!");
61
+ const glob = negated ? source.slice(1) : source;
62
+ const compiled = Result.getOrUndefined(GlobPattern.compileResult(glob));
63
+ return {
64
+ negated,
65
+ matches: (name) => compiled?.matches(name) ?? name === glob
66
+ };
67
+ });
68
+ const selected = [];
69
+ for (const { name } of packages) {
70
+ let passed = false;
71
+ for (const { negated, matches } of matchers) if (!passed && !negated && matches(name)) passed = true;
72
+ else if (passed && negated && matches(name)) passed = false;
73
+ if (passed) selected.push(name);
74
+ }
75
+ return selected;
76
+ };
77
+ const BUMP_LEVEL = {
78
+ none: 0,
79
+ patch: 1,
80
+ minor: 2,
81
+ major: 3
82
+ };
83
+ /**
84
+ * `apply-release-plan`'s `shouldUpdateDependencyBasedOnConfig`: whether a
85
+ * dependent's specifier on `release` is one `changeset version` updates. A
86
+ * `workspace:` path answers whether it points at the dependency
87
+ * (`dependencyPath`, relative to the workspace root); the edits never rewrite
88
+ * one whatever the answer, but the changelog's dependency lines read it.
89
+ */
90
+ const shouldUpdate = (release, specifier, kind, options, dependencyPath) => {
91
+ let range = specifier;
92
+ if (WORKSPACE.test(range)) {
93
+ range = range.replace(WORKSPACE, "");
94
+ if (range === "*") return true;
95
+ if (range === "^" || range === "~") range = `${range}${release.oldVersion}`;
96
+ else if (parseRange(range) === void 0) return posix.normalize(range) === dependencyPath;
97
+ }
98
+ if (!satisfies(release.newVersion, range)) return true;
99
+ if (kind === "peerDependencies") return !options.onlyPeersOutOfRange;
100
+ return BUMP_LEVEL[release.type] >= BUMP_LEVEL[options.minimum];
101
+ };
102
+
103
+ export { DEPENDENCY_KINDS, WORKSPACE, cleanVersion, increment, matchNames, parseRange, satisfies, shouldUpdate, writtenSets };
package/lint.d.ts CHANGED
@@ -1,55 +1,59 @@
1
1
  import { LintDiagnostic, LintRule, MarkdownLintOptions } from "@effected/markdown-lint";
2
2
  /**
3
- * The changeset style rules CSH001 to CSH005, each defined once as a
4
- * `LintRule` over `@effected/markdown` trees, so one definition runs in
5
- * `MarkdownLint` and, through `MarkdownlintAdapter`, in markdownlint and
6
- * markdownlint-cli2.
3
+ * Options for {@link ChangesetLint.lint}: `MarkdownLint`'s parse options,
4
+ * plus the rules to run.
7
5
  *
8
- * @remarks
9
- * The rules check a changeset's body, whatever its front matter says:
6
+ * @public
7
+ */
8
+ interface ChangesetLintOptions extends MarkdownLintOptions {
9
+ /**
10
+ * The workspace's package names. When given, the
11
+ * {@link ChangesetLint.knownPackages} rule runs over them; without them,
12
+ * a name is never checked against the workspace.
13
+ */
14
+ readonly packages?: Iterable<string> | undefined;
15
+ /** Rules run after the defaults: a house style's own, for example. */
16
+ readonly rules?: ReadonlyArray<LintRule> | undefined;
17
+ /**
18
+ * The default set to run, replacing {@link ChangesetLint.defaults}; pass
19
+ * `[]` to run only `rules`.
20
+ */
21
+ readonly defaults?: ReadonlyArray<LintRule> | undefined;
22
+ }
23
+ /**
24
+ * Lint rules for changeset files that hold under any house style: only what
25
+ * the changesets tool itself refuses a file for, as `@changesets/parse`
26
+ * reads one, plus, when the workspace's names are given, that each named
27
+ * package exists.
10
28
  *
11
- * - `CSH001` `changeset-heading-hierarchy`: no `h1`, and no heading that
12
- * skips a level.
13
- * - `CSH002` `changeset-required-sections`: every `h2` names one of the
14
- * thirteen categories (`Breaking Changes`, `Features`, `Bug Fixes`,
15
- * `Performance`, `Documentation`, `Refactoring`, `Tests`, `Build System`,
16
- * `CI`, `Dependencies`, `Maintenance`, `Reverts`, `Other`), ignoring case.
17
- * - `CSH003` `changeset-content-structure`: no empty section, no code fence
18
- * without a language, no empty list item.
19
- * - `CSH004` `changeset-uncategorized-content`: no content before the first
20
- * `h2`.
21
- * - `CSH005` `changeset-dependency-table-format`: a `Dependencies` section
22
- * holds a `Dependency | Type | Action | From | To` table whose cells are
23
- * valid.
29
+ * @remarks
30
+ * Each rule is an `@effected/markdown-lint` `LintRule`, so one definition
31
+ * runs in `MarkdownLint` and, through `MarkdownlintAdapter`, in markdownlint
32
+ * and markdownlint-cli2. A house style (section headings, summary layout)
33
+ * is not here: pass its rules as `rules`, or beside these to
34
+ * `MarkdownlintAdapter.rules`.
24
35
  *
25
- * Messages, lines and columns are savvy-web/systems' own, which wrote the
26
- * rules. systems implements each rule twice, and where its two engines
27
- * disagree these follow its markdownlint engine, the one markdownlint-cli2
28
- * and a pre-commit hook run. That engine reads micromark tokens, so:
36
+ * The rules, named in their own scheme: `CF` for changeset front matter.
29
37
  *
30
- * - Only top-level blocks are sections: a heading, list or code block
31
- * inside a list item or a block quote is not checked by CSH001, CSH002 or
32
- * CSH003.
33
- * - A heading or table cell is compared as written, with backslash escapes
34
- * resolved and inline formatting kept: a heading of `Features` in a code
35
- * span and `## *Bug Fixes*` are unknown sections, and a `From` cell of
36
- * `1.0.0` in a code span is not a version. That verdict looks stricter than an author
37
- * expects, but it is what markdownlint enforces.
38
- * - CSH003 checks fenced code only, since an indented block has no fence to
39
- * name a language on, and calls a list item empty unless it holds a
40
- * paragraph: an item of only an HTML comment, a nested list or a heading is
41
- * empty, and an item of only an image is not.
42
- * - A table row shorter than the header has too few columns. The parsed tree
43
- * pads it with empty cells, which are not counted.
44
- * - A setext heading directly under a link reference definition is
45
- * reported on the definition's line, where micromark starts its token.
46
- * - A heading over several lines is named on one line, as markdownlint
47
- * writes every detail.
38
+ * - `CF001` `changeset-front-matter`: the file is not empty, has a front
39
+ * matter block between `---` lines, the block is YAML, and a non-empty
40
+ * value is a mapping. The block is found with `@changesets/parse`'s own
41
+ * pattern, which allows leading whitespace and does not require the block
42
+ * at the start of the file.
43
+ * - `CF002` `changeset-package-name`: every key is a package name, which
44
+ * `@changesets/parse` checks only as not blank, and neither does this: an
45
+ * npm-name check would refuse files changesets accepts.
46
+ * - `CF003` `changeset-release-type`: every value is `major`, `minor`,
47
+ * `patch` or `none`.
48
+ * - `CF004` `changeset-known-package`, from
49
+ * {@link ChangesetLint.knownPackages}: every key names a package of the
50
+ * workspace. It runs only when the names are given.
48
51
  *
49
- * One difference remains, and it is the parser's, not a rule's: after an
50
- * indented code block, markdownlint's micromark reads a bare `- ` line as a
51
- * paragraph, where CommonMark reads an empty list item, so CSH003 reports an
52
- * empty item there and markdownlint does not.
52
+ * An empty front matter and an empty summary are both legal: they are what
53
+ * `changeset add --empty` writes. `CF002` to `CF004` read only a front
54
+ * matter `CF001` accepts, so a broken block is reported once.
55
+ * `__test__/ChangesetLint.test.ts` holds the defaults to `@changesets/parse`:
56
+ * a file it parses fails none of them, and a file it refuses fails one.
53
57
  *
54
58
  * @example
55
59
  * ```ts
@@ -57,36 +61,38 @@ import { LintDiagnostic, LintRule, MarkdownLintOptions } from "@effected/markdow
57
61
  * import { ChangesetLint } from "@effected/changesets/lint";
58
62
  *
59
63
  * // .markdownlint-cli2.mjs
60
- * export default { customRules: MarkdownlintAdapter.rules(ChangesetLint.rules) };
64
+ * export default { customRules: MarkdownlintAdapter.rules(ChangesetLint.defaults) };
61
65
  * ```
62
66
  *
63
67
  * @public
64
68
  */
65
69
  export declare class ChangesetLint {
66
- /** CSH001: headings start at `h2` and never skip a level. */
67
- static readonly headingHierarchy: LintRule;
68
- /** CSH002: every `h2` names a changeset category. */
69
- static readonly requiredSections: LintRule;
70
- /** CSH003: sections have content, fences a language, list items text. */
71
- static readonly contentStructure: LintRule;
72
- /** CSH004: nothing comes before the first category heading. */
73
- static readonly uncategorizedContent: LintRule;
74
- /** CSH005: a `Dependencies` section holds a valid dependency table. */
75
- static readonly dependencyTableFormat: LintRule;
70
+ /** `CF001`: a front matter block of YAML, a mapping when not empty. */
71
+ static readonly frontMatter: LintRule;
72
+ /** `CF002`: every key names a package. */
73
+ static readonly packageName: LintRule;
74
+ /** `CF003`: every value is a release type. */
75
+ static readonly releaseType: LintRule;
76
+ /** The default rules, `CF001` to `CF003`, in that order. */
77
+ static readonly defaults: ReadonlyArray<LintRule>;
76
78
  /**
77
- * The five rules in the order savvy-web/systems' linter runs them, CSH005
78
- * before CSH004, which is the order `MarkdownLint` reports their findings
79
- * in.
79
+ * `CF004` `changeset-known-package`: every front matter key names one of
80
+ * `packages`, the workspace's package names.
81
+ *
82
+ * @param packages - The workspace's package names.
80
83
  */
81
- static readonly rules: ReadonlyArray<LintRule>;
84
+ static knownPackages(packages: Iterable<string>): LintRule;
82
85
  /**
83
- * Lint one changeset file's text with all five rules: `MarkdownLint.lint`
84
- * over {@link ChangesetLint.rules}. Line numbers count the whole file, front
85
- * matter included.
86
+ * Lint one changeset file's text: `MarkdownLint.lint` over
87
+ * {@link ChangesetLint.defaults} (or `options.defaults`), then
88
+ * {@link ChangesetLint.knownPackages} when `options.packages` is given,
89
+ * then `options.rules`. Line numbers count the whole file, front matter
90
+ * included.
86
91
  *
87
92
  * @param source - The changeset file's text.
88
- * @param options - Parse options, passed to `MarkdownLint.lint`.
93
+ * @param options - The rules and the parse options.
89
94
  */
90
- static lint(source: string, options?: MarkdownLintOptions): ReadonlyArray<LintDiagnostic>;
95
+ static lint(source: string, options?: ChangesetLintOptions): ReadonlyArray<LintDiagnostic>;
91
96
  }
97
+ export type { ChangesetLintOptions };
92
98
  //# sourceMappingURL=lint.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/changesets",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "private": false,
5
5
  "description": "Changeset files, `.changeset/config.json` and the release plan as Effect schemas and pure functions.",
6
6
  "keywords": [
@@ -43,8 +43,8 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@effected/glob": "^0.20.0",
46
- "@effected/semver": "^0.22.0",
47
- "@effected/workspaces": "^0.44.1",
46
+ "@effected/semver": "^0.23.0",
47
+ "@effected/workspaces": "^0.44.2",
48
48
  "@effected/yaml": "^0.29.0"
49
49
  },
50
50
  "peerDependencies": {
@@ -1,37 +0,0 @@
1
- import { RULE_DOCS, headingAnchor } from "./docs.js";
2
- import { LintRule } from "@effected/markdown-lint";
3
-
4
- // src/internal/lint/content-structure.ts
5
- const ContentStructure = LintRule.make({
6
- names: ["changeset-content-structure", "CSH003"],
7
- description: "Sections must have content, code blocks need languages, list items need text",
8
- tags: ["changeset"],
9
- information: RULE_DOCS.CSH003,
10
- check: (context, report) => {
11
- const children = context.root.children;
12
- children.forEach((node, index) => {
13
- if (node.type !== "heading" || node.depth !== 2) return;
14
- const next = children[index + 1];
15
- if (next === void 0 || next.type === "heading" && next.depth === 2) report(context.diagnostic({
16
- at: headingAnchor(context.source, children, index),
17
- detail: `Empty section: heading has no content before the next section or end of file. Add a list of changes (e.g., "- Added feature X") under this heading, or remove the empty heading. See: ${RULE_DOCS.CSH003}`
18
- }));
19
- });
20
- const codes = [];
21
- const items = [];
22
- for (const node of children) if (node.type === "code" && node.fenceChar !== void 0 && (node.lang === void 0 || node.lang === "")) codes.push(context.diagnostic({
23
- at: node,
24
- detail: `Code block is missing a language identifier. Add a language after the opening fence (e.g., \`\`\`ts, \`\`\`json, \`\`\`bash). See: ${RULE_DOCS.CSH003}`
25
- }));
26
- else if (node.type === "list") for (const item of node.children) {
27
- if (item.children.some((child) => child.type === "paragraph")) continue;
28
- items.push(context.diagnostic({
29
- at: item,
30
- detail: `Empty list item. Each list item must contain descriptive text (e.g., "- Fixed login timeout issue"). See: ${RULE_DOCS.CSH003}`
31
- }));
32
- }
33
- for (const finding of [...codes, ...items]) report(finding);
34
- }
35
- });
36
-
37
- export { ContentStructure };
@@ -1,117 +0,0 @@
1
- import { RULE_DOCS, VERSION_RE, headingAnchor, writtenText } from "./docs.js";
2
- import { LintRule } from "@effected/markdown-lint";
3
-
4
- // src/internal/lint/dependency-table-format.ts
5
- const EM_DASH = "—";
6
- const VALID_TYPES = [
7
- "dependency",
8
- "devDependency",
9
- "peerDependency",
10
- "optionalDependency",
11
- "workspace",
12
- "config",
13
- "runtime",
14
- "packageManager"
15
- ];
16
- const VALID_ACTIONS = [
17
- "added",
18
- "updated",
19
- "removed"
20
- ];
21
- const EXPECTED_HEADERS = [
22
- "dependency",
23
- "type",
24
- "action",
25
- "from",
26
- "to"
27
- ];
28
- /**
29
- * A row's cells as written, escapes resolved, as systems' markdownlint rule
30
- * reads them. GFM pads a short row to the header's width with zero-width
31
- * cells at the row's end; those were not written and are not counted, so a
32
- * short row reads as too few columns, as markdownlint sees it. An empty cell
33
- * the author wrote sits before a pipe, so it is never at the row's end.
34
- */
35
- const cellsOf = (source, row) => {
36
- const end = row.position.end.offset;
37
- let written = row.children.length;
38
- while (written > 0) {
39
- const cell = row.children[written - 1];
40
- if (cell === void 0 || cell.position.start.offset !== end || cell.position.end.offset !== end) break;
41
- written--;
42
- }
43
- return row.children.slice(0, written).map((cell) => writtenText(source, cell).trim());
44
- };
45
- const DependencyTableFormat = LintRule.make({
46
- names: ["changeset-dependency-table-format", "CSH005"],
47
- description: "Dependencies section must contain a valid dependency table",
48
- tags: ["changeset"],
49
- information: RULE_DOCS.CSH005,
50
- check: (context, report) => {
51
- const children = context.root.children;
52
- children.forEach((node, index) => {
53
- if (node.type !== "heading" || node.depth !== 2) return;
54
- if (writtenText(context.source, node).toLowerCase() !== "dependencies") return;
55
- let table;
56
- for (let next = index + 1; next < children.length; next++) {
57
- const candidate = children[next];
58
- if (candidate === void 0 || candidate.type === "heading") break;
59
- if (candidate.type === "table") {
60
- table = candidate;
61
- break;
62
- }
63
- }
64
- if (table === void 0 || table.type !== "table") {
65
- report(context.diagnostic({
66
- at: headingAnchor(context.source, children, index),
67
- detail: `Dependencies section must contain a table, not a list or paragraph. See: ${RULE_DOCS.CSH005}`
68
- }));
69
- return;
70
- }
71
- const [header, ...rows] = table.children;
72
- if (header === void 0) {
73
- report(context.diagnostic({
74
- at: table,
75
- detail: `Dependencies table is missing a header row. See: ${RULE_DOCS.CSH005}`
76
- }));
77
- return;
78
- }
79
- const headers = cellsOf(context.source, header).map((cell) => cell.toLowerCase());
80
- if (headers.length !== EXPECTED_HEADERS.length || !headers.every((cell, column) => cell === EXPECTED_HEADERS[column])) {
81
- report(context.diagnostic({
82
- at: header,
83
- detail: `Dependencies table must have columns: Dependency, Type, Action, From, To. Got: ${headers.join(", ")}. See: ${RULE_DOCS.CSH005}`
84
- }));
85
- return;
86
- }
87
- if (rows.length === 0) {
88
- report(context.diagnostic({
89
- at: table,
90
- detail: `Dependencies table must have at least one data row. See: ${RULE_DOCS.CSH005}`
91
- }));
92
- return;
93
- }
94
- for (const row of rows) {
95
- const cells = cellsOf(context.source, row);
96
- const at = (detail) => report(context.diagnostic({
97
- at: row,
98
- detail
99
- }));
100
- if (cells.length < 5) {
101
- at(`Dependencies table row has too few columns (expected 5, got ${cells.length}). See: ${RULE_DOCS.CSH005}`);
102
- continue;
103
- }
104
- const [dependency = "", type = "", action = "", from = "", to = ""] = cells;
105
- if (dependency === "") at(`Dependencies table row has an empty 'Dependency' cell. See: ${RULE_DOCS.CSH005}`);
106
- if (!VALID_TYPES.includes(type)) at(`Invalid dependency type '${type}'. Valid types are: ${VALID_TYPES.join(", ")}. See: ${RULE_DOCS.CSH005}`);
107
- if (!VALID_ACTIONS.includes(action)) at(`Invalid dependency action '${action}'. Valid actions are: ${VALID_ACTIONS.join(", ")}. See: ${RULE_DOCS.CSH005}`);
108
- if (from !== "" && !VERSION_RE.test(from)) at(`Invalid 'from' value '${from}'. Must be a semver string or em dash (${EM_DASH}). See: ${RULE_DOCS.CSH005}`);
109
- if (to !== "" && !VERSION_RE.test(to)) at(`Invalid 'to' value '${to}'. Must be a semver string or em dash (${EM_DASH}). See: ${RULE_DOCS.CSH005}`);
110
- if (action === "added" && from !== EM_DASH) at(`'from' must be '${EM_DASH}' when action is 'added' (got '${from}'). See: ${RULE_DOCS.CSH005}`);
111
- if (action === "removed" && to !== EM_DASH) at(`'to' must be '${EM_DASH}' when action is 'removed' (got '${to}'). See: ${RULE_DOCS.CSH005}`);
112
- }
113
- });
114
- }
115
- });
116
-
117
- export { DependencyTableFormat };