@atlaskit/eslint-plugin-ui-styling-standard 2.4.1 → 3.0.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.
Files changed (39) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +0 -1
  3. package/dist/cjs/presets/all-flat.codegen.js +1 -2
  4. package/dist/cjs/presets/all.codegen.js +1 -2
  5. package/dist/cjs/rules/index.codegen.js +1 -3
  6. package/dist/cjs/rules/utils/walk-style-call-properties.js +24 -11
  7. package/dist/es2019/presets/all-flat.codegen.js +1 -2
  8. package/dist/es2019/presets/all.codegen.js +1 -2
  9. package/dist/es2019/rules/index.codegen.js +1 -3
  10. package/dist/es2019/rules/utils/walk-style-call-properties.js +15 -12
  11. package/dist/esm/presets/all-flat.codegen.js +1 -2
  12. package/dist/esm/presets/all.codegen.js +1 -2
  13. package/dist/esm/rules/index.codegen.js +1 -3
  14. package/dist/esm/rules/utils/walk-style-call-properties.js +24 -11
  15. package/dist/types/presets/all-flat.codegen.d.ts +1 -1
  16. package/dist/types/presets/all.codegen.d.ts +1 -1
  17. package/dist/types/rules/index.codegen.d.ts +1 -1
  18. package/dist/types/rules/utils/walk-style-call-properties.d.ts +0 -1
  19. package/package.json +1 -1
  20. package/dist/cjs/rules/no-top-layer-unsafe-selectors/find-template-selectors.js +0 -232
  21. package/dist/cjs/rules/no-top-layer-unsafe-selectors/index.js +0 -425
  22. package/dist/cjs/rules/no-top-layer-unsafe-selectors/preserve-list-layout.js +0 -63
  23. package/dist/cjs/rules/no-top-layer-unsafe-selectors/rewrite-selector.js +0 -2415
  24. package/dist/cjs/rules/utils/walk-style-object-properties.js +0 -47
  25. package/dist/es2019/rules/no-top-layer-unsafe-selectors/find-template-selectors.js +0 -226
  26. package/dist/es2019/rules/no-top-layer-unsafe-selectors/index.js +0 -382
  27. package/dist/es2019/rules/no-top-layer-unsafe-selectors/preserve-list-layout.js +0 -57
  28. package/dist/es2019/rules/no-top-layer-unsafe-selectors/rewrite-selector.js +0 -2131
  29. package/dist/es2019/rules/utils/walk-style-object-properties.js +0 -29
  30. package/dist/esm/rules/no-top-layer-unsafe-selectors/find-template-selectors.js +0 -226
  31. package/dist/esm/rules/no-top-layer-unsafe-selectors/index.js +0 -419
  32. package/dist/esm/rules/no-top-layer-unsafe-selectors/preserve-list-layout.js +0 -57
  33. package/dist/esm/rules/no-top-layer-unsafe-selectors/rewrite-selector.js +0 -2409
  34. package/dist/esm/rules/utils/walk-style-object-properties.js +0 -41
  35. package/dist/types/rules/no-top-layer-unsafe-selectors/find-template-selectors.d.ts +0 -29
  36. package/dist/types/rules/no-top-layer-unsafe-selectors/index.d.ts +0 -3
  37. package/dist/types/rules/no-top-layer-unsafe-selectors/preserve-list-layout.d.ts +0 -12
  38. package/dist/types/rules/no-top-layer-unsafe-selectors/rewrite-selector.d.ts +0 -164
  39. package/dist/types/rules/utils/walk-style-object-properties.d.ts +0 -18
@@ -1,41 +0,0 @@
1
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
2
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
3
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
4
- /**
5
- * Walk one style object's properties at every depth. With `skipTopLevel` the top-level
6
- * properties are walked into but not visited, which is how a `cssMap` or `keyframes` argument
7
- * hides its variant or block names. Nested objects are always visited in full. Use this directly
8
- * for a style object that is not the argument of a style call, such as the value of a `css` prop.
9
- *
10
- * `skipSubtree` stops the descent into a property's value, so its children are never visited.
11
- * A caller needs this when a nested block's keys are not the same kind of thing as its own key:
12
- * the children of an `@keyframes` block are offsets (`from`, `50%`), not selectors, and a rule
13
- * that treats them as selectors will report — or worse, fix — a keyframe offset. Declining to
14
- * visit the at-rule property itself is not enough, because the walk into its value is what
15
- * exposes the offsets. Omit it and the walk behaves exactly as before.
16
- */
17
- export function walkStyleObjectProperties(object, visitor, options) {
18
- walk(object, visitor, Boolean(options === null || options === void 0 ? void 0 : options.skipTopLevel), options === null || options === void 0 ? void 0 : options.skipSubtree);
19
- }
20
- function walk(object, visitor, skipVisitor, skipSubtree) {
21
- var _iterator = _createForOfIteratorHelper(object.properties),
22
- _step;
23
- try {
24
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
25
- var property = _step.value;
26
- if (property.type !== 'Property') {
27
- continue;
28
- }
29
- if (!skipVisitor) {
30
- visitor(property);
31
- }
32
- if (property.value.type === 'ObjectExpression' && !(skipSubtree !== null && skipSubtree !== void 0 && skipSubtree(property))) {
33
- walk(property.value, visitor, false, skipSubtree);
34
- }
35
- }
36
- } catch (err) {
37
- _iterator.e(err);
38
- } finally {
39
- _iterator.f();
40
- }
41
- }
@@ -1,29 +0,0 @@
1
- /**
2
- * Locate the selectors inside a tagged template literal's raw source text.
3
- *
4
- * The style-call index only sees call expressions, so `styled.div\`…\`` and `css\`…\`` are
5
- * invisible to it. This scanner fills that gap: it walks the text between the template's
6
- * backticks and returns the byte range of every selector, so ranges map 1:1 onto the file and
7
- * can be handed straight to an ESLint fixer.
8
- *
9
- * It deliberately does not try to be a CSS parser. A selector is the text between the last
10
- * `;`, `{` or `}` and the next `{`. Anything it mis-reads will either fail to parse as a
11
- * selector — in which case `rewriteSelector` skips it — or be reported for review. What it
12
- * must not do is mistake a `${…}` interpolation, a quoted string or a comment for CSS
13
- * structure, so it steps over all three.
14
- */
15
- export type TemplateSelector = {
16
- /**
17
- * The selector text, trimmed. Retains any `${…}` so the transform can skip it.
18
- */
19
- text: string;
20
- /**
21
- * Absolute start offset of `text` in the file.
22
- */
23
- start: number;
24
- /**
25
- * Absolute end offset of `text` in the file.
26
- */
27
- end: number;
28
- };
29
- export declare function findTemplateSelectors(source: string, offset: number): TemplateSelector[];
@@ -1,3 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- declare const rule: Rule.RuleModule;
3
- export default rule;
@@ -1,12 +0,0 @@
1
- /**
2
- * Re-apply the author's layout of a selector list to the rewritten one.
3
- *
4
- * The transform joins its branches with `, `. A selector list written over several lines would
5
- * be collapsed onto one by the fixer, so each rewritten branch is put back between the
6
- * separators the author wrote. Falls back to the transform's text when either list does not
7
- * split cleanly, or when the two do not have the same number of branches.
8
- */
9
- export declare function preserveListLayout({ original, rewritten, }: {
10
- original: string;
11
- rewritten: string;
12
- }): string;
@@ -1,164 +0,0 @@
1
- export type Population =
2
- /**
3
- * No human judgement is required. Either a guard form exists and has been applied
4
- * (`after` is set), or the selector is provably already safe (`after` is `null`, with a
5
- * `reason` saying why nothing was needed).
6
- */
7
- 'guardable'
8
- /**
9
- * No guard form exists for this selector. Needs human triage. `after` is `null`.
10
- */
11
- | 'residue'
12
- /**
13
- * Out of reach of any host — nothing to do, nothing to triage. `after` is `null`. The one
14
- * exception carries a `reviewCause`: the transform could not decide the reach question from
15
- * the selector alone and a human must. Nothing is written for it either way.
16
- */
17
- | 'excluded'
18
- /**
19
- * Statically undecidable: a dynamically-constructed selector, an unterminated argument, or
20
- * text the parser rejects. `after` is `null`.
21
- */
22
- | 'skipped';
23
- export type DamageMode =
24
- /**
25
- * A declaration lands on the host, or on something inside it, that was never meant to
26
- * receive it — or a real element starts matching because the host is inside it. Fixed by a
27
- * `:not()` guard.
28
- */
29
- 'popover-receives'
30
- /**
31
- * The host takes a positional slot, so a *real* element stops matching. Only `of S` fixes
32
- * this; a `:not()` guard cannot. Never reported while the `of S` family is withdrawn,
33
- * because no rewrite that would close it is emitted.
34
- */
35
- | 'real-element-loses';
36
- /**
37
- * CSS specificity as `[ids, classes, types]`.
38
- */
39
- export type Specificity = [number, number, number];
40
- /**
41
- * The rule body belonging to the selector, when the caller has it.
42
- *
43
- * Accepts either raw CSS declaration text — the shape the enumeration schema stores in its
44
- * `declarations` column — or a style object with camelCase or kebab-case keys.
45
- */
46
- export type Declarations = string | Record<string, string | number | null | undefined>;
47
- /**
48
- * Where a selector is written, which decides how a branch with no `&` is read.
49
- */
50
- export type SelectorScope =
51
- /**
52
- * A style object, a `css` / `styled` template, or a `css` prop. The authoring API scopes a
53
- * branch with no `&` to the component's own element: a branch starting with a pseudo is
54
- * `&:pseudo`, and any other branch is `& branch`. Such a branch is rewritten exactly as its
55
- * `&` spelling would be, and the `&`-less spelling is preserved in the output.
56
- */
57
- 'nested'
58
- /**
59
- * A plain stylesheet. A branch with no `&` reaches the whole document.
60
- */
61
- | 'global';
62
- export type RewriteOptions = {
63
- /**
64
- * Defaults to `global`, which is the reading a `.css`-file sweep needs. The ESLint rule
65
- * passes `nested` for everything it visits.
66
- */
67
- scope?: SelectorScope;
68
- };
69
- /**
70
- * Why a selector was skipped rather than decided.
71
- */
72
- export type SkipCause =
73
- /**
74
- * The text is not statically known: it carries a template-literal or preprocessor
75
- * interpolation.
76
- */
77
- 'dynamic'
78
- /**
79
- * The text is known but is not a selector the parser accepts: unbalanced brackets, an empty
80
- * string, or a parse failure. Most likely an authoring mistake.
81
- */
82
- | 'malformed';
83
- /**
84
- * Why an `excluded` selector still needs a human decision.
85
- */
86
- export type ReviewCause =
87
- /**
88
- * At global scope, a guarded compound sits below a bare `div` ancestor. The portal container
89
- * and every surface wrapper were divs, so the rule may already have reached the surface's
90
- * content before the flag, or the div may be the author's own wrapper. Only the author knows.
91
- */
92
- 'div-ancestor';
93
- export type RewriteResult = {
94
- /**
95
- * The selector exactly as it was passed in.
96
- */
97
- before: string;
98
- /**
99
- * The rewritten selector, or `null` when there is nothing to write. Non-null only when
100
- * `population === 'guardable'` *and* `guardCount > 0`.
101
- *
102
- * Whitespace around combinators and list separators is normalised, so `after` may differ
103
- * from `before` in formatting as well as in the guards added.
104
- */
105
- after: string | null;
106
- population: Population;
107
- /**
108
- * Empty unless a rewrite was emitted. Order is stable and deduplicated.
109
- */
110
- damageModes: DamageMode[];
111
- /**
112
- * The number of guards written. Each guarded compound of the main selector counts once —
113
- * even when its guard expands to two pseudo-classes, as `:only-child` does — and each
114
- * guarded top-level comma branch of a `:has()` counts once.
115
- *
116
- * These counts are asserted downstream by the verification scripts:
117
- * - `'.x:has(button, a)'` → 2
118
- * - `'& > div > div'` → 2
119
- * - `'& > div > span'` → 1
120
- */
121
- guardCount: number;
122
- /**
123
- * Mandatory for `residue`, `excluded` and `skipped`, and for a `guardable` result with no
124
- * `after`. Also present on a `guardable` result that carries a residual exposure a guard
125
- * cannot close — read it, it is not decoration.
126
- */
127
- reason?: string;
128
- /**
129
- * Present only when `population === 'skipped'`. Says whether the selector was skipped
130
- * because its text is not known (`dynamic`) or because its text does not parse
131
- * (`malformed`), so a caller can word its report accordingly.
132
- */
133
- skipCause?: SkipCause;
134
- /**
135
- * Present only when `population === 'excluded'` and the exclusion is a deferral rather than
136
- * a verdict: the transform would have written a guard but the reach question cannot be
137
- * settled from the selector alone. A caller that writes files should mark the site for a
138
- * human instead of filing it as out of reach.
139
- */
140
- reviewCause?: ReviewCause;
141
- /**
142
- * Max (a,b,c) across the top-level comma branches of `before`.
143
- */
144
- specificityBefore: Specificity;
145
- /**
146
- * Max (a,b,c) across the top-level comma branches of `after`, or of `before` when there is
147
- * no `after`. Always equal to `specificityBefore` — a rewrite that would change
148
- * specificity is refused as `residue` rather than emitted.
149
- */
150
- specificityAfter: Specificity;
151
- };
152
- /**
153
- * Rewrite a selector so a top layer host can neither receive its declarations nor displace
154
- * the real elements it targets.
155
- *
156
- * Pure and idempotent: feeding `after` back in yields `guardCount: 0` and `after: null`.
157
- *
158
- * @param selector A single selector or a comma-separated selector list. May contain the
159
- * nesting selector `&`.
160
- * @param declarations The rule body, if the caller has it. Used for exactly one decision — see
161
- * {@link findResetSignal}. Omitting it never produces a *wrong* answer, only a lossier one.
162
- * @param options See {@link RewriteOptions}.
163
- */
164
- export declare function rewriteSelector(selector: string, declarations?: Declarations, options?: RewriteOptions): RewriteResult;
@@ -1,18 +0,0 @@
1
- import type * as ESTree from 'eslint-codemod-utils';
2
- /**
3
- * Walk one style object's properties at every depth. With `skipTopLevel` the top-level
4
- * properties are walked into but not visited, which is how a `cssMap` or `keyframes` argument
5
- * hides its variant or block names. Nested objects are always visited in full. Use this directly
6
- * for a style object that is not the argument of a style call, such as the value of a `css` prop.
7
- *
8
- * `skipSubtree` stops the descent into a property's value, so its children are never visited.
9
- * A caller needs this when a nested block's keys are not the same kind of thing as its own key:
10
- * the children of an `@keyframes` block are offsets (`from`, `50%`), not selectors, and a rule
11
- * that treats them as selectors will report — or worse, fix — a keyframe offset. Declining to
12
- * visit the at-rule property itself is not enough, because the walk into its value is what
13
- * exposes the offsets. Omit it and the walk behaves exactly as before.
14
- */
15
- export declare function walkStyleObjectProperties(object: ESTree.ObjectExpression, visitor: (property: ESTree.Property) => void, options?: {
16
- skipTopLevel?: boolean;
17
- skipSubtree?: (property: ESTree.Property) => boolean;
18
- }): void;