@atlaskit/eslint-plugin-ui-styling-standard 2.4.1 → 3.0.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +19 -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/no-important-styles/index.js +35 -9
  7. package/dist/cjs/rules/utils/is-type-wrapper.js +23 -0
  8. package/dist/cjs/rules/utils/walk-style-call-properties.js +24 -11
  9. package/dist/es2019/presets/all-flat.codegen.js +1 -2
  10. package/dist/es2019/presets/all.codegen.js +1 -2
  11. package/dist/es2019/rules/index.codegen.js +1 -3
  12. package/dist/es2019/rules/no-important-styles/index.js +37 -9
  13. package/dist/es2019/rules/utils/is-type-wrapper.js +17 -0
  14. package/dist/es2019/rules/utils/walk-style-call-properties.js +15 -12
  15. package/dist/esm/presets/all-flat.codegen.js +1 -2
  16. package/dist/esm/presets/all.codegen.js +1 -2
  17. package/dist/esm/rules/index.codegen.js +1 -3
  18. package/dist/esm/rules/no-important-styles/index.js +35 -9
  19. package/dist/esm/rules/utils/is-type-wrapper.js +17 -0
  20. package/dist/esm/rules/utils/walk-style-call-properties.js +24 -11
  21. package/dist/types/presets/all-flat.codegen.d.ts +1 -1
  22. package/dist/types/presets/all.codegen.d.ts +1 -1
  23. package/dist/types/rules/index.codegen.d.ts +1 -1
  24. package/dist/types/rules/utils/is-type-wrapper.d.ts +6 -0
  25. package/dist/types/rules/utils/walk-style-call-properties.d.ts +0 -1
  26. package/package.json +1 -1
  27. package/dist/cjs/rules/no-top-layer-unsafe-selectors/find-template-selectors.js +0 -232
  28. package/dist/cjs/rules/no-top-layer-unsafe-selectors/index.js +0 -425
  29. package/dist/cjs/rules/no-top-layer-unsafe-selectors/preserve-list-layout.js +0 -63
  30. package/dist/cjs/rules/no-top-layer-unsafe-selectors/rewrite-selector.js +0 -2415
  31. package/dist/cjs/rules/utils/walk-style-object-properties.js +0 -47
  32. package/dist/es2019/rules/no-top-layer-unsafe-selectors/find-template-selectors.js +0 -226
  33. package/dist/es2019/rules/no-top-layer-unsafe-selectors/index.js +0 -382
  34. package/dist/es2019/rules/no-top-layer-unsafe-selectors/preserve-list-layout.js +0 -57
  35. package/dist/es2019/rules/no-top-layer-unsafe-selectors/rewrite-selector.js +0 -2131
  36. package/dist/es2019/rules/utils/walk-style-object-properties.js +0 -29
  37. package/dist/esm/rules/no-top-layer-unsafe-selectors/find-template-selectors.js +0 -226
  38. package/dist/esm/rules/no-top-layer-unsafe-selectors/index.js +0 -419
  39. package/dist/esm/rules/no-top-layer-unsafe-selectors/preserve-list-layout.js +0 -57
  40. package/dist/esm/rules/no-top-layer-unsafe-selectors/rewrite-selector.js +0 -2409
  41. package/dist/esm/rules/utils/walk-style-object-properties.js +0 -41
  42. package/dist/types/rules/no-top-layer-unsafe-selectors/find-template-selectors.d.ts +0 -29
  43. package/dist/types/rules/no-top-layer-unsafe-selectors/index.d.ts +0 -3
  44. package/dist/types/rules/no-top-layer-unsafe-selectors/preserve-list-layout.d.ts +0 -12
  45. package/dist/types/rules/no-top-layer-unsafe-selectors/rewrite-selector.d.ts +0 -164
  46. package/dist/types/rules/utils/walk-style-object-properties.d.ts +0 -18
@@ -1,26 +1,17 @@
1
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
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
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
- import { walkStyleObjectProperties } from './walk-style-object-properties';
5
4
  export function walkStyleCallProperties(styleCall, visitor, options) {
6
5
  var skipTopLevel = !(options !== null && options !== void 0 && options.includeTopLevel) && (styleCall.styleFunction === 'cssMap' || styleCall.styleFunction === 'keyframes');
7
- var _ref = options !== null && options !== void 0 ? options : {},
8
- skipSubtree = _ref.skipSubtree;
9
6
  var _iterator = _createForOfIteratorHelper(styleCall.node.arguments),
10
7
  _step;
11
8
  try {
12
9
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
13
10
  var argument = _step.value;
14
11
  if (argument.type === 'ObjectExpression') {
15
- walkStyleObjectProperties(argument, visitor, {
16
- skipTopLevel: skipTopLevel,
17
- skipSubtree: skipSubtree
18
- });
12
+ walkStyleObject(argument, visitor, skipTopLevel);
19
13
  } else if (argument.type === 'ArrowFunctionExpression' && argument.expression && argument.body.type === 'ObjectExpression') {
20
- walkStyleObjectProperties(argument.body, visitor, {
21
- skipTopLevel: skipTopLevel,
22
- skipSubtree: skipSubtree
23
- });
14
+ walkStyleObject(argument.body, visitor, skipTopLevel);
24
15
  }
25
16
  }
26
17
  } catch (err) {
@@ -28,4 +19,26 @@ export function walkStyleCallProperties(styleCall, visitor, options) {
28
19
  } finally {
29
20
  _iterator.f();
30
21
  }
22
+ }
23
+ function walkStyleObject(object, visitor, skipVisitor) {
24
+ var _iterator2 = _createForOfIteratorHelper(object.properties),
25
+ _step2;
26
+ try {
27
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
28
+ var property = _step2.value;
29
+ if (property.type !== 'Property') {
30
+ continue;
31
+ }
32
+ if (!skipVisitor) {
33
+ visitor(property);
34
+ }
35
+ if (property.value.type === 'ObjectExpression') {
36
+ walkStyleObject(property.value, visitor, false);
37
+ }
38
+ }
39
+ } catch (err) {
40
+ _iterator2.e(err);
41
+ } finally {
42
+ _iterator2.f();
43
+ }
31
44
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::75b18fe1e3e0e0eeeb87a8dd4ed975ae>>
3
+ * @codegen <<SignedSource::4d0de15d2213df65666693ea490b4cce>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import type { Linter } from 'eslint';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::ff2cac75bedd9b12fc1c17bc6cf66c5c>>
3
+ * @codegen <<SignedSource::56ecb290562bdf88a8a5b5388a39e5f9>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import type { ESLint } from 'eslint';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7b2b0662d0eeb0e3a3e4c844a505d27e>>
3
+ * @codegen <<SignedSource::094f8a058153c7e839c5d98d2718ca4e>>
4
4
  * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import type { Rule } from 'eslint';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Whether `node` is a TypeScript wrapper (`as`, `satisfies`, `<T>`, `!`) around an expression.
3
+ */
4
+ export declare function isTypeWrapper(node: {
5
+ type: string;
6
+ } | null | undefined): boolean;
@@ -2,5 +2,4 @@ import type * as ESTree from 'eslint-codemod-utils';
2
2
  import type { StyleCall } from './style-calls';
3
3
  export declare function walkStyleCallProperties(styleCall: StyleCall, visitor: (property: ESTree.Property) => void, options?: {
4
4
  includeTopLevel?: boolean;
5
- skipSubtree?: (property: ESTree.Property) => boolean;
6
5
  }): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "2.4.1",
3
+ "version": "3.0.1",
4
4
  "author": "Atlassian Pty Ltd",
5
5
  "description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
6
6
  "license": "Apache-2.0",
@@ -1,232 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findTemplateSelectors = findTemplateSelectors;
7
- /**
8
- * Locate the selectors inside a tagged template literal's raw source text.
9
- *
10
- * The style-call index only sees call expressions, so `styled.div\`…\`` and `css\`…\`` are
11
- * invisible to it. This scanner fills that gap: it walks the text between the template's
12
- * backticks and returns the byte range of every selector, so ranges map 1:1 onto the file and
13
- * can be handed straight to an ESLint fixer.
14
- *
15
- * It deliberately does not try to be a CSS parser. A selector is the text between the last
16
- * `;`, `{` or `}` and the next `{`. Anything it mis-reads will either fail to parse as a
17
- * selector — in which case `rewriteSelector` skips it — or be reported for review. What it
18
- * must not do is mistake a `${…}` interpolation, a quoted string or a comment for CSS
19
- * structure, so it steps over all three.
20
- */
21
-
22
- function findTemplateSelectors(source, offset) {
23
- var found = [];
24
- var segmentStart = 0;
25
- /**
26
- * Set when a comment appears after the segment's first non-whitespace character. A selector
27
- * with a comment inside it — `& /* x *​/ > div` — cannot be replaced as one contiguous range
28
- * without eating the comment, so it is skipped rather than mangled. A comment *before* the
29
- * selector just moves `segmentStart` past it.
30
- */
31
- var commentInsideSegment = false;
32
- /**
33
- * How many `(` are open. Inside a function's parentheses `//` is data, not a comment:
34
- * `url(//cdn.example.com/a.png)` and an unquoted data URI both carry one.
35
- */
36
- var parenthesisDepth = 0;
37
- /**
38
- * How many CSS `{` are open. `${…}` braces and parentheses do not count.
39
- */
40
- var braceDepth = 0;
41
- /**
42
- * The brace depth at which a `@keyframes` block opened, or `null` outside one. Everything
43
- * nested inside is an offset (`from`, `50%`), not a selector — each parses as a tag selector,
44
- * so without this the guard is written onto a keyframe and the animation stops. Skipping the
45
- * at-rule's own prelude is not enough, because the block's contents open their own segments.
46
- */
47
- var keyframesDepth = null;
48
- var startSegment = function startSegment(at) {
49
- segmentStart = at;
50
- commentInsideSegment = false;
51
- };
52
-
53
- /**
54
- * Step over a comment spanning `[start, end)`. A comment before the segment's first
55
- * non-whitespace character just moves the segment past it; a comment inside the segment
56
- * marks it unfixable. Returns the index to resume scanning at.
57
- */
58
- var skipComment = function skipComment(start, end) {
59
- var isLeading = source.slice(segmentStart, start).trim() === '';
60
- if (isLeading) {
61
- segmentStart = end;
62
- } else {
63
- commentInsideSegment = true;
64
- }
65
- return end;
66
- };
67
- for (var index = 0; index < source.length; index++) {
68
- var character = source[index];
69
-
70
- /* Step over a quoted string — `content: "{"` must not open a block. */
71
- if (character === '"' || character === "'") {
72
- index = skipQuoted(source, index);
73
- continue;
74
- }
75
- if (character === '/' && source[index + 1] === '*') {
76
- var close = source.indexOf('*/', index + 2);
77
- var end = close === -1 ? source.length : close + 2;
78
- index = skipComment(index, end) - 1;
79
- continue;
80
- }
81
-
82
- /**
83
- * A `//` line comment. Emotion and styled-components strip these before the CSS is
84
- * parsed, so a selector written after one on the next line is real. Inside parentheses
85
- * the same two characters are part of a URL, so the depth check keeps them.
86
- */
87
- if (character === '/' && source[index + 1] === '/' && parenthesisDepth === 0) {
88
- var newline = source.indexOf('\n', index + 2);
89
- var _end = newline === -1 ? source.length : newline + 1;
90
- index = skipComment(index, _end) - 1;
91
- continue;
92
- }
93
- if (character === '(') {
94
- parenthesisDepth++;
95
- continue;
96
- }
97
- if (character === ')') {
98
- parenthesisDepth = Math.max(0, parenthesisDepth - 1);
99
- continue;
100
- }
101
-
102
- /* Step over a `${…}` interpolation. Its braces are not CSS braces, but the `${…}` text
103
- * itself stays in the segment so the transform can recognise the selector as dynamic. */
104
- if (character === '{' && index > 0 && source[index - 1] === '$') {
105
- var isLeading = source.slice(segmentStart, index - 1).trim() === '';
106
- index = skipInterpolation(source, index);
107
- /**
108
- * A `${mixin}` alone on its line, with no `;` after it, is a statement of its own:
109
- * the selector on the next line starts a fresh segment rather than inheriting the
110
- * interpolation and being read as dynamic.
111
- */
112
- if (isLeading && isRestOfLineBlank(source, index + 1)) {
113
- startSegment(index + 1);
114
- }
115
- continue;
116
- }
117
- if (character === '{') {
118
- var raw = source.slice(segmentStart, index);
119
- var leading = raw.length - raw.trimStart().length;
120
- var text = raw.trim();
121
-
122
- /* At-rules are blocks but not selectors; the transform has nothing to say about them. */
123
- if (text !== '' && !text.startsWith('@') && !commentInsideSegment && keyframesDepth === null) {
124
- found.push({
125
- text: text,
126
- start: offset + segmentStart + leading,
127
- end: offset + segmentStart + leading + text.length
128
- });
129
- }
130
- if (keyframesDepth === null && /^@(-[a-z]+-)?keyframes\b/i.test(text)) {
131
- keyframesDepth = braceDepth;
132
- }
133
- braceDepth++;
134
- startSegment(index + 1);
135
- continue;
136
- }
137
- if (character === '}') {
138
- braceDepth = Math.max(0, braceDepth - 1);
139
- if (keyframesDepth !== null && braceDepth <= keyframesDepth) {
140
- keyframesDepth = null;
141
- }
142
- }
143
- if (character === '}' || character === ';') {
144
- startSegment(index + 1);
145
- }
146
- }
147
- return found;
148
- }
149
-
150
- /**
151
- * Is everything from `start` to the next newline whitespace? A missing newline does not count:
152
- * `${selector}` at the very end has nothing after it to separate from.
153
- */
154
- function isRestOfLineBlank(source, start) {
155
- var newline = source.indexOf('\n', start);
156
- return newline !== -1 && source.slice(start, newline).trim() === '';
157
- }
158
-
159
- /**
160
- * Index of the quote closing the string that opens at `start`, or the end of the source when
161
- * the string is unterminated.
162
- */
163
- function skipQuoted(source, start) {
164
- var quote = source[start];
165
- var index = start + 1;
166
- while (index < source.length) {
167
- if (source[index] === '\\') {
168
- index += 2;
169
- continue;
170
- }
171
- if (source[index] === quote) {
172
- return index;
173
- }
174
- index++;
175
- }
176
- return source.length;
177
- }
178
-
179
- /**
180
- * Index of the `}` closing the interpolation whose `{` is at `start`, or the end of the source
181
- * when it is unterminated.
182
- *
183
- * The interpolation holds JavaScript, so a brace inside one of its string literals is not a
184
- * brace: `${cond ? '}' : ''}` closes at the last character, not at the quoted one. Quoted
185
- * strings and template literals are stepped over; a template literal may in turn hold its own
186
- * interpolations, so the two skips call each other.
187
- */
188
- function skipInterpolation(source, start) {
189
- var depth = 1;
190
- var index = start + 1;
191
- while (index < source.length && depth > 0) {
192
- var character = source[index];
193
- if (character === '"' || character === "'") {
194
- index = skipQuoted(source, index) + 1;
195
- continue;
196
- }
197
- if (character === '`') {
198
- index = skipTemplateLiteral(source, index) + 1;
199
- continue;
200
- }
201
- if (character === '{') {
202
- depth++;
203
- } else if (character === '}') {
204
- depth--;
205
- }
206
- index++;
207
- }
208
- return index - 1;
209
- }
210
-
211
- /**
212
- * Index of the backtick closing the template literal that opens at `start`, or the end of the
213
- * source when it is unterminated.
214
- */
215
- function skipTemplateLiteral(source, start) {
216
- var index = start + 1;
217
- while (index < source.length) {
218
- if (source[index] === '\\') {
219
- index += 2;
220
- continue;
221
- }
222
- if (source[index] === '`') {
223
- return index;
224
- }
225
- if (source[index] === '$' && source[index + 1] === '{') {
226
- index = skipInterpolation(source, index + 1) + 1;
227
- continue;
228
- }
229
- index++;
230
- }
231
- return source.length;
232
- }