@atlaskit/eslint-plugin-ui-styling-standard 2.1.3 → 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 (38) hide show
  1. package/CHANGELOG.md +8 -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 +46 -32
  5. package/dist/cjs/rules/no-unsafe-selectors/index.js +87 -84
  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 +3 -4
  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 +36 -34
  15. package/dist/es2019/rules/no-unsafe-selectors/index.js +67 -87
  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 +3 -4
  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 +46 -32
  25. package/dist/esm/rules/no-unsafe-selectors/index.js +88 -85
  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 +3 -4
  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/walk-css-map.d.ts +1 -7
  34. package/dist/types/rules/utils/is-simple-selector.d.ts +11 -0
  35. package/dist/types/rules/utils/parse-selector.d.ts +1 -2
  36. package/dist/types/rules/utils/style-calls.d.ts +17 -0
  37. package/dist/types/rules/utils/walk-style-call-properties.d.ts +5 -0
  38. package/package.json +1 -1
@@ -1,11 +1,15 @@
1
- import { getScope } from '@atlaskit/eslint-utils/context-compat';
2
- import { isXcss } from '@atlaskit/eslint-utils/is-supported-import';
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; }
3
4
  import { importSources } from '@atlaskit/eslint-utils/schema';
4
- import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
5
5
  import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
6
+ import { isSimpleSelector } from '../utils/is-simple-selector';
6
7
  import { parseSelector } from '../utils/parse-selector';
8
+ import { getStyleCalls } from '../utils/style-calls';
9
+ import { walkStyleCallProperties } from '../utils/walk-style-call-properties';
7
10
  import { lintSelector } from './lint-selector';
8
- import { walkCssMap } from './walk-css-map';
11
+ import { walkCssMapCall } from './walk-css-map';
12
+ import { allowedPseudos } from './constants';
9
13
  var ignoredAtRules = new Set(['@container',
10
14
  // ignored because it's covered by `no-container-queries`
11
15
  '@media',
@@ -56,93 +60,92 @@ var rule = createLintRuleWithTypedConfig({
56
60
  },
57
61
  create: function create(context, config) {
58
62
  return {
59
- Program: function Program(program) {
60
- walkCssMap({
61
- context: context,
62
- program: program,
63
- importSources: config.importSources,
64
- visitor: function visitor(property) {
65
- var type = property.type,
66
- node = property.node;
67
- if (type === 'grouped-at-rules') {
68
- context.report({
69
- node: node.key,
70
- messageId: 'no-grouped-at-rules'
71
- });
72
- return;
63
+ Program: function Program() {
64
+ var _iterator = _createForOfIteratorHelper(getStyleCalls(context)),
65
+ _step;
66
+ try {
67
+ var _loop = function _loop() {
68
+ var styleCall = _step.value;
69
+ if (!config.importSources.includes(styleCall.importSource)) {
70
+ return 1; // continue
73
71
  }
74
- if (type === 'selectors') {
75
- context.report({
76
- node: node.key,
77
- messageId: 'no-selectors-object'
72
+ if (styleCall.styleFunction === 'cssMap') {
73
+ walkCssMapCall(styleCall.node, function (property) {
74
+ var type = property.type,
75
+ node = property.node;
76
+ if (type === 'grouped-at-rules') {
77
+ context.report({
78
+ node: node.key,
79
+ messageId: 'no-grouped-at-rules'
80
+ });
81
+ } else if (type === 'selectors') {
82
+ context.report({
83
+ node: node.key,
84
+ messageId: 'no-selectors-object'
85
+ });
86
+ }
78
87
  });
79
- return;
80
88
  }
81
- }
82
- });
83
- },
84
- CallExpression: function CallExpression(node) {
85
- var _getScope = getScope(context, node),
86
- references = _getScope.references;
87
- var isXcssCall = isXcss(node, references, config.importSources);
88
- walkStyleProperties(node, references, config.importSources, function (_ref) {
89
- var key = _ref.key,
90
- value = _ref.value;
91
- /**
92
- * If the value isn't an object expression then the key can't be a selector.
93
- *
94
- * This assumes all styles have to be inline, which is enforced by `no-unsafe-values`
95
- */
96
- if (value.type !== 'ObjectExpression') {
97
- return;
98
- }
99
-
100
- /**
101
- * Technically the key could be an identifier too, e.g.
102
- *
103
- * ```ts
104
- * css({
105
- * // This key is an identifier, not a literal
106
- * selector: {}
107
- * });
108
- * ```
109
- *
110
- * But an identifier couldn't violate anything in this rule,
111
- * because it can't contain '@' or ':' characters.
112
- */
113
- if (key.type !== 'Literal' || typeof key.value !== 'string') {
114
- return;
115
- }
116
- var selectorText = key.value;
117
- if (selectorText.includes('@')) {
118
- lintAtRule({
119
- context: context,
120
- sourceNode: key,
121
- atRule: selectorText
122
- });
123
- return;
124
- }
125
- try {
126
- var selectorList = parseSelector(context, selectorText);
127
- selectorList.nodes.forEach(function (selector) {
128
- return lintSelector({
129
- context: context,
130
- sourceNode: key,
131
- selector: selector,
132
- config: config,
133
- isXcssCall: isXcssCall
134
- });
135
- });
136
- } catch (_unused) {
137
- context.report({
138
- node: key,
139
- messageId: 'no-unparsable-selectors',
140
- data: {
141
- selectorText: selectorText
89
+ walkStyleCallProperties(styleCall, function (_ref) {
90
+ var key = _ref.key,
91
+ value = _ref.value;
92
+ if (value.type !== 'ObjectExpression' || key.type !== 'Literal' || typeof key.value !== 'string') {
93
+ return;
94
+ }
95
+ var selectorText = key.value;
96
+ if (selectorText.includes('@')) {
97
+ lintAtRule({
98
+ context: context,
99
+ sourceNode: key,
100
+ atRule: selectorText
101
+ });
102
+ return;
103
+ }
104
+ if (isSimpleSelector(selectorText, {
105
+ allowedPseudos: allowedPseudos,
106
+ allowLeadingPseudo: styleCall.styleFunction === 'xcss'
107
+ })) {
108
+ return;
109
+ }
110
+ try {
111
+ var selectorList = parseSelector(context, selectorText);
112
+ var _iterator2 = _createForOfIteratorHelper(selectorList.nodes),
113
+ _step2;
114
+ try {
115
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
116
+ var selector = _step2.value;
117
+ lintSelector({
118
+ context: context,
119
+ sourceNode: key,
120
+ selector: selector,
121
+ config: config,
122
+ isXcssCall: styleCall.styleFunction === 'xcss'
123
+ });
124
+ }
125
+ } catch (err) {
126
+ _iterator2.e(err);
127
+ } finally {
128
+ _iterator2.f();
129
+ }
130
+ } catch (_unused) {
131
+ context.report({
132
+ node: key,
133
+ messageId: 'no-unparsable-selectors',
134
+ data: {
135
+ selectorText: selectorText
136
+ }
137
+ });
142
138
  }
143
139
  });
140
+ };
141
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
142
+ if (_loop()) continue;
144
143
  }
145
- });
144
+ } catch (err) {
145
+ _iterator.e(err);
146
+ } finally {
147
+ _iterator.f();
148
+ }
146
149
  }
147
150
  };
148
151
  }
@@ -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), {}, {