@cssdoc/providers 0.5.0 → 0.5.2

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/dist/index.d.mts CHANGED
@@ -38,6 +38,14 @@ interface Diagnostic {
38
38
  span?: SourceSpan$1;
39
39
  /** Severity (defaults to `warning`). */
40
40
  severity: Severity;
41
+ /**
42
+ * Optional structured payload for consumers. `maskedName` is the class token as it appears in the
43
+ * linted (possibly projected) source, so the language server can restore an embedded `${…}`
44
+ * interpolation for display instead of the masked filler.
45
+ */
46
+ data?: {
47
+ maskedName?: string;
48
+ };
41
49
  }
42
50
  /** What kind of thing a completion inserts. */
43
51
  type CompletionKind = "component" | "modifier" | "part" | "property" | "function" | "state";
@@ -177,7 +185,7 @@ declare function applyDirectives(diagnostics: Diagnostic[], source: string): Dia
177
185
  //#endregion
178
186
  //#region src/aspects.d.ts
179
187
  declare const record: {
180
- model(index: CssDocIndex, naming?: ResolvedNaming, structureIgnore?: readonly string[]): Diagnostic[];
188
+ model(index: CssDocIndex, naming?: ResolvedNaming, structureIgnore?: readonly string[], siblingIndex?: CssDocIndex): Diagnostic[];
181
189
  completions(index: CssDocIndex): Completion[];
182
190
  hover(base: string, index: CssDocIndex, detail?: HoverDetail, sections?: HoverSections, sectionOrder?: HoverSectionOrder): Hover | undefined;
183
191
  definition(base: string, index: CssDocIndex): Location$1 | undefined;
@@ -217,7 +225,7 @@ declare const func: {
217
225
  /** The aspect names covered, in a stable order (the extension point for future aspects). */
218
226
  declare const ASPECTS: readonly ["record", "modifier", "part", "css-part", "custom-property", "structure", "function", "state", "condition"];
219
227
  /** Author-side hygiene diagnostics over the whole model (missing summaries, undocumented members, drift, invalid defaults). */
220
- declare function lintModel(index: CssDocIndex, severities?: RuleSeverities, naming?: ResolvedNaming, structureIgnore?: readonly string[]): Diagnostic[];
228
+ declare function lintModel(index: CssDocIndex, severities?: RuleSeverities, naming?: ResolvedNaming, structureIgnore?: readonly string[], siblingIndex?: CssDocIndex): Diagnostic[];
221
229
  /** Consumer-side diagnostics for custom-property assignments (`--x: value` must match its `@property` syntax). */
222
230
  declare function checkPropertyAssignments(assignments: readonly PropertyAssignment[], index: CssDocIndex, severities?: RuleSeverities): Diagnostic[];
223
231
  /**
package/dist/index.mjs CHANGED
@@ -231,8 +231,10 @@ const renderStructureTree = (nodes, depth = 0) => nodes.flatMap((n) => {
231
231
  ] : [`${pad}${n.selector}`];
232
232
  });
233
233
  const record = {
234
- model(index, naming, structureIgnore = []) {
234
+ model(index, naming, structureIgnore = [], siblingIndex = index) {
235
235
  const out = [];
236
+ const siblingClasses = new Set(siblingIndex.records.map((r) => stripDot(r.entry.className)));
237
+ const siblingNames = new Set(siblingIndex.records.flatMap((r) => r.entry.kind === "component" ? [r.entry.name] : []));
236
238
  for (const info of index.records) {
237
239
  if (!info.entry.summary?.trim()) out.push(warn({
238
240
  aspect: "record",
@@ -253,26 +255,30 @@ const record = {
253
255
  if (info.entry.structure?.length) {
254
256
  const known = /* @__PURE__ */ new Set([
255
257
  stripDot(info.entry.className),
256
- ...index.records.map((r) => stripDot(r.entry.className)),
258
+ ...siblingClasses,
257
259
  ...info.entry.parts.flatMap((p) => [stripDot(p.name), ...(p.modifiers ?? []).map((m) => m.name)]),
258
260
  ...info.entry.shadowParts.map((p) => stripDot(p.name)),
259
261
  ...info.entry.states.map((s) => s.name),
260
262
  ...info.entry.modifiers.map((m) => m.name),
261
263
  ...info.entry.slots.map((s) => s.name)
262
264
  ]);
265
+ const own = stripDot(info.entry.className);
266
+ const prefix = info.entry.name && own.endsWith(info.entry.name) ? own.slice(0, own.length - info.entry.name.length) : "";
267
+ const isSibling = (cls) => prefix !== "" && cls.startsWith(prefix) && siblingNames.has(cls.slice(prefix.length));
263
268
  const seen = /* @__PURE__ */ new Set();
264
269
  const walk = (nodes) => {
265
270
  for (const node of nodes) {
266
271
  for (const m of node.selector.matchAll(/\.([\w-]+)/gu)) {
267
272
  const cls = m[1];
268
- if (seen.has(cls) || known.has(cls) || structureIgnore.some((g) => globMatch(g, cls))) continue;
273
+ if (seen.has(cls) || known.has(cls) || isSibling(cls) || structureIgnore.some((g) => globMatch(g, cls))) continue;
269
274
  seen.add(cls);
270
275
  out.push(warn({
271
276
  aspect: "record",
272
277
  rule: "structure-unknown-selector",
273
278
  message: `@structure references ".${cls}", which isn't the component class or a documented member (add it, or list it under structureIgnore).`,
274
279
  record: info.entry.name,
275
- span: info.span
280
+ span: info.span,
281
+ data: { maskedName: cls }
276
282
  }));
277
283
  }
278
284
  walk(node.children);
@@ -800,9 +806,9 @@ const ASPECTS = [
800
806
  "condition"
801
807
  ];
802
808
  /** Author-side hygiene diagnostics over the whole model (missing summaries, undocumented members, drift, invalid defaults). */
803
- function lintModel(index, severities = DEFAULT_RULE_SEVERITIES, naming, structureIgnore) {
809
+ function lintModel(index, severities = DEFAULT_RULE_SEVERITIES, naming, structureIgnore, siblingIndex) {
804
810
  return applySeverities([
805
- ...record.model(index, naming, structureIgnore),
811
+ ...record.model(index, naming, structureIgnore, siblingIndex),
806
812
  ...modifier.model(index),
807
813
  ...part.model(index, naming),
808
814
  ...cssPart.model(index),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cssdoc/providers",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Host-agnostic aspect providers over the @cssdoc/index — diagnostics, completions, hover, and definitions for modifiers, custom properties, structure, functions, states, and conditions.",
5
5
  "keywords": [
6
6
  "css",
@@ -29,8 +29,8 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "css-tree": "^3.2.1",
32
- "@cssdoc/core": "0.5.0",
33
- "@cssdoc/index": "0.5.0"
32
+ "@cssdoc/core": "0.5.2",
33
+ "@cssdoc/index": "0.5.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/css-tree": "^2.3.11",