@lark-apaas/fullstack-presets 1.1.22 → 1.1.23-beta.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.
@@ -1,28 +1,44 @@
1
1
  /**
2
2
  * ESLint rule: no-styled-jsx-data-uri-url-ref
3
3
  *
4
- * Detects CSS `url("data:...url(...)...")` inside `<style jsx>` template
5
- * literals. The stylis CSS parser (used by styled-jsx) misreads the inner
6
- * `url(` as a new CSS url() function call, breaking bracket counting and
7
- * causing "Nesting detected" build failures.
4
+ * Catches `url("data:...")` atoms inside `<style jsx>` whose body contains
5
+ * raw `(` or `)` characters. The stylis CSS parser (used by styled-jsx)
6
+ * tracks parenthesis depth while it walks the surrounding `url(...)` token,
7
+ * so any unescaped paren in the data URI body throws bracket matching off
8
+ * and causes a "Nesting detected" build failure on a perfectly valid
9
+ * sibling declaration further down the stylesheet.
8
10
  *
9
- * This rule surfaces the problem at lint time (IDE red squiggly + CI gate)
10
- * instead of letting it escape to build time.
11
+ * Two observed flavours:
11
12
  *
12
- * Observed: 107 cases in week 04-06~04-12, all from AI-generated SVG noise
13
- * textures containing `filter='url(%23noise)'` inside data URIs.
13
+ * 1. Inline `url(#id)` references (e.g. SVG noise textures with
14
+ * `filter='url(%23noise)'`). This was the original 04-06~04-12 wave
15
+ * (107 cases / week, see referenced docs).
16
+ *
17
+ * 2. Inline CSS functions used as SVG attribute values, e.g.
18
+ * `fill='hsl(40,30%25,97%25)'`, `transform='translate(10,20)'`. These
19
+ * contain bare `(` `)` but no nested `url(`, so they slipped past the
20
+ * earlier nested-url-only check. W21 (2026-05-18~24) saw ~11 such cases
21
+ * even though the rule was already enabled — same stylis bug, different
22
+ * surface.
23
+ *
24
+ * This rule surfaces both at lint time (IDE red squiggly + CI gate) instead
25
+ * of letting them escape to build time.
14
26
  *
15
27
  * @see ~/docs/styled-jsx-nesting-bug-analysis-20260330.md
28
+ * @see ~/docs/miaoda-precommit-ts2307-rootcause-20260525.md
16
29
  * @see https://bytedance.larkoffice.com/wiki/TTNDwzgLzi9Q0skTUT5clFX3nNd
17
30
  */
18
31
  import type { Rule } from 'eslint';
19
32
  /**
20
33
  * Precise detection: scan the CSS text character-by-character, looking for
21
- * `url(<quote>data:...<quote>)` atoms. For each such atom, check whether the
22
- * body (between the matching quotes) contains `url(`. Only flag if the
23
- * offending `url(` is truly nested inside a data URI body — this eliminates
24
- * the false-positive case where a data URI and a separate `url(#gradient)`
25
- * coexist in the same CSS but are unrelated.
34
+ * `url(<quote>data:...<quote>)` atoms. For each such atom, return true if
35
+ * the body (between the matching quotes) contains a raw `(` or `)` those
36
+ * characters confuse the stylis tokenizer's paren counter and cause it to
37
+ * misattribute the bug to a later, unrelated declaration.
38
+ *
39
+ * A data URI body should never contain raw parens — they belong either
40
+ * URL-encoded (`%28`/`%29`) or, better, in a sibling `.svg` file referenced
41
+ * by external `url(/foo.svg)`.
26
42
  *
27
43
  * Safety properties (can't hang / crash lint):
28
44
  * - Single forward scan, O(n); `i` always advances past every candidate.
@@ -32,6 +48,10 @@ import type { Rule } from 'eslint';
32
48
  * - Bails safely (returns false) on unterminated strings.
33
49
  * - Zero regex backtracking; no catastrophic-regex risk.
34
50
  *
51
+ * The function name is kept for backwards compatibility (existing imports);
52
+ * the implementation now flags any paren-bearing data URI body, not just
53
+ * the historical `url(...)` nested case.
54
+ *
35
55
  * @param cssText the full CSS source of a single <style jsx> block
36
56
  */
37
57
  export declare function hasDataUriWithNestedUrl(cssText: string): boolean;
@@ -3,11 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hasDataUriWithNestedUrl = hasDataUriWithNestedUrl;
4
4
  /**
5
5
  * Precise detection: scan the CSS text character-by-character, looking for
6
- * `url(<quote>data:...<quote>)` atoms. For each such atom, check whether the
7
- * body (between the matching quotes) contains `url(`. Only flag if the
8
- * offending `url(` is truly nested inside a data URI body — this eliminates
9
- * the false-positive case where a data URI and a separate `url(#gradient)`
10
- * coexist in the same CSS but are unrelated.
6
+ * `url(<quote>data:...<quote>)` atoms. For each such atom, return true if
7
+ * the body (between the matching quotes) contains a raw `(` or `)` those
8
+ * characters confuse the stylis tokenizer's paren counter and cause it to
9
+ * misattribute the bug to a later, unrelated declaration.
10
+ *
11
+ * A data URI body should never contain raw parens — they belong either
12
+ * URL-encoded (`%28`/`%29`) or, better, in a sibling `.svg` file referenced
13
+ * by external `url(/foo.svg)`.
11
14
  *
12
15
  * Safety properties (can't hang / crash lint):
13
16
  * - Single forward scan, O(n); `i` always advances past every candidate.
@@ -17,6 +20,10 @@ exports.hasDataUriWithNestedUrl = hasDataUriWithNestedUrl;
17
20
  * - Bails safely (returns false) on unterminated strings.
18
21
  * - Zero regex backtracking; no catastrophic-regex risk.
19
22
  *
23
+ * The function name is kept for backwards compatibility (existing imports);
24
+ * the implementation now flags any paren-bearing data URI body, not just
25
+ * the historical `url(...)` nested case.
26
+ *
20
27
  * @param cssText the full CSS source of a single <style jsx> block
21
28
  */
22
29
  function hasDataUriWithNestedUrl(cssText) {
@@ -64,8 +71,11 @@ function hasDataUriWithNestedUrl(cssText) {
64
71
  if (!terminated)
65
72
  return false; // unterminated data URI — bail safely
66
73
  const body = cssText.slice(bodyStart, j);
67
- // If the data URI body contains a literal `url(`, stylis will break.
68
- if (body.indexOf('url(') !== -1)
74
+ // Any raw `(` or `)` in the body confuses the stylis paren counter.
75
+ // (Nested `url(...)` is a subset of this — the original 04-06 wave.)
76
+ // Inline CSS-function attribute values like `hsl(...)` or
77
+ // `transform='translate(...)'` are the W21 surface we missed before.
78
+ if (body.indexOf('(') !== -1 || body.indexOf(')') !== -1)
69
79
  return true;
70
80
  // Move past this data URI and keep scanning for more url() atoms.
71
81
  i = j + 1;
@@ -82,9 +92,10 @@ const rule = {
82
92
  },
83
93
  schema: [],
84
94
  messages: {
85
- dataUriUrlRef: '`url("data:...")` 的内容里嵌套了 `url(...)` 引用(如 SVG filter 的 `url(#id)`),会导致 styled-jsx CSS 解析器(stylis)' +
86
- '误判括号配对并报 "Nesting detected" 构建错误。请将 SVG 移到独立 .svg 文件通过 import 引用,' +
87
- '或改用 CSS 变量 / 外链 background-image 代替内联 data URI。',
95
+ dataUriUrlRef: '`url("data:...")` 的内容里含有未转义的括号 `(` `)`(如 `url(#noise)` / `hsl(...)` / `translate(...)`),' +
96
+ '会让 styled-jsx CSS 解析器(stylis)误算括号深度,把后面合法的 CSS 规则报成 "Nesting detected" 构建错误。' +
97
+ '建议将 SVG 移到独立 .svg 文件通过 import 引用(或 `client/public/*.svg` + 外链 background-image),' +
98
+ '不要把含 CSS 函数的 SVG 属性值内联到 data URI 里。',
88
99
  },
89
100
  },
90
101
  create(context) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/fullstack-presets",
3
- "version": "1.1.22",
3
+ "version": "1.1.23-beta.0",
4
4
  "files": [
5
5
  "lib"
6
6
  ],