@atlaskit/eslint-plugin-ui-styling-standard 1.0.4 → 1.1.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 (59) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +17 -17
  3. package/dist/cjs/rules/atlaskit-theme/index.js +9 -8
  4. package/dist/cjs/rules/convert-props-syntax/index.js +5 -3
  5. package/dist/cjs/rules/enforce-style-prop/index.js +53 -14
  6. package/dist/cjs/rules/local-cx-xcss/index.js +3 -2
  7. package/dist/cjs/rules/no-array-arguments/index.js +4 -3
  8. package/dist/cjs/rules/no-container-queries/index.js +3 -2
  9. package/dist/cjs/rules/no-dynamic-styles/index.js +3 -2
  10. package/dist/cjs/rules/no-important-styles/index.js +3 -2
  11. package/dist/cjs/rules/no-imported-style-values/index.js +6 -5
  12. package/dist/cjs/rules/no-nested-selectors/index.js +4 -3
  13. package/dist/cjs/rules/no-styled/index.js +4 -3
  14. package/dist/cjs/rules/no-unsafe-selectors/index.js +3 -2
  15. package/dist/cjs/rules/no-unsafe-selectors/source-position-utils.js +2 -1
  16. package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +5 -4
  17. package/dist/cjs/rules/no-unsafe-values/index.js +3 -2
  18. package/dist/cjs/rules/no-unsafe-values/utils.js +1 -2
  19. package/dist/cjs/rules/use-compiled/index.js +3 -2
  20. package/dist/cjs/rules/use-compiled/is-safe.js +3 -2
  21. package/dist/cjs/rules/use-compiled/utils.js +2 -1
  22. package/dist/es2019/rules/atlaskit-theme/index.js +5 -4
  23. package/dist/es2019/rules/convert-props-syntax/index.js +6 -3
  24. package/dist/es2019/rules/enforce-style-prop/index.js +50 -13
  25. package/dist/es2019/rules/local-cx-xcss/index.js +3 -2
  26. package/dist/es2019/rules/no-array-arguments/index.js +3 -2
  27. package/dist/es2019/rules/no-container-queries/index.js +2 -1
  28. package/dist/es2019/rules/no-dynamic-styles/index.js +2 -2
  29. package/dist/es2019/rules/no-important-styles/index.js +2 -1
  30. package/dist/es2019/rules/no-imported-style-values/index.js +4 -3
  31. package/dist/es2019/rules/no-nested-selectors/index.js +3 -2
  32. package/dist/es2019/rules/no-styled/index.js +5 -4
  33. package/dist/es2019/rules/no-unsafe-selectors/index.js +2 -1
  34. package/dist/es2019/rules/no-unsafe-selectors/source-position-utils.js +2 -1
  35. package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +3 -2
  36. package/dist/es2019/rules/no-unsafe-values/index.js +2 -1
  37. package/dist/es2019/rules/use-compiled/index.js +3 -2
  38. package/dist/es2019/rules/use-compiled/is-safe.js +3 -2
  39. package/dist/es2019/rules/use-compiled/utils.js +2 -1
  40. package/dist/esm/rules/atlaskit-theme/index.js +9 -8
  41. package/dist/esm/rules/convert-props-syntax/index.js +5 -3
  42. package/dist/esm/rules/enforce-style-prop/index.js +53 -14
  43. package/dist/esm/rules/local-cx-xcss/index.js +3 -2
  44. package/dist/esm/rules/no-array-arguments/index.js +4 -3
  45. package/dist/esm/rules/no-container-queries/index.js +3 -2
  46. package/dist/esm/rules/no-dynamic-styles/index.js +3 -3
  47. package/dist/esm/rules/no-important-styles/index.js +3 -2
  48. package/dist/esm/rules/no-imported-style-values/index.js +6 -5
  49. package/dist/esm/rules/no-nested-selectors/index.js +4 -3
  50. package/dist/esm/rules/no-styled/index.js +5 -4
  51. package/dist/esm/rules/no-unsafe-selectors/index.js +3 -2
  52. package/dist/esm/rules/no-unsafe-selectors/source-position-utils.js +2 -1
  53. package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +5 -4
  54. package/dist/esm/rules/no-unsafe-values/index.js +3 -2
  55. package/dist/esm/rules/no-unsafe-values/utils.js +1 -2
  56. package/dist/esm/rules/use-compiled/index.js +3 -2
  57. package/dist/esm/rules/use-compiled/is-safe.js +3 -2
  58. package/dist/esm/rules/use-compiled/utils.js +2 -1
  59. package/package.json +6 -5
@@ -4,6 +4,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
4
4
  import { isNodeOfType } from 'eslint-codemod-utils';
5
5
  import { analyze } from 'eslint-scope';
6
6
  import ESTraverse from 'estraverse';
7
+ import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
7
8
  import { isEmotion, isStyledComponents } from '@atlaskit/eslint-utils/is-supported-import';
8
9
  import { createLintRule } from '../utils/create-rule';
9
10
 
@@ -212,7 +213,7 @@ var lintArguments = function lintArguments(context, args) {
212
213
  ESTraverse.traverse(property.value, {
213
214
  enter: function enter(node, _parent) {
214
215
  if (node.type === 'ArrowFunctionExpression') {
215
- var propNames = parseArrowFunctionExpression(node, context.getSourceCode());
216
+ var propNames = parseArrowFunctionExpression(node, getSourceCode(context));
216
217
  if (!propNames) {
217
218
  // We've encountered a CSS value we don't recognise, skip.
218
219
  return;
@@ -250,7 +251,7 @@ var lintArguments = function lintArguments(context, args) {
250
251
  node: argument,
251
252
  messageId: 'unsupported-prop-syntax',
252
253
  fix: function fix(fixer) {
253
- var sourceCode = context.getSourceCode();
254
+ var sourceCode = getSourceCode(context);
254
255
  return fixPropsObjectUsages(fixer, sourceCode, argument,
255
256
  // The
256
257
  // allProps.some((propUsage) => !propUsage.valid)
@@ -381,7 +382,8 @@ export var rule = createLintRule({
381
382
  return {
382
383
  CallExpression: function CallExpression(node) {
383
384
  var _node$parent, _node$parent2;
384
- var references = context.getScope().references;
385
+ var _getScope = getScope(context, node),
386
+ references = _getScope.references;
385
387
 
386
388
  // Rule should ignore .attrs() calls
387
389
  if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'attrs') {
@@ -1,11 +1,12 @@
1
1
  import { isNodeOfType } from 'eslint-codemod-utils';
2
2
  import { getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
3
+ import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
3
4
  import { findVariable } from '@atlaskit/eslint-utils/find-variable';
4
5
  import { createLintRule } from '../utils/create-rule';
5
6
  var isParameter = function isParameter(context, identifier) {
6
7
  var _findVariable;
7
8
  var definitions = (_findVariable = findVariable({
8
- sourceCode: context.getSourceCode(),
9
+ sourceCode: getSourceCode(context),
9
10
  identifier: identifier
10
11
  })) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
11
12
  if (!definitions || !definitions.length) {
@@ -17,7 +18,7 @@ var isParameter = function isParameter(context, identifier) {
17
18
  var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
18
19
  var _variable$identifiers;
19
20
  var variable = findVariable({
20
- sourceCode: context.getSourceCode(),
21
+ sourceCode: getSourceCode(context),
21
22
  identifier: identifier
22
23
  });
23
24
  if (!variable) {
@@ -25,8 +26,6 @@ var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
25
26
  }
26
27
  var variableDefinition = variable.defs[0].node;
27
28
 
28
- // console.log('@@variableDefinition', variableDefinition);
29
-
30
29
  // If identifier is a RestElement, report warning
31
30
  if (((_variable$identifiers = variable.identifiers[0]) === null || _variable$identifiers === void 0 || (_variable$identifiers = _variable$identifiers.parent) === null || _variable$identifiers === void 0 ? void 0 : _variable$identifiers.type) === 'RestElement') {
32
31
  return false;
@@ -71,6 +70,7 @@ function isPropertyValueAllowed(property, context) {
71
70
  if (property.type === 'SpreadElement') {
72
71
  return false;
73
72
  }
73
+
74
74
  // property.type === 'Property', moving on to check if value is static
75
75
  if (property.value.type === 'Literal') {
76
76
  return false;
@@ -78,7 +78,7 @@ function isPropertyValueAllowed(property, context) {
78
78
  return isIdentifierAllowed(context, property.value);
79
79
  } else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier') {
80
80
  var variable = findVariable({
81
- sourceCode: context.getSourceCode(),
81
+ sourceCode: getSourceCode(context),
82
82
  identifier: property.value.callee
83
83
  });
84
84
  // Anything returned by getAllowedFunctionCalls should be used in css prop instead
@@ -92,7 +92,7 @@ function isPropertyValueAllowed(property, context) {
92
92
  } else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
93
93
  var _findVariable2;
94
94
  var definitions = (_findVariable2 = findVariable({
95
- sourceCode: context.getSourceCode(),
95
+ sourceCode: getSourceCode(context),
96
96
  identifier: property.value.object
97
97
  })) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
98
98
  if (!definitions || !definitions.length) {
@@ -134,15 +134,16 @@ export var rule = createLintRule({
134
134
  },
135
135
  create: function create(context) {
136
136
  return {
137
- 'JSXAttribute[name.name="style"] > JSXExpressionContainer': function JSXAttributeNameNameStyleJSXExpressionContainer(node) {
138
- var _node$expression$expr;
137
+ 'JSXAttribute[name.name="style"] > JSXExpressionContainer': function JSXAttributeNameNameStyle__JSXExpressionContainer(node) {
138
+ var _node$expression$expr, _expression;
139
139
  if (!isNodeOfType(node, 'JSXExpressionContainer')) {
140
140
  return;
141
141
  }
142
142
 
143
143
  // we've reached an attribute named style
144
144
 
145
- var expression;
145
+ var expression = null;
146
+ var reportOnNodeExpression = false;
146
147
  if (
147
148
  // @ts-expect-error -- TSAsExpression is not valid in estree
148
149
  node.expression.type === 'TSAsExpression' &&
@@ -154,21 +155,59 @@ export var rule = createLintRule({
154
155
  } else if (node.expression.type === 'ObjectExpression') {
155
156
  // Typical `style={{ … }}` scenario
156
157
  expression = node.expression;
157
- } else {
158
+ } else if (node.expression.type === 'Identifier') {
159
+ var _variable$defs;
160
+ /*
161
+ * Example:
162
+ * ```tsx
163
+ * const style = { width: 100 };
164
+ * <div style={style} />
165
+ * ```
166
+ */
167
+ var variable = findVariable({
168
+ sourceCode: getSourceCode(context),
169
+ identifier: node.expression
170
+ });
171
+
172
+ // Types are alluding us here, but we really only want an ObjectExpression here
173
+ // Additionally, if we have multiple variable definitions, we're in some unhandled scenario
174
+ // so we're only going to look at the first one…
175
+ var hopefulObjectExpression = variable === null || variable === void 0 || (_variable$defs = variable.defs) === null || _variable$defs === void 0 || (_variable$defs = _variable$defs[0]) === null || _variable$defs === void 0 || (_variable$defs = _variable$defs.node) === null || _variable$defs === void 0 ? void 0 : _variable$defs.init;
176
+ if ((hopefulObjectExpression === null || hopefulObjectExpression === void 0 ? void 0 : hopefulObjectExpression.type) === 'ObjectExpression') {
177
+ expression = hopefulObjectExpression;
178
+ }
179
+ reportOnNodeExpression = true;
180
+ }
181
+ if (!((_expression = expression) !== null && _expression !== void 0 && _expression.properties)) {
158
182
  context.report({
159
183
  node: node,
160
184
  messageId: 'enforce-style-prop'
161
185
  });
162
186
  return;
163
187
  }
164
- expression.properties.forEach(function (value) {
165
- if (!isPropertyValueAllowed(value, context)) {
188
+ if (reportOnNodeExpression) {
189
+ // In some cases we want to report on the `node.expression` itself, eg.
190
+ // `styles` in `style={styles}` should get the error
191
+ if (expression.properties.some(function (value) {
192
+ return !isPropertyValueAllowed(value, context);
193
+ })) {
166
194
  context.report({
167
- node: value,
195
+ node: node.expression,
168
196
  messageId: 'enforce-style-prop'
169
197
  });
170
198
  }
171
- });
199
+ } else {
200
+ // Typically we want to report on the individual styles, eg.
201
+ // `color: 'red'` in `style={{ color: 'red' }}` should get the error
202
+ expression.properties.forEach(function (value) {
203
+ if (!isPropertyValueAllowed(value, context)) {
204
+ context.report({
205
+ node: value,
206
+ messageId: 'enforce-style-prop'
207
+ });
208
+ }
209
+ });
210
+ }
172
211
  }
173
212
  };
174
213
  }
@@ -1,5 +1,6 @@
1
- import { createLintRule } from '../utils/create-rule';
1
+ import { getScope } from '@atlaskit/eslint-utils/context-compat';
2
2
  import { CSS_IN_JS_IMPORTS, isCxFunction } from '@atlaskit/eslint-utils/is-supported-import';
3
+ import { createLintRule } from '../utils/create-rule';
3
4
  var IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
4
5
  function getParentJSXAttribute(node) {
5
6
  var parent = node.parent;
@@ -27,7 +28,7 @@ export var rule = createLintRule({
27
28
  create: function create(context) {
28
29
  return {
29
30
  'CallExpression[callee.name="cx"]': function CallExpressionCalleeNameCx(node) {
30
- if (node.type === 'CallExpression' && isCxFunction(node.callee, context.getScope().references, IMPORT_SOURCES)) {
31
+ if (node.type === 'CallExpression' && isCxFunction(node.callee, getScope(context, node).references, IMPORT_SOURCES)) {
31
32
  var parentJSXAttribute = getParentJSXAttribute(node);
32
33
  var propName = parentJSXAttribute === null || parentJSXAttribute === void 0 ? void 0 : parentJSXAttribute.name.name.toString();
33
34
  if (propName && /[xX]css$/.test(propName)) {
@@ -3,6 +3,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
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
4
  // eslint-disable-next-line @atlassian/tangerine/import/entry-points
5
5
 
6
+ import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
6
7
  import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
7
8
  import { createLintRule } from '../utils/create-rule';
8
9
  var schema = [{
@@ -36,8 +37,8 @@ export var rule = createLintRule({
36
37
  var importSources = getImportSources(context);
37
38
  return {
38
39
  CallExpression: function CallExpression(node) {
39
- var _context$getScope = context.getScope(),
40
- references = _context$getScope.references;
40
+ var _getScope = getScope(context, node),
41
+ references = _getScope.references;
41
42
  if (!hasStyleObjectArguments(node.callee, references, importSources)) {
42
43
  return;
43
44
  }
@@ -66,7 +67,7 @@ export var rule = createLintRule({
66
67
  var items = argument.elements.filter(function (value) {
67
68
  return value !== null;
68
69
  }).map(function (element) {
69
- return context.getSourceCode().getText(element);
70
+ return getSourceCode(context).getText(element);
70
71
  });
71
72
  return fixer.replaceText(argument, items.join(', '));
72
73
  }
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable @atlassian/tangerine/import/entry-points */
2
2
 
3
3
  import estraverse from 'estraverse';
4
+ import { getScope } from '@atlaskit/eslint-utils/context-compat';
4
5
  import { getImportSources, isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
5
6
  import { createLintRule } from '../utils/create-rule';
6
7
  var schema = [{
@@ -33,8 +34,8 @@ export var rule = createLintRule({
33
34
  var importSources = getImportSources(context);
34
35
  return {
35
36
  CallExpression: function CallExpression(node) {
36
- var _context$getScope = context.getScope(),
37
- references = _context$getScope.references;
37
+ var _getScope = getScope(context, node),
38
+ references = _getScope.references;
38
39
  if (isCss(node.callee, references, importSources) || isStyled(node.callee, references, importSources) || isKeyframes(node.callee, references, importSources) || isCssMap(node.callee, references, importSources) || isXcss(node.callee, references, importSources)) {
39
40
  estraverse.traverse(node, {
40
41
  enter: function enter(node) {
@@ -2,8 +2,8 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
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
4
  // eslint-disable-next-line @atlassian/tangerine/import/entry-points
5
-
6
5
  import esquery from 'esquery';
6
+ import { getScope } from '@atlaskit/eslint-utils/context-compat';
7
7
  import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
8
8
  import { createLintRule } from '../utils/create-rule';
9
9
  var schema = [{
@@ -36,8 +36,8 @@ export var rule = createLintRule({
36
36
  var importSources = getImportSources(context);
37
37
  return {
38
38
  CallExpression: function CallExpression(node) {
39
- var _context$getScope = context.getScope(),
40
- references = _context$getScope.references;
39
+ var _getScope = getScope(context, node),
40
+ references = _getScope.references;
41
41
  if (!hasStyleObjectArguments(node.callee, references, importSources)) {
42
42
  return;
43
43
  }
@@ -2,6 +2,7 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
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
4
  import esquery from 'esquery';
5
+ import { getScope } from '@atlaskit/eslint-utils/context-compat';
5
6
  import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
6
7
  import { importSources } from '@atlaskit/eslint-utils/schema';
7
8
  import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
@@ -28,8 +29,8 @@ export var rule = createLintRuleWithTypedConfig({
28
29
  var importSources = _ref.importSources;
29
30
  return {
30
31
  CallExpression: function CallExpression(node) {
31
- var _context$getScope = context.getScope(),
32
- references = _context$getScope.references;
32
+ var _getScope = getScope(context, node),
33
+ references = _getScope.references;
33
34
  if (!hasStyleObjectArguments(node.callee, references, importSources)) {
34
35
  return;
35
36
  }
@@ -8,6 +8,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
8
8
  import esquery from 'esquery';
9
9
  import estraverse from 'estraverse';
10
10
  import { getAllowedDynamicKeys, getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
11
+ import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
11
12
  import { findVariable } from '@atlaskit/eslint-utils/find-variable';
12
13
  import { getImportSources, hasStyleObjectArguments, isCxFunction } from '@atlaskit/eslint-utils/is-supported-import';
13
14
  import { createLintRule } from '../utils/create-rule';
@@ -54,7 +55,7 @@ var schema = [{
54
55
  var isIdentifierImported = function isIdentifierImported(identifier, context, functionAllowList, keysAllowList) {
55
56
  var variable = findVariable({
56
57
  identifier: identifier,
57
- sourceCode: context.getSourceCode()
58
+ sourceCode: getSourceCode(context)
58
59
  });
59
60
  if (!variable) {
60
61
  return false;
@@ -154,19 +155,19 @@ export var rule = createLintRule({
154
155
  if (callExpression.callee !== identifier) {
155
156
  return false;
156
157
  }
157
- return isCxFunction(identifier, context.getScope().references, importSources);
158
+ return isCxFunction(identifier, getScope(context, identifier).references, importSources);
158
159
  };
159
160
  return {
160
161
  // Checking css/cssMap/keyframes/styled/xcss calls
161
162
  CallExpression: function CallExpression(node) {
162
- var _context$getScope = context.getScope(),
163
- references = _context$getScope.references;
163
+ var _getScope = getScope(context, node),
164
+ references = _getScope.references;
164
165
  if (!hasStyleObjectArguments(node.callee, references, importSources)) {
165
166
  return;
166
167
  }
167
168
  node.arguments.forEach(checkForIdentifiers);
168
169
  },
169
- 'JSXAttribute[name.name=/^(style|css|xcss)$/]': function JSXAttributeNameNameStyleCssXcss$(jsxAttribute) {
170
+ 'JSXAttribute[name.name=/^(style|css|xcss)$/]': function JSXAttributeNameName_StyleCssXcss$_(jsxAttribute) {
170
171
  if (jsxAttribute.type !== 'JSXAttribute') {
171
172
  return;
172
173
  }
@@ -1,7 +1,8 @@
1
1
  import _toArray from "@babel/runtime/helpers/toArray";
2
2
  import cssSelectorParser, { isNesting, isPseudo } from 'postcss-selector-parser';
3
- import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
3
+ import { getScope } from '@atlaskit/eslint-utils/context-compat';
4
4
  import { importSources } from '@atlaskit/eslint-utils/schema';
5
+ import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
5
6
  import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
6
7
  var getCssSelector = function getCssSelector(key) {
7
8
  if (key.type === 'Literal' && typeof key.value === 'string') {
@@ -53,8 +54,8 @@ export var rule = createLintRuleWithTypedConfig({
53
54
  var importSources = _ref.importSources;
54
55
  return {
55
56
  CallExpression: function CallExpression(node) {
56
- var _context$getScope = context.getScope(),
57
- references = _context$getScope.references;
57
+ var _getScope = getScope(context, node),
58
+ references = _getScope.references;
58
59
  walkStyleProperties(node, references, importSources, function (_ref2) {
59
60
  var key = _ref2.key,
60
61
  value = _ref2.value;
@@ -1,4 +1,5 @@
1
- import { isStyled, getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
1
+ import { getAncestors, getScope } from '@atlaskit/eslint-utils/context-compat';
2
+ import { getImportSources, isStyled } from '@atlaskit/eslint-utils/is-supported-import';
2
3
  import { createLintRule } from '../utils/create-rule';
3
4
  export var rule = createLintRule({
4
5
  meta: {
@@ -16,7 +17,7 @@ export var rule = createLintRule({
16
17
  create: function create(context) {
17
18
  return {
18
19
  CallExpression: function CallExpression(node) {
19
- var references = context.getScope().references;
20
+ var references = getScope(context, node).references;
20
21
  var importSources = getImportSources(context);
21
22
  if (isStyled(node, references, importSources)) {
22
23
  context.report({
@@ -26,10 +27,10 @@ export var rule = createLintRule({
26
27
  }
27
28
  },
28
29
  MemberExpression: function MemberExpression(node) {
29
- var references = context.getScope().references;
30
+ var references = getScope(context, node).references;
30
31
  var importSources = getImportSources(context);
31
32
  if (node.object.type === 'Identifier' && isStyled(node.object, references, importSources)) {
32
- var parent = context.getAncestors().at(-1);
33
+ var parent = getAncestors(context, node).at(-1);
33
34
  if (parent && (parent.type === 'CallExpression' || parent.type === 'MemberExpression')) {
34
35
  return;
35
36
  }
@@ -1,4 +1,5 @@
1
1
  import cssSelectorParser from 'postcss-selector-parser';
2
+ import { getScope } from '@atlaskit/eslint-utils/context-compat';
2
3
  import { isXcss } from '@atlaskit/eslint-utils/is-supported-import';
3
4
  import { importSources } from '@atlaskit/eslint-utils/schema';
4
5
  import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
@@ -78,8 +79,8 @@ var rule = createLintRuleWithTypedConfig({
78
79
  });
79
80
  },
80
81
  CallExpression: function CallExpression(node) {
81
- var _context$getScope = context.getScope(),
82
- references = _context$getScope.references;
82
+ var _getScope = getScope(context, node),
83
+ references = _getScope.references;
83
84
  var isXcssCall = isXcss(node, references, config.importSources);
84
85
  walkStyleProperties(node, references, config.importSources, function (_ref) {
85
86
  var key = _ref.key,
@@ -1,4 +1,5 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
2
3
  export function getRangeFromNode(_ref) {
3
4
  var node = _ref.node,
4
5
  sourceNode = _ref.sourceNode;
@@ -26,7 +27,7 @@ export function getSourceLocationFromRange(context, _ref2) {
26
27
  var _ref3 = _slicedToArray(_ref2, 2),
27
28
  start = _ref3[0],
28
29
  end = _ref3[1];
29
- var sourceCode = context.getSourceCode();
30
+ var sourceCode = getSourceCode(context);
30
31
  return {
31
32
  start: sourceCode.getLocFromIndex(start),
32
33
  end: sourceCode.getLocFromIndex(end)
@@ -5,11 +5,12 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
5
  * This is because the API is likely to change and should not be considered stable.
6
6
  */
7
7
 
8
+ import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
8
9
  export function walkCssMap(_ref) {
9
10
  var context = _ref.context,
10
11
  importSources = _ref.importSources,
11
12
  visitor = _ref.visitor;
12
- var program = context.getSourceCode().ast;
13
+ var program = getSourceCode(context).ast;
13
14
  var importDeclaration = program.body.find(function (node) {
14
15
  return node.type === 'ImportDeclaration' && importSources.includes(node.source.value);
15
16
  });
@@ -19,9 +20,9 @@ export function walkCssMap(_ref) {
19
20
  if (!specifier) {
20
21
  return;
21
22
  }
22
- var _context$getSourceCod = context.getSourceCode().scopeManager.getDeclaredVariables(specifier),
23
- _context$getSourceCod2 = _slicedToArray(_context$getSourceCod, 1),
24
- variable = _context$getSourceCod2[0];
23
+ var _getSourceCode$scopeM = getSourceCode(context).scopeManager.getDeclaredVariables(specifier),
24
+ _getSourceCode$scopeM2 = _slicedToArray(_getSourceCode$scopeM, 1),
25
+ variable = _getSourceCode$scopeM2[0];
25
26
  if (!variable) {
26
27
  return;
27
28
  }
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable @atlassian/tangerine/import/entry-points */
2
2
 
3
+ import { getScope } from '@atlaskit/eslint-utils/context-compat';
3
4
  import { getImportSources, isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
4
5
  import { createLintRule } from '../utils/create-rule';
5
6
  import { messages } from './messages';
@@ -61,8 +62,8 @@ export var rule = createLintRule({
61
62
  var importSources = getImportSources(context);
62
63
  return {
63
64
  CallExpression: function CallExpression(node) {
64
- var _context$getScope = context.getScope(),
65
- references = _context$getScope.references;
65
+ var _getScope = getScope(context, node),
66
+ references = _getScope.references;
66
67
  if (!isCss(node.callee, references, importSources) && !isStyled(node.callee, references, importSources) && !isKeyframes(node.callee, references, importSources) && !isCssMap(node.callee, references, importSources) && !isXcss(node.callee, references, importSources)) {
67
68
  return;
68
69
  }
@@ -31,7 +31,7 @@ export var Linter = /*#__PURE__*/function () {
31
31
  /**
32
32
  * Wrapper around `context.report` to provide type checking on the message ID.
33
33
  */
34
- _createClass(Linter, [{
34
+ return _createClass(Linter, [{
35
35
  key: "report",
36
36
  value: function report(descriptor) {
37
37
  this.context.report(descriptor);
@@ -426,5 +426,4 @@ export var Linter = /*#__PURE__*/function () {
426
426
  this.lintArguments(this.baseNode.arguments);
427
427
  }
428
428
  }]);
429
- return Linter;
430
429
  }();
@@ -2,10 +2,11 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import { identifier, importDeclaration, importSpecifier, literal } from 'eslint-codemod-utils';
5
+ import { getAllComments } from '@atlaskit/eslint-utils/context-compat';
5
6
  import { findVariable } from '@atlaskit/eslint-utils/find-variable';
6
7
  import { createLintRule } from '../utils/create-rule';
7
- import { getFirstImportFromSource, isImportDefaultSpecifier, isImportNamespaceSpecifier, isImportSpecifier } from './utils';
8
8
  import { isSafeStyled, isSafeUsage } from './is-safe';
9
+ import { getFirstImportFromSource, isImportDefaultSpecifier, isImportNamespaceSpecifier, isImportSpecifier } from './utils';
9
10
  var SUPPORTED_EMOTION_IMPORTS = new Set(['css', 'keyframes', 'ClassNames', 'jsx']);
10
11
  var SUPPORTED_IMPORT_MAP = {
11
12
  '@emotion/core': SUPPORTED_EMOTION_IMPORTS,
@@ -56,7 +57,7 @@ export var rule = createLintRule({
56
57
  var config = readConfig(context);
57
58
  return {
58
59
  Program: function Program() {
59
- var pragma = context.getSourceCode().getAllComments().find(function (n) {
60
+ var pragma = getAllComments(context).find(function (n) {
60
61
  return n.value.includes('@jsxImportSource @emotion/react');
61
62
  });
62
63
  if (!pragma) {
@@ -1,4 +1,5 @@
1
1
  import { closestOfType } from 'eslint-codemod-utils';
2
+ import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
2
3
  import { findVariable } from '@atlaskit/eslint-utils/find-variable';
3
4
  export function isSafeUsage(_ref) {
4
5
  var context = _ref.context,
@@ -11,14 +12,14 @@ export function isSafeUsage(_ref) {
11
12
  if (importName === 'css') {
12
13
  var css = findVariable({
13
14
  identifier: specifier.local,
14
- sourceCode: context.getSourceCode()
15
+ sourceCode: getSourceCode(context)
15
16
  });
16
17
  return css !== null && isSafeCss(css);
17
18
  }
18
19
  if (importName === 'keyframes') {
19
20
  var keyframes = findVariable({
20
21
  identifier: specifier.local,
21
- sourceCode: context.getSourceCode()
22
+ sourceCode: getSourceCode(context)
22
23
  });
23
24
  return keyframes !== null && isSafeKeyframes(keyframes);
24
25
  }
@@ -1,5 +1,6 @@
1
+ import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
1
2
  export function getFirstImportFromSource(context, source) {
2
- return context.getSourceCode().ast.body.filter(isImportDeclaration).find(function (node) {
3
+ return getSourceCode(context).ast.body.filter(isImportDeclaration).find(function (node) {
3
4
  return node.source.value === source;
4
5
  });
5
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "1.0.4",
3
+ "version": "1.1.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",
@@ -40,10 +40,10 @@
40
40
  "./package.json": "./package.json"
41
41
  },
42
42
  "dependencies": {
43
- "@atlaskit/eslint-plugin-design-system": "^11.0.0",
44
- "@atlaskit/eslint-utils": "^1.7.0",
43
+ "@atlaskit/eslint-plugin-design-system": "^12.0.0",
44
+ "@atlaskit/eslint-utils": "^1.9.0",
45
45
  "@babel/runtime": "^7.0.0",
46
- "@typescript-eslint/utils": "^5.48.1",
46
+ "@typescript-eslint/utils": "^7.1.0",
47
47
  "ajv": "^6.12.6",
48
48
  "eslint-codemod-utils": "^1.8.6",
49
49
  "eslint-scope": "^8.0.0",
@@ -55,13 +55,14 @@
55
55
  },
56
56
  "devDependencies": {
57
57
  "@af/formatting": "*",
58
- "@atlaskit/ds-lib": "^3.3.0",
58
+ "@atlaskit/ds-lib": "^3.5.0",
59
59
  "@atlassian/codegen": "*",
60
60
  "@atlassian/ts-loader": "*",
61
61
  "@eslint/eslintrc": "^3.0.2",
62
62
  "@types/eslint": "^8.56.6",
63
63
  "@types/eslint__eslintrc": "^2.1.2",
64
64
  "@types/estraverse": "^5.1.7",
65
+ "@types/json-schema": "^7.0.15",
65
66
  "eslint": "^8.57.0",
66
67
  "lodash": "^4.17.21",
67
68
  "typescript": "~5.4.2"