@redpanda-data/docs-extensions-and-macros 5.31.0 → 5.35.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.
@@ -11,7 +11,8 @@ image:
11
11
  tag: latest
12
12
 
13
13
  # -- Service settings that were commented out wholesale. The nested markers
14
- # below are dead: no pipeline can attach them.
14
+ # below are dead: they use the indented `# -- ` form, which helm-docs does
15
+ # not recognize as a marker at all, so no pipeline can attach them.
15
16
  # service:
16
17
  # -- set service.name to override the default service name
17
18
  # name: redpanda
@@ -20,8 +21,9 @@ image:
20
21
  # annotations: {}
21
22
 
22
23
 
23
- # A marker separated from any key by a blank line is dead too:
24
- # -- This orphaned description attaches to nothing.
24
+ # A marker separated from the next key by blank lines is NOT dead: helm-docs
25
+ # ignores the gap and hands it to the next real key below, which is `resources`.
26
+ # -- Orphaned marker; helm-docs attaches this to the next real key.
25
27
 
26
28
  # @doc external.domain -- Optional domain advertised to external clients.
27
29
  # @default -- `nil`
@@ -33,6 +35,17 @@ resources:
33
35
  # @ignored
34
36
  internalHiddenKey: {}
35
37
 
38
+ misattached:
39
+ # -- Written for the commented-out key below, but with no blank line and no
40
+ # later marker, helm-docs hands this text to realKeyBelow instead.
41
+ # optionalKey:
42
+ realKeyBelow: value
43
+ # -- Written for the commented-out key below. The real key that follows has
44
+ # its own marker, so helm-docs uses that one and nothing is misattached.
45
+ # anotherOptional:
46
+ # -- The guarded key's own description.
47
+ guarded: value
48
+
36
49
  undocumentedTopLevel:
37
50
  child: value
38
51
 
@@ -25,7 +25,8 @@ const SURFACES = {
25
25
  rpk: require('./surfaces/rpk'),
26
26
  helm: require('./surfaces/helm'),
27
27
  crd: require('./surfaces/crd'),
28
- connect: require('./surfaces/connect')
28
+ connect: require('./surfaces/connect'),
29
+ api: require('./surfaces/api')
29
30
  }
30
31
 
31
32
  /**
@@ -54,6 +54,79 @@ function isNameEcho (name, description) {
54
54
  return true
55
55
  }
56
56
 
57
+ /**
58
+ * Blank out the spans of a description where a code-ish token is expected to
59
+ * appear bare, so the inline-code rule only sees prose:
60
+ *
61
+ * * backticked spans - already marked up, which is the whole point;
62
+ * * URLs and Markdown link targets - a path inside a link is part of the
63
+ * link, and backticking it would break the link;
64
+ * * anything the declaration is named after, which name-echo owns.
65
+ *
66
+ * Replaced with spaces rather than removed so match indices stay meaningful.
67
+ */
68
+ function maskNonProse (text) {
69
+ let out = text
70
+ const blank = (m) => ' '.repeat(m.length)
71
+ // Backticked spans first: a URL inside backticks is already marked up.
72
+ out = out.replace(/`[^`]*`/g, blank)
73
+ // Markdown links: mask the whole construct, target included.
74
+ out = out.replace(/\[[^\]]*\]\([^)]*\)/g, blank)
75
+ // Bare URLs, and AsciiDoc's url[text] form.
76
+ out = out.replace(/\b[a-z][a-z0-9+.-]*:\/\/\S+/gi, blank)
77
+ return out
78
+ }
79
+
80
+ /**
81
+ * Tokens that are code and read as code, so they belong in inline code.
82
+ * Backticks are the portable choice: a single-backtick span is inline code in
83
+ * both AsciiDoc and Markdown, so one rule covers every surface regardless of
84
+ * which format the generator emits.
85
+ *
86
+ * Deliberately narrow. This rule posts inline suggestions on engineering PRs,
87
+ * so a false positive costs more than a miss:
88
+ *
89
+ * * snake_case with at least two segments - in this domain that is always an
90
+ * identifier (`default_topic_partitions`), never prose;
91
+ * * long flags (`--tolerate-data-loss`);
92
+ * * absolute paths with at least two segments (`/etc/redpanda/redpanda.yaml`,
93
+ * `/v1/topics`).
94
+ *
95
+ * Not included, on purpose: dotted keys (`segment.bytes`) collide with
96
+ * sentence boundaries and abbreviations; bare `true`/`false` and numbers
97
+ * appear in ordinary prose; single-segment lowercase words are unrecoverable
98
+ * from prose without a symbol table.
99
+ */
100
+ const CODE_TOKEN_PATTERNS = Object.freeze([
101
+ { id: 'identifier', re: /\b[a-z][a-z0-9]*(?:_[a-z0-9]+)+\b/g },
102
+ { id: 'flag', re: /(?<![\w-])--[a-z][a-z0-9]*(?:-[a-z0-9]+)*\b/g },
103
+ { id: 'path', re: /(?<![\w/])\/[a-z][a-zA-Z0-9_.-]*(?:\/[a-zA-Z0-9_.{}-]+)+\/?/g }
104
+ ])
105
+
106
+ /**
107
+ * Code-ish tokens in a description that are not inside inline code.
108
+ * Exported for tests and for the surfaces that scope the rule differently.
109
+ */
110
+ function findBareCodeTokens (text, name = null) {
111
+ const masked = maskNonProse(String(text || ''))
112
+ const found = []
113
+ const seen = new Set()
114
+ for (const { id, re } of CODE_TOKEN_PATTERNS) {
115
+ re.lastIndex = 0
116
+ let match
117
+ while ((match = re.exec(masked)) !== null) {
118
+ const token = match[0]
119
+ // The declaration's own name restating itself is name-echo's finding,
120
+ // not a markup one.
121
+ if (name && token === name) continue
122
+ if (seen.has(token)) continue
123
+ seen.add(token)
124
+ found.push({ token, kind: id })
125
+ }
126
+ }
127
+ return found
128
+ }
129
+
57
130
  const COMMON_RULES = [
58
131
  {
59
132
  name: 'empty-description',
@@ -142,7 +215,20 @@ const COMMON_RULES = [
142
215
  }
143
216
  return []
144
217
  }
218
+ },
219
+ {
220
+ name: 'missing-inline-code',
221
+ description: 'Code value or field name in prose without inline code',
222
+ severity: 'warning',
223
+ check: (decl) => {
224
+ const bare = findBareCodeTokens(decl.string, decl.name)
225
+ if (bare.length === 0) return []
226
+ const list = bare.map((b) => `\`${b.token}\``).join(', ')
227
+ return [{
228
+ message: `Code values and field names belong in inline code: ${list}. Wrap each in backticks, which render as inline code in both AsciiDoc and Markdown.`
229
+ }]
230
+ }
145
231
  }
146
232
  ]
147
233
 
148
- module.exports = { COMMON_RULES, JARGON_TERMS, isNameEcho, tokenize }
234
+ module.exports = { COMMON_RULES, JARGON_TERMS, isNameEcho, tokenize, findBareCodeTokens, maskNonProse }