@atlaskit/eslint-plugin-ui-styling-standard 2.1.2 → 2.1.4

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 (40) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +18 -18
  3. package/dist/cjs/rules/no-important-styles/index.js +79 -99
  4. package/dist/cjs/rules/no-nested-selectors/index.js +48 -36
  5. package/dist/cjs/rules/no-unsafe-selectors/index.js +88 -87
  6. package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +140 -101
  7. package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +20 -50
  8. package/dist/cjs/rules/utils/create-rule-with-typed-config.js +29 -10
  9. package/dist/cjs/rules/utils/is-simple-selector.js +70 -0
  10. package/dist/cjs/rules/utils/parse-selector.js +30 -0
  11. package/dist/cjs/rules/utils/style-calls.js +127 -0
  12. package/dist/cjs/rules/utils/walk-style-call-properties.js +50 -0
  13. package/dist/es2019/rules/no-important-styles/index.js +79 -70
  14. package/dist/es2019/rules/no-nested-selectors/index.js +38 -36
  15. package/dist/es2019/rules/no-unsafe-selectors/index.js +68 -89
  16. package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +29 -23
  17. package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +4 -30
  18. package/dist/es2019/rules/utils/create-rule-with-typed-config.js +30 -10
  19. package/dist/es2019/rules/utils/is-simple-selector.js +63 -0
  20. package/dist/es2019/rules/utils/parse-selector.js +23 -0
  21. package/dist/es2019/rules/utils/style-calls.js +89 -0
  22. package/dist/es2019/rules/utils/walk-style-call-properties.js +23 -0
  23. package/dist/esm/rules/no-important-styles/index.js +80 -100
  24. package/dist/esm/rules/no-nested-selectors/index.js +48 -34
  25. package/dist/esm/rules/no-unsafe-selectors/index.js +89 -87
  26. package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +141 -102
  27. package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +19 -49
  28. package/dist/esm/rules/utils/create-rule-with-typed-config.js +30 -10
  29. package/dist/esm/rules/utils/is-simple-selector.js +64 -0
  30. package/dist/esm/rules/utils/parse-selector.js +23 -0
  31. package/dist/esm/rules/utils/style-calls.js +120 -0
  32. package/dist/esm/rules/utils/walk-style-call-properties.js +44 -0
  33. package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -1
  34. package/dist/types/rules/no-unsafe-selectors/walk-css-map.d.ts +1 -7
  35. package/dist/types/rules/utils/create-rule-with-typed-config.d.ts +1 -1
  36. package/dist/types/rules/utils/is-simple-selector.d.ts +11 -0
  37. package/dist/types/rules/utils/parse-selector.d.ts +9 -0
  38. package/dist/types/rules/utils/style-calls.d.ts +17 -0
  39. package/dist/types/rules/utils/walk-style-call-properties.d.ts +5 -0
  40. package/package.json +3 -3
@@ -1,14 +1,26 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ 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; } } }; }
3
+ 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; } }
4
+ 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; }
2
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
- import { isNesting } from 'postcss-selector-parser';
6
+ import { isNesting, isPseudo } from 'postcss-selector-parser';
4
7
  import { allowedPseudos } from './constants';
5
8
  import { getSourceLocationFromRange } from './get-source-location-from-range';
6
9
  import { getRangeFromNode } from './source-position-utils';
7
10
  export function lintSelector(args) {
8
11
  checkNoAmbiguousPseudos(args);
9
- checkNoRestrictedPseudos(args);
10
- checkNoLegacyPseudoElementSyntax(args);
11
- checkNoIncreasedSpecificity(args);
12
+ var pseudos = [];
13
+ var nestings = [];
14
+ args.selector.walk(function (node) {
15
+ if (isPseudo(node)) {
16
+ pseudos.push(node);
17
+ } else if (isNesting(node)) {
18
+ nestings.push(node);
19
+ }
20
+ });
21
+ checkNoRestrictedPseudos(args, pseudos);
22
+ checkNoLegacyPseudoElementSyntax(args, pseudos);
23
+ checkNoIncreasedSpecificity(args, nestings);
12
24
  }
13
25
  var legacyPseudoElements = new Set([':after', ':before', ':first-letter', ':first-line']);
14
26
 
@@ -76,39 +88,47 @@ function checkNoAmbiguousPseudos(_ref) {
76
88
  });
77
89
  }
78
90
  }
79
- function checkNoRestrictedPseudos(_ref2) {
91
+ function checkNoRestrictedPseudos(_ref2, pseudos) {
80
92
  var context = _ref2.context,
81
- sourceNode = _ref2.sourceNode,
82
- selector = _ref2.selector;
83
- selector.walkPseudos(function (pseudo) {
84
- if (allowedPseudos.has(pseudo.value)) {
85
- return;
86
- }
93
+ sourceNode = _ref2.sourceNode;
94
+ var _iterator = _createForOfIteratorHelper(pseudos),
95
+ _step;
96
+ try {
97
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
98
+ var pseudo = _step.value;
99
+ if (allowedPseudos.has(pseudo.value)) {
100
+ continue;
101
+ }
87
102
 
88
- /**
89
- * If someone has written `:after` it is allowed,
90
- * they've just used the legacy syntax.
91
- *
92
- * This will be caught by the `no-legacy-pseudo-element-syntax` check.
93
- */
94
- if (legacyPseudoElements.has(pseudo.value) && allowedPseudos.has(":".concat(pseudo.value))) {
95
- return;
96
- }
97
- if (!allowedPseudos.has(pseudo.value)) {
98
- var range = getRangeFromNode({
99
- node: pseudo,
100
- sourceNode: sourceNode
101
- });
102
- var loc = getSourceLocationFromRange(context, range);
103
- context.report({
104
- loc: loc,
105
- messageId: 'no-restricted-pseudos',
106
- data: {
107
- pseudo: pseudo.value
108
- }
109
- });
103
+ /**
104
+ * If someone has written `:after` it is allowed,
105
+ * they've just used the legacy syntax.
106
+ *
107
+ * This will be caught by the `no-legacy-pseudo-element-syntax` check.
108
+ */
109
+ if (legacyPseudoElements.has(pseudo.value) && allowedPseudos.has(":".concat(pseudo.value))) {
110
+ continue;
111
+ }
112
+ if (!allowedPseudos.has(pseudo.value)) {
113
+ var range = getRangeFromNode({
114
+ node: pseudo,
115
+ sourceNode: sourceNode
116
+ });
117
+ var loc = getSourceLocationFromRange(context, range);
118
+ context.report({
119
+ loc: loc,
120
+ messageId: 'no-restricted-pseudos',
121
+ data: {
122
+ pseudo: pseudo.value
123
+ }
124
+ });
125
+ }
110
126
  }
111
- });
127
+ } catch (err) {
128
+ _iterator.e(err);
129
+ } finally {
130
+ _iterator.f();
131
+ }
112
132
  }
113
133
 
114
134
  /**
@@ -116,78 +136,97 @@ function checkNoRestrictedPseudos(_ref2) {
116
136
  *
117
137
  * https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
118
138
  */
119
- function checkNoLegacyPseudoElementSyntax(_ref3) {
139
+ function checkNoLegacyPseudoElementSyntax(_ref3, pseudos) {
120
140
  var context = _ref3.context,
121
- sourceNode = _ref3.sourceNode,
122
- selector = _ref3.selector;
123
- selector.walkPseudos(function (pseudo) {
124
- if (legacyPseudoElements.has(pseudo.value)) {
125
- var range = getRangeFromNode({
126
- node: pseudo,
127
- sourceNode: sourceNode
128
- });
129
- var loc = getSourceLocationFromRange(context, range);
130
- context.report({
131
- loc: loc,
132
- messageId: 'no-legacy-pseudo-element-syntax',
133
- fix: /*#__PURE__*/_regeneratorRuntime.mark(function fix(fixer) {
134
- return _regeneratorRuntime.wrap(function (_context3) {
135
- while (1) switch (_context3.prev = _context3.next) {
136
- case 0:
137
- _context3.next = 1;
138
- return fixer.insertTextBeforeRange(range, ':');
139
- case 1:
140
- case "end":
141
- return _context3.stop();
142
- }
143
- }, fix);
144
- })
145
- });
141
+ sourceNode = _ref3.sourceNode;
142
+ var _iterator2 = _createForOfIteratorHelper(pseudos),
143
+ _step2;
144
+ try {
145
+ var _loop = function _loop() {
146
+ var pseudo = _step2.value;
147
+ if (legacyPseudoElements.has(pseudo.value)) {
148
+ var range = getRangeFromNode({
149
+ node: pseudo,
150
+ sourceNode: sourceNode
151
+ });
152
+ var loc = getSourceLocationFromRange(context, range);
153
+ context.report({
154
+ loc: loc,
155
+ messageId: 'no-legacy-pseudo-element-syntax',
156
+ fix: /*#__PURE__*/_regeneratorRuntime.mark(function fix(fixer) {
157
+ return _regeneratorRuntime.wrap(function (_context3) {
158
+ while (1) switch (_context3.prev = _context3.next) {
159
+ case 0:
160
+ _context3.next = 1;
161
+ return fixer.insertTextBeforeRange(range, ':');
162
+ case 1:
163
+ case "end":
164
+ return _context3.stop();
165
+ }
166
+ }, fix);
167
+ })
168
+ });
169
+ }
170
+ };
171
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
172
+ _loop();
146
173
  }
147
- });
174
+ } catch (err) {
175
+ _iterator2.e(err);
176
+ } finally {
177
+ _iterator2.f();
178
+ }
148
179
  }
149
- function checkNoIncreasedSpecificity(_ref4) {
180
+ function checkNoIncreasedSpecificity(_ref4, nestings) {
150
181
  var context = _ref4.context,
151
- sourceNode = _ref4.sourceNode,
152
- selector = _ref4.selector;
153
- selector.walkNesting(function (nesting) {
154
- /**
155
- * If it's not the start of a chain, then it's already been reported.
156
- */
157
- if (isNesting(nesting.prev())) {
158
- return;
159
- }
160
- var next = nesting.next();
182
+ sourceNode = _ref4.sourceNode;
183
+ var _iterator3 = _createForOfIteratorHelper(nestings),
184
+ _step3;
185
+ try {
186
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
187
+ var nesting = _step3.value;
188
+ /**
189
+ * If it's not the start of a chain, then it's already been reported.
190
+ */
191
+ if (isNesting(nesting.prev())) {
192
+ continue;
193
+ }
194
+ var next = nesting.next();
161
195
 
162
- /**
163
- * If it is followed by something other than another nesting selector,
164
- * then it isn't just there to increase specificity — it is actually necessary.
165
- */
166
- if (next && !isNesting(next)) {
167
- return;
168
- }
169
- var lastNesting = nesting;
170
- while (isNesting(next)) {
171
- lastNesting = next;
172
- next = next.next();
196
+ /**
197
+ * If it is followed by something other than another nesting selector,
198
+ * then it isn't just there to increase specificity — it is actually necessary.
199
+ */
200
+ if (next && !isNesting(next)) {
201
+ continue;
202
+ }
203
+ var lastNesting = nesting;
204
+ while (isNesting(next)) {
205
+ lastNesting = next;
206
+ next = next.next();
207
+ }
208
+ var _getRangeFromNode = getRangeFromNode({
209
+ node: nesting,
210
+ sourceNode: sourceNode
211
+ }),
212
+ _getRangeFromNode2 = _slicedToArray(_getRangeFromNode, 1),
213
+ start = _getRangeFromNode2[0];
214
+ var _getRangeFromNode3 = getRangeFromNode({
215
+ node: lastNesting,
216
+ sourceNode: sourceNode
217
+ }),
218
+ _getRangeFromNode4 = _slicedToArray(_getRangeFromNode3, 2),
219
+ _ = _getRangeFromNode4[0],
220
+ end = _getRangeFromNode4[1];
221
+ var loc = getSourceLocationFromRange(context, [start, end]);
222
+ context.report({
223
+ loc: loc,
224
+ messageId: 'no-increased-specificity'
225
+ });
173
226
  }
174
- var _getRangeFromNode = getRangeFromNode({
175
- node: nesting,
176
- sourceNode: sourceNode
177
- }),
178
- _getRangeFromNode2 = _slicedToArray(_getRangeFromNode, 1),
179
- start = _getRangeFromNode2[0];
180
- var _getRangeFromNode3 = getRangeFromNode({
181
- node: lastNesting,
182
- sourceNode: sourceNode
183
- }),
184
- _getRangeFromNode4 = _slicedToArray(_getRangeFromNode3, 2),
185
- _ = _getRangeFromNode4[0],
186
- end = _getRangeFromNode4[1];
187
- var loc = getSourceLocationFromRange(context, [start, end]);
188
- context.report({
189
- loc: loc,
190
- messageId: 'no-increased-specificity'
191
- });
192
- });
227
+ } catch (err) {
228
+ _iterator3.e(err);
229
+ } finally {
230
+ _iterator3.f();
231
+ }
193
232
  }
@@ -1,12 +1,9 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
1
  /**
3
2
  * This util is intentionally not in `@atlaskit/eslint-utils` at this time.
4
3
  *
5
4
  * This is because the API is likely to change and should not be considered stable.
6
5
  */
7
6
 
8
- import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
9
-
10
7
  /**
11
8
  * At-rules that are allowed to be used in "grouped" form within cssMap.
12
9
  *
@@ -53,45 +50,18 @@ import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
53
50
  */
54
51
  var allowedGroupedAtRules = new Set(['@starting-style' // Has no parameters, can only be written in grouped form
55
52
  ]);
56
- export function walkCssMap(_ref) {
57
- var context = _ref.context,
58
- importSources = _ref.importSources,
59
- visitor = _ref.visitor;
60
- var program = getSourceCode(context).ast;
61
- var importDeclaration = program.body.find(function (node) {
62
- return node.type === 'ImportDeclaration' && importSources.includes(node.source.value);
63
- });
64
- var specifier = importDeclaration === null || importDeclaration === void 0 ? void 0 : importDeclaration.specifiers.find(function (specifier) {
65
- return specifier.type === 'ImportSpecifier' && 'name' in specifier.imported && specifier.imported.name === 'cssMap';
66
- });
67
- if (!specifier) {
68
- return;
69
- }
70
- var _getSourceCode$scopeM = getSourceCode(context).scopeManager.getDeclaredVariables(specifier),
71
- _getSourceCode$scopeM2 = _slicedToArray(_getSourceCode$scopeM, 1),
72
- variable = _getSourceCode$scopeM2[0];
73
- if (!variable) {
74
- return;
75
- }
76
- variable.references.forEach(function (reference) {
77
- var identifier = reference.identifier;
78
- var parent = identifier.parent;
79
- if (parent.type !== 'CallExpression') {
80
- return;
81
- }
82
- var variantMap = parent.arguments[0];
83
- if (variantMap.type !== 'ObjectExpression') {
84
- return;
85
- }
53
+ export function walkCssMapCall(call, visitor) {
54
+ var variantMap = call.arguments[0];
55
+ if ((variantMap === null || variantMap === void 0 ? void 0 : variantMap.type) === 'ObjectExpression') {
86
56
  walkCssMapVariantMap({
87
57
  variantMap: variantMap,
88
58
  visitor: visitor
89
59
  });
90
- });
60
+ }
91
61
  }
92
- function walkCssMapVariantMap(_ref2) {
93
- var variantMap = _ref2.variantMap,
94
- visitor = _ref2.visitor;
62
+ function walkCssMapVariantMap(_ref) {
63
+ var variantMap = _ref.variantMap,
64
+ visitor = _ref.visitor;
95
65
  variantMap.properties.forEach(function (property) {
96
66
  if (property.type !== 'Property') {
97
67
  return;
@@ -102,9 +72,9 @@ function walkCssMapVariantMap(_ref2) {
102
72
  });
103
73
  });
104
74
  }
105
- function walkCssMapVariant(_ref3) {
106
- var variant = _ref3.variant,
107
- visitor = _ref3.visitor;
75
+ function walkCssMapVariant(_ref2) {
76
+ var variant = _ref2.variant,
77
+ visitor = _ref2.visitor;
108
78
  visitor({
109
79
  type: 'variant',
110
80
  node: variant
@@ -143,9 +113,9 @@ function walkCssMapVariant(_ref3) {
143
113
  });
144
114
  });
145
115
  }
146
- function walkCssMapAtRuleGrouping(_ref4) {
147
- var atRuleGrouping = _ref4.atRuleGrouping,
148
- visitor = _ref4.visitor;
116
+ function walkCssMapAtRuleGrouping(_ref3) {
117
+ var atRuleGrouping = _ref3.atRuleGrouping,
118
+ visitor = _ref3.visitor;
149
119
  var atRule = getKeyValue(atRuleGrouping.key);
150
120
  if (!atRule) {
151
121
  return;
@@ -172,9 +142,9 @@ function walkCssMapAtRuleGrouping(_ref4) {
172
142
  });
173
143
  });
174
144
  }
175
- function walkCssMapSelectors(_ref5) {
176
- var selectors = _ref5.selectors,
177
- visitor = _ref5.visitor;
145
+ function walkCssMapSelectors(_ref4) {
146
+ var selectors = _ref4.selectors,
147
+ visitor = _ref4.visitor;
178
148
  visitor({
179
149
  type: 'selectors',
180
150
  node: selectors
@@ -192,9 +162,9 @@ function walkCssMapSelectors(_ref5) {
192
162
  });
193
163
  });
194
164
  }
195
- function walkStyleRuleset(_ref6) {
196
- var ruleset = _ref6.ruleset,
197
- visitor = _ref6.visitor;
165
+ function walkStyleRuleset(_ref5) {
166
+ var ruleset = _ref5.ruleset,
167
+ visitor = _ref5.visitor;
198
168
  visitor({
199
169
  type: 'ruleset',
200
170
  node: ruleset
@@ -3,7 +3,27 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
4
  import Ajv from 'ajv';
5
5
  import { getRuleUrl } from './get-rule-url';
6
+
7
+ /**
8
+ * A single shared Ajv instance is reused across every rule instead of constructing
9
+ * a new one each time a default config is needed. Ajv's constructor is expensive
10
+ * (it compiles its own meta-schemas), so we only ever want to pay for it once.
11
+ */
12
+ var ajv = new Ajv({
13
+ useDefaults: true
14
+ });
6
15
  export var createLintRuleWithTypedConfig = function createLintRuleWithTypedConfig(rule) {
16
+ /**
17
+ * Lazily-computed, cached default config.
18
+ *
19
+ * The default config is derived purely from the rule's (static) schema, so it is
20
+ * constant for the life of the process. Compiling the schema with Ajv involves
21
+ * runtime code generation (`new Function`), which is expensive — previously this
22
+ * ran on every `getDefaultConfig()` call, i.e. once per linted file. We now compute
23
+ * it at most once per rule and reuse the result.
24
+ */
25
+ var defaultConfig;
26
+
7
27
  /**
8
28
  * Gets the default config by running the same validator
9
29
  * ESLint does against an empty config object with
@@ -13,16 +33,16 @@ export var createLintRuleWithTypedConfig = function createLintRuleWithTypedConfi
13
33
  * will be populated with the specified default value.
14
34
  */
15
35
  function getDefaultConfig() {
16
- var ajv = new Ajv({
17
- useDefaults: true
18
- });
19
- var validate = ajv.compile(rule.meta.schema);
20
- var config = {};
21
- /**
22
- * The `validate()` function mutates the config object.
23
- */
24
- validate(config);
25
- return config;
36
+ if (defaultConfig === undefined) {
37
+ var validate = ajv.compile(rule.meta.schema);
38
+ var _config = {};
39
+ /**
40
+ * The `validate()` function mutates the config object.
41
+ */
42
+ validate(_config);
43
+ defaultConfig = _config;
44
+ }
45
+ return defaultConfig;
26
46
  }
27
47
  return _objectSpread(_objectSpread({}, rule), {}, {
28
48
  meta: _objectSpread(_objectSpread({}, rule.meta), {}, {
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Recognizes simple, parseable selector lists made only from nesting and non-functional pseudos.
3
+ * Returning false means the caller must use the full selector parser.
4
+ */
5
+ export function isSimpleSelector(selectorText) {
6
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
7
+ var index = 0;
8
+ while (index < selectorText.length) {
9
+ index = skipWhitespace(selectorText, index);
10
+ var hasNesting = selectorText.charCodeAt(index) === 38;
11
+ if (hasNesting) {
12
+ index++;
13
+ if (selectorText.charCodeAt(index) === 38) {
14
+ return false;
15
+ }
16
+ } else if (!options.allowLeadingPseudo || selectorText.charCodeAt(index) !== 58) {
17
+ return false;
18
+ }
19
+ var pseudoCount = 0;
20
+ while (selectorText.charCodeAt(index) === 58) {
21
+ var pseudoStart = index++;
22
+ if (selectorText.charCodeAt(index) === 58) {
23
+ index++;
24
+ }
25
+ var nameStart = index;
26
+ while (index < selectorText.length && isPseudoNameCharacter(selectorText.charCodeAt(index))) {
27
+ index++;
28
+ }
29
+ if (index === nameStart || selectorText.charCodeAt(index) === 40) {
30
+ return false;
31
+ }
32
+ if (options.allowedPseudos && !options.allowedPseudos.has(selectorText.slice(pseudoStart, index))) {
33
+ return false;
34
+ }
35
+ pseudoCount++;
36
+ }
37
+ if (pseudoCount === 0 && (!hasNesting || !options.allowBareNesting)) {
38
+ return false;
39
+ }
40
+ index = skipWhitespace(selectorText, index);
41
+ if (index === selectorText.length) {
42
+ return true;
43
+ }
44
+ if (selectorText.charCodeAt(index) !== 44) {
45
+ return false;
46
+ }
47
+ index++;
48
+ }
49
+ return false;
50
+ }
51
+ function skipWhitespace(value, start) {
52
+ var index = start;
53
+ while (index < value.length) {
54
+ var character = value.charCodeAt(index);
55
+ if (character !== 32 && (character < 9 || character > 13)) {
56
+ break;
57
+ }
58
+ index++;
59
+ }
60
+ return index;
61
+ }
62
+ function isPseudoNameCharacter(character) {
63
+ return character === 45 || character === 95 || character >= 48 && character <= 57 || character >= 65 && character <= 90 || character >= 97 && character <= 122;
64
+ }
@@ -0,0 +1,23 @@
1
+ import cssSelectorParser from 'postcss-selector-parser';
2
+ import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
3
+ var cssSelectorProcessor = cssSelectorParser();
4
+ var selectorCache = new WeakMap();
5
+
6
+ /**
7
+ * Parse each selector once per linted source file. Consumers treat the returned AST as read-only.
8
+ */
9
+ export function parseSelector(context, selectorText) {
10
+ var sourceCode = getSourceCode(context);
11
+ var sourceFileCache = selectorCache.get(sourceCode);
12
+ if (!sourceFileCache) {
13
+ sourceFileCache = new Map();
14
+ selectorCache.set(sourceCode, sourceFileCache);
15
+ }
16
+ var cachedSelector = sourceFileCache.get(selectorText);
17
+ if (cachedSelector) {
18
+ return cachedSelector;
19
+ }
20
+ var selector = cssSelectorProcessor.astSync(selectorText);
21
+ sourceFileCache.set(selectorText, selector);
22
+ return selector;
23
+ }
@@ -0,0 +1,120 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ 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; } } }; }
3
+ 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; } }
4
+ 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; }
5
+ import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
6
+ var styleFunctionNames = new Set(['css', 'cssMap', 'keyframes', 'styled', 'xcss']);
7
+ var defaultStyledImportSources = new Set(['@emotion/styled', 'styled' + '-components']);
8
+ var styleCallsBySourceCode = new WeakMap();
9
+
10
+ /**
11
+ * Visit imported style calls without resolving every CallExpression against its current scope.
12
+ *
13
+ * ESLint has already linked import bindings to all of their references. Building this index once
14
+ * per source file makes each styling rule proportional to the number of style calls instead of the
15
+ * number of all calls in the file.
16
+ */
17
+ export function getStyleCalls(context) {
18
+ var sourceCode = getSourceCode(context);
19
+ var styleCalls = styleCallsBySourceCode.get(sourceCode);
20
+ if (!styleCalls) {
21
+ styleCalls = buildStyleCallIndex(sourceCode);
22
+ styleCallsBySourceCode.set(sourceCode, styleCalls);
23
+ }
24
+ return styleCalls;
25
+ }
26
+ function buildStyleCallIndex(sourceCode) {
27
+ var styleCalls = [];
28
+ var seenCalls = new Set();
29
+ var scopeManager = sourceCode.scopeManager;
30
+ if (!scopeManager) {
31
+ return styleCalls;
32
+ }
33
+ var _iterator = _createForOfIteratorHelper(sourceCode.ast.body),
34
+ _step;
35
+ try {
36
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
37
+ var statement = _step.value;
38
+ if (statement.type !== 'ImportDeclaration' || typeof statement.source.value !== 'string') {
39
+ continue;
40
+ }
41
+ var importSource = statement.source.value;
42
+ var _iterator2 = _createForOfIteratorHelper(statement.specifiers),
43
+ _step2;
44
+ try {
45
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
46
+ var specifier = _step2.value;
47
+ var styleFunction = getStyleFunctionFromSpecifier(specifier, importSource);
48
+ if (!styleFunction) {
49
+ continue;
50
+ }
51
+ var _scopeManager$getDecl = scopeManager.getDeclaredVariables(specifier),
52
+ _scopeManager$getDecl2 = _slicedToArray(_scopeManager$getDecl, 1),
53
+ variable = _scopeManager$getDecl2[0];
54
+ if (!variable) {
55
+ continue;
56
+ }
57
+ var _iterator3 = _createForOfIteratorHelper(variable.references),
58
+ _step3;
59
+ try {
60
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
61
+ var reference = _step3.value;
62
+ var call = getStyleCall(reference.identifier, styleFunction);
63
+ if (!call || seenCalls.has(call)) {
64
+ continue;
65
+ }
66
+ seenCalls.add(call);
67
+ styleCalls.push({
68
+ importSource: importSource,
69
+ node: call,
70
+ styleFunction: styleFunction
71
+ });
72
+ }
73
+ } catch (err) {
74
+ _iterator3.e(err);
75
+ } finally {
76
+ _iterator3.f();
77
+ }
78
+ }
79
+ } catch (err) {
80
+ _iterator2.e(err);
81
+ } finally {
82
+ _iterator2.f();
83
+ }
84
+ }
85
+ } catch (err) {
86
+ _iterator.e(err);
87
+ } finally {
88
+ _iterator.f();
89
+ }
90
+ return styleCalls;
91
+ }
92
+ function getStyleFunctionFromSpecifier(specifier, importSource) {
93
+ if (specifier.type === 'ImportSpecifier' && specifier.imported.type === 'Identifier' && styleFunctionNames.has(specifier.imported.name)) {
94
+ return specifier.imported.name;
95
+ }
96
+ if (specifier.type !== 'ImportDefaultSpecifier') {
97
+ return null;
98
+ }
99
+ if (styleFunctionNames.has(specifier.local.name)) {
100
+ return specifier.local.name;
101
+ }
102
+ return defaultStyledImportSources.has(importSource) ? 'styled' : null;
103
+ }
104
+ function getStyleCall(identifier, styleFunction) {
105
+ var _parent2, _parent$parent;
106
+ var callee = identifier;
107
+ var parent = callee.parent;
108
+ while (((_parent = parent) === null || _parent === void 0 ? void 0 : _parent.type) === 'MemberExpression' && parent.object === callee) {
109
+ var _parent;
110
+ callee = parent;
111
+ parent = callee.parent;
112
+ }
113
+ if (((_parent2 = parent) === null || _parent2 === void 0 ? void 0 : _parent2.type) !== 'CallExpression' || parent.callee !== callee) {
114
+ return null;
115
+ }
116
+ if (styleFunction === 'styled' && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.callee === parent) {
117
+ return parent.parent;
118
+ }
119
+ return parent;
120
+ }