@wix/origami-lint 1.34.13 → 1.34.14

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.
@@ -1,4 +1,4 @@
1
- import { createCssFileReporter, describeAtRule, getCssChildren, getDashedId, getSegmentClass, getSelectorSegments, isPresetProperty, isSafeCssIdentifier } from "../../rules-api/index.js";
1
+ import { createCssFileReporter, describeAtRule, getCssChildren, getDashedId, getMixinId, getSegmentClass, getSelectorSegments, isOneEditAway, isPresetProperty, isSafeCssIdentifier } from "../../rules-api/index.js";
2
2
  import { defineRule } from "./define-rule.js";
3
3
  export default defineRule({
4
4
  name: 'apply-and-presets',
@@ -30,6 +30,7 @@ function checkAppliesAndPresets(root, kind, rulesApi, report) {
30
30
  elementRules.push(elementRule);
31
31
  }
32
32
  });
33
+ checkApplyTargets(elementRules, getDeclaredMixinIds([root, rulesApi.page.css.files.theme]), kind, reportInFile);
33
34
  const groups = groupBySelector(elementRules.filter((rule) => !rule.selector.startsWith(':root') && isSelectorParsed(rule.selector)));
34
35
  const componentClasses = new Set(Object.values(rulesApi.page.components).flatMap((component) => component.classNames));
35
36
  for (const group of groups)
@@ -108,6 +109,26 @@ function checkSelectorRules(group, componentClasses, reportInFile) {
108
109
  }
109
110
  }
110
111
  }
112
+ /** An element's `@apply --id` names a `@mixin --id` that theme.css or the same file declares (OUR-006), `--id()` included: the import reads
113
+ * the parentheses as part of the id. A mixin's own links are global-styles' (CONV-styleParser.ts:673). */
114
+ function checkApplyTargets(elementRules, declaredIds, kind, reportInFile) {
115
+ for (const { apply, selector } of elementRules) {
116
+ if (!apply)
117
+ continue;
118
+ const id = getDashedId(apply.params);
119
+ if (declaredIds.has(id))
120
+ continue;
121
+ // the build strips a trailing `()`; the import doesn't, and reads `btn()` as the id (astParser.ts MIXIN_ID_PATTERN)
122
+ const called = id.endsWith('()') ? id.slice(0, -2) : null;
123
+ if (called !== null && declaredIds.has(called)) {
124
+ reportInFile(apply, `rule \`${selector.trim()}\`: \`@apply --${id}\` reads as the global style \`${id}\`, which the site doesn't have: write \`@apply --${called}\`, without the parentheses (tracker OUR-006).`);
125
+ continue;
126
+ }
127
+ const nearMiss = [...declaredIds].find((declared) => isOneEditAway(id, declared));
128
+ const fix = nearMiss ? `Did you mean \`@apply --${nearMiss}\`? Otherwise apply` : 'Apply';
129
+ reportInFile(apply, `rule \`${selector.trim()}\`: \`@apply --${id}\` names no global style: no \`@mixin --${id}\` in theme.css${kind === 'style' ? ' or style.css' : ''}. ${fix} one theme.css declares, or declare \`@mixin --${id}\` in theme.css (tracker OUR-006).`);
130
+ }
131
+ }
111
132
  /** A `--preset-<path>` names each part as a CSS identifier (CONV-styleParser.ts:62); returns the pick, or none after reporting. */
112
133
  function checkPresetName(declaration, where, reportInFile) {
113
134
  if (declaration.prop === '--preset')
@@ -262,6 +283,10 @@ function decodePresetPath(suffix) {
262
283
  path.push(current);
263
284
  return path;
264
285
  }
286
+ /** The ids the files' top-level `@mixin`s declare (getMixinId); a file the site doesn't have declares none. */
287
+ function getDeclaredMixinIds(files) {
288
+ return new Set(files.flatMap((file) => (file ? getCssChildren(file) : []).flatMap((node) => (node.type === 'atrule' && node.name === 'mixin' ? (getMixinId(node) ?? []) : []))));
289
+ }
265
290
  /** Whether an `@apply` is one dashed id with no block after it (CONV-astParser.ts:41; an empty block, or one with only comments, passes). */
266
291
  const isApplyWritten = (apply) => getDashedId(apply.params) !== undefined && getCssChildren(apply).length === 0;
267
292
  // ── grouping ──
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/origami-lint",
3
- "version": "1.34.13",
3
+ "version": "1.34.14",
4
4
  "description": "Offline lint for an exported Origami site: lints the pages that changed since the last passing run",
5
5
  "type": "module",
6
6
  "bin": {
@@ -52,5 +52,5 @@
52
52
  ]
53
53
  }
54
54
  },
55
- "falconPackageHash": "70a9ee3d299565f2869a89a7c2269513b67bdf6101e989b4545ecc19"
55
+ "falconPackageHash": "d2ba4667a9a53d4c6d1aef0526993a1bdc7a46daaa1fc52f8fa7ca81"
56
56
  }