@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
@@ -38,7 +38,7 @@ var Linter = exports.Linter = /*#__PURE__*/function () {
38
38
  /**
39
39
  * Wrapper around `context.report` to provide type checking on the message ID.
40
40
  */
41
- (0, _createClass2.default)(Linter, [{
41
+ return (0, _createClass2.default)(Linter, [{
42
42
  key: "report",
43
43
  value: function report(descriptor) {
44
44
  this.context.report(descriptor);
@@ -433,5 +433,4 @@ var Linter = exports.Linter = /*#__PURE__*/function () {
433
433
  this.lintArguments(this.baseNode.arguments);
434
434
  }
435
435
  }]);
436
- return Linter;
437
436
  }();
@@ -9,10 +9,11 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
9
9
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
11
  var _eslintCodemodUtils = require("eslint-codemod-utils");
12
+ var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
12
13
  var _findVariable = require("@atlaskit/eslint-utils/find-variable");
13
14
  var _createRule = require("../utils/create-rule");
14
- var _utils = require("./utils");
15
15
  var _isSafe = require("./is-safe");
16
+ var _utils = require("./utils");
16
17
  var SUPPORTED_EMOTION_IMPORTS = new Set(['css', 'keyframes', 'ClassNames', 'jsx']);
17
18
  var SUPPORTED_IMPORT_MAP = {
18
19
  '@emotion/core': SUPPORTED_EMOTION_IMPORTS,
@@ -63,7 +64,7 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
63
64
  var config = readConfig(context);
64
65
  return {
65
66
  Program: function Program() {
66
- var pragma = context.getSourceCode().getAllComments().find(function (n) {
67
+ var pragma = (0, _contextCompat.getAllComments)(context).find(function (n) {
67
68
  return n.value.includes('@jsxImportSource @emotion/react');
68
69
  });
69
70
  if (!pragma) {
@@ -8,6 +8,7 @@ exports.isSafeKeyframes = isSafeKeyframes;
8
8
  exports.isSafeStyled = isSafeStyled;
9
9
  exports.isSafeUsage = isSafeUsage;
10
10
  var _eslintCodemodUtils = require("eslint-codemod-utils");
11
+ var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
11
12
  var _findVariable = require("@atlaskit/eslint-utils/find-variable");
12
13
  function isSafeUsage(_ref) {
13
14
  var context = _ref.context,
@@ -20,14 +21,14 @@ function isSafeUsage(_ref) {
20
21
  if (importName === 'css') {
21
22
  var css = (0, _findVariable.findVariable)({
22
23
  identifier: specifier.local,
23
- sourceCode: context.getSourceCode()
24
+ sourceCode: (0, _contextCompat.getSourceCode)(context)
24
25
  });
25
26
  return css !== null && isSafeCss(css);
26
27
  }
27
28
  if (importName === 'keyframes') {
28
29
  var keyframes = (0, _findVariable.findVariable)({
29
30
  identifier: specifier.local,
30
- sourceCode: context.getSourceCode()
31
+ sourceCode: (0, _contextCompat.getSourceCode)(context)
31
32
  });
32
33
  return keyframes !== null && isSafeKeyframes(keyframes);
33
34
  }
@@ -7,8 +7,9 @@ exports.getFirstImportFromSource = getFirstImportFromSource;
7
7
  exports.isImportDefaultSpecifier = isImportDefaultSpecifier;
8
8
  exports.isImportNamespaceSpecifier = isImportNamespaceSpecifier;
9
9
  exports.isImportSpecifier = isImportSpecifier;
10
+ var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
10
11
  function getFirstImportFromSource(context, source) {
11
- return context.getSourceCode().ast.body.filter(isImportDeclaration).find(function (node) {
12
+ return (0, _contextCompat.getSourceCode)(context).ast.body.filter(isImportDeclaration).find(function (node) {
12
13
  return node.source.value === source;
13
14
  });
14
15
  }
@@ -1,3 +1,4 @@
1
+ import { getAncestors, getScope } from '@atlaskit/eslint-utils/context-compat';
1
2
  import { getImportSources, isCompiled } from '@atlaskit/eslint-utils/is-supported-import';
2
3
  import { createLintRule } from '../utils/create-rule';
3
4
  const isIdentifierReferenced = (hasImportSpecifier, node, references) => references.some(reference => {
@@ -58,8 +59,8 @@ export const rule = createLintRule({
58
59
  'CallExpression Identifier': node => {
59
60
  const {
60
61
  references
61
- } = context.getScope();
62
- const ancestors = context.getAncestors();
62
+ } = getScope(context, node);
63
+ const ancestors = getAncestors(context, node);
63
64
 
64
65
  // Check if ancestor node is a call expression to Compiled
65
66
  if (ancestors.some(ancestor => ancestor.type === 'CallExpression' && ancestor.callee && isCompiled(ancestor.callee, references, importSources))) {
@@ -73,8 +74,8 @@ export const rule = createLintRule({
73
74
  'TaggedTemplateExpression Identifier': node => {
74
75
  const {
75
76
  references
76
- } = context.getScope();
77
- const ancestors = context.getAncestors();
77
+ } = getScope(context, node);
78
+ const ancestors = getAncestors(context, node);
78
79
 
79
80
  // Check if ancestor node is a tagged template expression to Compiled
80
81
  if (ancestors.some(ancestor => ancestor.type === 'TaggedTemplateExpression' && ancestor.tag && isCompiled(ancestor.tag, references, importSources))) {
@@ -1,6 +1,7 @@
1
1
  import { isNodeOfType } from 'eslint-codemod-utils';
2
2
  import { analyze } from 'eslint-scope';
3
3
  import ESTraverse from 'estraverse';
4
+ import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
4
5
  import { isEmotion, isStyledComponents } from '@atlaskit/eslint-utils/is-supported-import';
5
6
  import { createLintRule } from '../utils/create-rule';
6
7
 
@@ -162,7 +163,7 @@ const lintArguments = (context, args) => {
162
163
  ESTraverse.traverse(property.value, {
163
164
  enter: function (node, _parent) {
164
165
  if (node.type === 'ArrowFunctionExpression') {
165
- const propNames = parseArrowFunctionExpression(node, context.getSourceCode());
166
+ const propNames = parseArrowFunctionExpression(node, getSourceCode(context));
166
167
  if (!propNames) {
167
168
  // We've encountered a CSS value we don't recognise, skip.
168
169
  return;
@@ -191,7 +192,7 @@ const lintArguments = (context, args) => {
191
192
  node: argument,
192
193
  messageId: 'unsupported-prop-syntax',
193
194
  fix(fixer) {
194
- const sourceCode = context.getSourceCode();
195
+ const sourceCode = getSourceCode(context);
195
196
  return fixPropsObjectUsages(fixer, sourceCode, argument,
196
197
  // The
197
198
  // allProps.some((propUsage) => !propUsage.valid)
@@ -283,7 +284,9 @@ export const rule = createLintRule({
283
284
  return {
284
285
  CallExpression: node => {
285
286
  var _node$parent, _node$parent2;
286
- const references = context.getScope().references;
287
+ const {
288
+ references
289
+ } = getScope(context, node);
287
290
 
288
291
  // Rule should ignore .attrs() calls
289
292
  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
  const isParameter = (context, identifier) => {
6
7
  var _findVariable;
7
8
  const 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 @@ const isParameter = (context, identifier) => {
17
18
  const isIdentifierAllowed = (context, identifier) => {
18
19
  var _variable$identifiers, _variable$identifiers2;
19
20
  const variable = findVariable({
20
- sourceCode: context.getSourceCode(),
21
+ sourceCode: getSourceCode(context),
21
22
  identifier: identifier
22
23
  });
23
24
  if (!variable) {
@@ -25,8 +26,6 @@ const isIdentifierAllowed = (context, identifier) => {
25
26
  }
26
27
  const 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 ? void 0 : (_variable$identifiers2 = _variable$identifiers.parent) === null || _variable$identifiers2 === void 0 ? void 0 : _variable$identifiers2.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
  const 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
  const 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) {
@@ -135,14 +135,15 @@ export const rule = createLintRule({
135
135
  create(context) {
136
136
  return {
137
137
  'JSXAttribute[name.name="style"] > JSXExpressionContainer': node => {
138
- var _node$expression$expr;
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
- let expression;
145
+ let expression = null;
146
+ let 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,57 @@ export const 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, _variable$defs$, _variable$defs$$node;
160
+ /*
161
+ * Example:
162
+ * ```tsx
163
+ * const style = { width: 100 };
164
+ * <div style={style} />
165
+ * ```
166
+ */
167
+ const 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
+ const hopefulObjectExpression = variable === null || variable === void 0 ? void 0 : (_variable$defs = variable.defs) === null || _variable$defs === void 0 ? void 0 : (_variable$defs$ = _variable$defs[0]) === null || _variable$defs$ === void 0 ? void 0 : (_variable$defs$$node = _variable$defs$.node) === null || _variable$defs$$node === void 0 ? void 0 : _variable$defs$$node.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(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(value => !isPropertyValueAllowed(value, context))) {
166
192
  context.report({
167
- node: value,
193
+ node: node.expression,
168
194
  messageId: 'enforce-style-prop'
169
195
  });
170
196
  }
171
- });
197
+ } else {
198
+ // Typically we want to report on the individual styles, eg.
199
+ // `color: 'red'` in `style={{ color: 'red' }}` should get the error
200
+ expression.properties.forEach(value => {
201
+ if (!isPropertyValueAllowed(value, context)) {
202
+ context.report({
203
+ node: value,
204
+ messageId: 'enforce-style-prop'
205
+ });
206
+ }
207
+ });
208
+ }
172
209
  }
173
210
  };
174
211
  }
@@ -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
  const IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
4
5
  function getParentJSXAttribute(node) {
5
6
  let parent = node.parent;
@@ -27,7 +28,7 @@ export const rule = createLintRule({
27
28
  create(context) {
28
29
  return {
29
30
  'CallExpression[callee.name="cx"]': 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
  const parentJSXAttribute = getParentJSXAttribute(node);
32
33
  const propName = parentJSXAttribute === null || parentJSXAttribute === void 0 ? void 0 : parentJSXAttribute.name.name.toString();
33
34
  if (propName && /[xX]css$/.test(propName)) {
@@ -1,5 +1,6 @@
1
1
  // eslint-disable-next-line @atlassian/tangerine/import/entry-points
2
2
 
3
+ import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
3
4
  import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
4
5
  import { createLintRule } from '../utils/create-rule';
5
6
  const schema = [{
@@ -35,7 +36,7 @@ export const rule = createLintRule({
35
36
  CallExpression(node) {
36
37
  const {
37
38
  references
38
- } = context.getScope();
39
+ } = getScope(context, node);
39
40
  if (!hasStyleObjectArguments(node.callee, references, importSources)) {
40
41
  return;
41
42
  }
@@ -57,7 +58,7 @@ export const rule = createLintRule({
57
58
  */
58
59
  return null;
59
60
  }
60
- const items = argument.elements.filter(value => value !== null).map(element => context.getSourceCode().getText(element));
61
+ const items = argument.elements.filter(value => value !== null).map(element => getSourceCode(context).getText(element));
61
62
  return fixer.replaceText(argument, items.join(', '));
62
63
  }
63
64
  });
@@ -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
  const schema = [{
@@ -35,7 +36,7 @@ export const rule = createLintRule({
35
36
  CallExpression(node) {
36
37
  const {
37
38
  references
38
- } = context.getScope();
39
+ } = getScope(context, node);
39
40
  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)) {
40
41
  estraverse.traverse(node, {
41
42
  enter(node) {
@@ -1,6 +1,6 @@
1
1
  // eslint-disable-next-line @atlassian/tangerine/import/entry-points
2
-
3
2
  import esquery from 'esquery';
3
+ import { getScope } from '@atlaskit/eslint-utils/context-compat';
4
4
  import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
5
5
  import { createLintRule } from '../utils/create-rule';
6
6
  const schema = [{
@@ -35,7 +35,7 @@ export const rule = createLintRule({
35
35
  CallExpression(node) {
36
36
  const {
37
37
  references
38
- } = context.getScope();
38
+ } = getScope(context, node);
39
39
  if (!hasStyleObjectArguments(node.callee, references, importSources)) {
40
40
  return;
41
41
  }
@@ -1,4 +1,5 @@
1
1
  import esquery from 'esquery';
2
+ import { getScope } from '@atlaskit/eslint-utils/context-compat';
2
3
  import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
3
4
  import { importSources } from '@atlaskit/eslint-utils/schema';
4
5
  import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
@@ -28,7 +29,7 @@ export const rule = createLintRuleWithTypedConfig({
28
29
  CallExpression(node) {
29
30
  const {
30
31
  references
31
- } = context.getScope();
32
+ } = getScope(context, node);
32
33
  if (!hasStyleObjectArguments(node.callee, references, importSources)) {
33
34
  return;
34
35
  }
@@ -5,6 +5,7 @@
5
5
  import esquery from 'esquery';
6
6
  import estraverse from 'estraverse';
7
7
  import { getAllowedDynamicKeys, getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
8
+ import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
8
9
  import { findVariable } from '@atlaskit/eslint-utils/find-variable';
9
10
  import { getImportSources, hasStyleObjectArguments, isCxFunction } from '@atlaskit/eslint-utils/is-supported-import';
10
11
  import { createLintRule } from '../utils/create-rule';
@@ -51,7 +52,7 @@ const schema = [{
51
52
  const isIdentifierImported = (identifier, context, functionAllowList, keysAllowList) => {
52
53
  const variable = findVariable({
53
54
  identifier: identifier,
54
- sourceCode: context.getSourceCode()
55
+ sourceCode: getSourceCode(context)
55
56
  });
56
57
  if (!variable) {
57
58
  return false;
@@ -141,14 +142,14 @@ export const rule = createLintRule({
141
142
  if (callExpression.callee !== identifier) {
142
143
  return false;
143
144
  }
144
- return isCxFunction(identifier, context.getScope().references, importSources);
145
+ return isCxFunction(identifier, getScope(context, identifier).references, importSources);
145
146
  };
146
147
  return {
147
148
  // Checking css/cssMap/keyframes/styled/xcss calls
148
149
  CallExpression(node) {
149
150
  const {
150
151
  references
151
- } = context.getScope();
152
+ } = getScope(context, node);
152
153
  if (!hasStyleObjectArguments(node.callee, references, importSources)) {
153
154
  return;
154
155
  }
@@ -1,6 +1,7 @@
1
1
  import cssSelectorParser, { isNesting, isPseudo } from 'postcss-selector-parser';
2
- import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
2
+ import { getScope } from '@atlaskit/eslint-utils/context-compat';
3
3
  import { importSources } from '@atlaskit/eslint-utils/schema';
4
+ import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
4
5
  import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
5
6
  const getCssSelector = key => {
6
7
  if (key.type === 'Literal' && typeof key.value === 'string') {
@@ -51,7 +52,7 @@ export const rule = createLintRuleWithTypedConfig({
51
52
  CallExpression(node) {
52
53
  const {
53
54
  references
54
- } = context.getScope();
55
+ } = getScope(context, node);
55
56
  walkStyleProperties(node, references, importSources, ({
56
57
  key,
57
58
  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 const rule = createLintRule({
4
5
  meta: {
@@ -16,7 +17,7 @@ export const rule = createLintRule({
16
17
  create(context) {
17
18
  return {
18
19
  CallExpression: node => {
19
- const references = context.getScope().references;
20
+ const references = getScope(context, node).references;
20
21
  const importSources = getImportSources(context);
21
22
  if (isStyled(node, references, importSources)) {
22
23
  context.report({
@@ -26,10 +27,10 @@ export const rule = createLintRule({
26
27
  }
27
28
  },
28
29
  MemberExpression: node => {
29
- const references = context.getScope().references;
30
+ const references = getScope(context, node).references;
30
31
  const importSources = getImportSources(context);
31
32
  if (node.object.type === 'Identifier' && isStyled(node.object, references, importSources)) {
32
- const parent = context.getAncestors().at(-1);
33
+ const 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';
@@ -82,7 +83,7 @@ const rule = createLintRuleWithTypedConfig({
82
83
  CallExpression(node) {
83
84
  const {
84
85
  references
85
- } = context.getScope();
86
+ } = getScope(context, node);
86
87
  const isXcssCall = isXcss(node, references, config.importSources);
87
88
  walkStyleProperties(node, references, config.importSources, ({
88
89
  key,
@@ -1,3 +1,4 @@
1
+ import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
1
2
  export function getRangeFromNode({
2
3
  node,
3
4
  sourceNode
@@ -23,7 +24,7 @@ export function getRangeFromNode({
23
24
  return [start, end];
24
25
  }
25
26
  export function getSourceLocationFromRange(context, [start, end]) {
26
- const sourceCode = context.getSourceCode();
27
+ const sourceCode = getSourceCode(context);
27
28
  return {
28
29
  start: sourceCode.getLocFromIndex(start),
29
30
  end: sourceCode.getLocFromIndex(end)
@@ -4,18 +4,19 @@
4
4
  * This is because the API is likely to change and should not be considered stable.
5
5
  */
6
6
 
7
+ import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
7
8
  export function walkCssMap({
8
9
  context,
9
10
  importSources,
10
11
  visitor
11
12
  }) {
12
- const program = context.getSourceCode().ast;
13
+ const program = getSourceCode(context).ast;
13
14
  const importDeclaration = program.body.find(node => node.type === 'ImportDeclaration' && importSources.includes(node.source.value));
14
15
  const specifier = importDeclaration === null || importDeclaration === void 0 ? void 0 : importDeclaration.specifiers.find(specifier => specifier.type === 'ImportSpecifier' && specifier.imported.name === 'cssMap');
15
16
  if (!specifier) {
16
17
  return;
17
18
  }
18
- const [variable] = context.getSourceCode().scopeManager.getDeclaredVariables(specifier);
19
+ const [variable] = getSourceCode(context).scopeManager.getDeclaredVariables(specifier);
19
20
  if (!variable) {
20
21
  return;
21
22
  }
@@ -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';
@@ -63,7 +64,7 @@ export const rule = createLintRule({
63
64
  CallExpression(node) {
64
65
  const {
65
66
  references
66
- } = context.getScope();
67
+ } = getScope(context, node);
67
68
  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)) {
68
69
  return;
69
70
  }
@@ -1,8 +1,9 @@
1
1
  import { identifier, importDeclaration, importSpecifier, literal } from 'eslint-codemod-utils';
2
+ import { getAllComments } from '@atlaskit/eslint-utils/context-compat';
2
3
  import { findVariable } from '@atlaskit/eslint-utils/find-variable';
3
4
  import { createLintRule } from '../utils/create-rule';
4
- import { getFirstImportFromSource, isImportDefaultSpecifier, isImportNamespaceSpecifier, isImportSpecifier } from './utils';
5
5
  import { isSafeStyled, isSafeUsage } from './is-safe';
6
+ import { getFirstImportFromSource, isImportDefaultSpecifier, isImportNamespaceSpecifier, isImportSpecifier } from './utils';
6
7
  const SUPPORTED_EMOTION_IMPORTS = new Set(['css', 'keyframes', 'ClassNames', 'jsx']);
7
8
  const SUPPORTED_IMPORT_MAP = {
8
9
  '@emotion/core': SUPPORTED_EMOTION_IMPORTS,
@@ -51,7 +52,7 @@ export const rule = createLintRule({
51
52
  const config = readConfig(context);
52
53
  return {
53
54
  Program() {
54
- const pragma = context.getSourceCode().getAllComments().find(n => n.value.includes('@jsxImportSource @emotion/react'));
55
+ const pragma = getAllComments(context).find(n => n.value.includes('@jsxImportSource @emotion/react'));
55
56
  if (!pragma) {
56
57
  return;
57
58
  }
@@ -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({
4
5
  context,
@@ -12,14 +13,14 @@ export function isSafeUsage({
12
13
  if (importName === 'css') {
13
14
  const css = findVariable({
14
15
  identifier: specifier.local,
15
- sourceCode: context.getSourceCode()
16
+ sourceCode: getSourceCode(context)
16
17
  });
17
18
  return css !== null && isSafeCss(css);
18
19
  }
19
20
  if (importName === 'keyframes') {
20
21
  const keyframes = findVariable({
21
22
  identifier: specifier.local,
22
- sourceCode: context.getSourceCode()
23
+ sourceCode: getSourceCode(context)
23
24
  });
24
25
  return keyframes !== null && isSafeKeyframes(keyframes);
25
26
  }
@@ -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(node => node.source.value === source);
3
+ return getSourceCode(context).ast.body.filter(isImportDeclaration).find(node => node.source.value === source);
3
4
  }
4
5
  function isImportDeclaration(node) {
5
6
  return node.type === 'ImportDeclaration';
@@ -1,3 +1,4 @@
1
+ import { getAncestors, getScope } from '@atlaskit/eslint-utils/context-compat';
1
2
  import { getImportSources, isCompiled } from '@atlaskit/eslint-utils/is-supported-import';
2
3
  import { createLintRule } from '../utils/create-rule';
3
4
  var isIdentifierReferenced = function isIdentifierReferenced(hasImportSpecifier, node, references) {
@@ -57,10 +58,10 @@ export var rule = createLintRule({
57
58
  create: function create(context) {
58
59
  var importSources = getImportSources(context);
59
60
  return {
60
- 'CallExpression Identifier': function CallExpressionIdentifier(node) {
61
- var _context$getScope = context.getScope(),
62
- references = _context$getScope.references;
63
- var ancestors = context.getAncestors();
61
+ 'CallExpression Identifier': function CallExpression_Identifier(node) {
62
+ var _getScope = getScope(context, node),
63
+ references = _getScope.references;
64
+ var ancestors = getAncestors(context, node);
64
65
 
65
66
  // Check if ancestor node is a call expression to Compiled
66
67
  if (ancestors.some(function (ancestor) {
@@ -73,10 +74,10 @@ export var rule = createLintRule({
73
74
  }
74
75
  }
75
76
  },
76
- 'TaggedTemplateExpression Identifier': function TaggedTemplateExpressionIdentifier(node) {
77
- var _context$getScope2 = context.getScope(),
78
- references = _context$getScope2.references;
79
- var ancestors = context.getAncestors();
77
+ 'TaggedTemplateExpression Identifier': function TaggedTemplateExpression_Identifier(node) {
78
+ var _getScope2 = getScope(context, node),
79
+ references = _getScope2.references;
80
+ var ancestors = getAncestors(context, node);
80
81
 
81
82
  // Check if ancestor node is a tagged template expression to Compiled
82
83
  if (ancestors.some(function (ancestor) {