@atlaskit/eslint-plugin-platform 2.0.0 → 2.0.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/eslint-plugin-platform
2
2
 
3
+ ## 2.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#182128](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/182128)
8
+ [`c00cde6230838`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c00cde6230838) -
9
+ fix v9 support regression
10
+ - Updated dependencies
11
+
12
+ ## 2.0.1
13
+
14
+ ### Patch Changes
15
+
16
+ - [`2034d96c50c40`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2034d96c50c40) -
17
+ fixed backwards compatibility with older versions of eslint
18
+
3
19
  ## 2.0.0
4
20
 
5
21
  ### Major Changes
@@ -11,7 +11,7 @@ var isCompiledAPI = function isCompiledAPI(context, node) {
11
11
  var importSources = (0, _isSupportedImport.getImportSources)(context);
12
12
  var _getScope = (0, _contextCompat.getScope)(context, node),
13
13
  references = _getScope.references;
14
- var ancestors = context.getAncestors();
14
+ var ancestors = (0, _contextCompat.getAncestors)(context, node);
15
15
  if (ancestors.some(function (ancestor) {
16
16
  return ancestor.type === 'CallExpression' && ancestor.callee && ((0, _isSupportedImport.isCompiled)(ancestor.callee, references, importSources) || (0, _isSupportedImport.isAtlasKitCSS)(ancestor.callee, references, importSources));
17
17
  })) {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getScope = void 0;
6
+ exports.getScope = exports.getAncestors = void 0;
7
7
  /**
8
8
  * TODO: Consider whether this should be replaced by ESLint's compat library.
9
9
  * Either way, this should be removed once we no longer need to support ESLint versions less than 8.40.
@@ -24,10 +24,24 @@ var getSourceCode = function getSourceCode(context) {
24
24
  * A compatibility layer to support older versions of ESLint.
25
25
  * `context.sourceCode.getScope()` is the preferred way to access Scope, as
26
26
  * `context.getScope()` was removed in v9.
27
+ * https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getscope()
27
28
  * @param context - The ESLint rule context
28
29
  * @param node - The node to get the scope for
29
30
  */
30
31
  var getScope = exports.getScope = function getScope(context, node) {
31
- var _getSourceCode$getSco, _getSourceCode;
32
- return (_getSourceCode$getSco = (_getSourceCode = getSourceCode(context)) === null || _getSourceCode === void 0 ? void 0 : _getSourceCode.getScope(node)) !== null && _getSourceCode$getSco !== void 0 ? _getSourceCode$getSco : context.getScope();
32
+ var _getSourceCode$getSco, _getSourceCode, _getSourceCode$getSco2;
33
+ return (_getSourceCode$getSco = (_getSourceCode = getSourceCode(context)) === null || _getSourceCode === void 0 || (_getSourceCode$getSco2 = _getSourceCode.getScope) === null || _getSourceCode$getSco2 === void 0 ? void 0 : _getSourceCode$getSco2.call(_getSourceCode, node)) !== null && _getSourceCode$getSco !== void 0 ? _getSourceCode$getSco : context.getScope();
34
+ };
35
+
36
+ /**
37
+ * A compatibility layer to support older versions of ESLint.
38
+ * `context.sourceCode.getAncestors()` is the preferred way to access Ancestors, as
39
+ * `context.getScope()` was removed in v9.
40
+ * https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getancestors()
41
+ * @param context - The ESLint rule context
42
+ * @param node - The node to get the scope for
43
+ */
44
+ var getAncestors = exports.getAncestors = function getAncestors(context, node) {
45
+ var _getSourceCode$getAnc, _getSourceCode2, _getSourceCode2$getAn;
46
+ return (_getSourceCode$getAnc = (_getSourceCode2 = getSourceCode(context)) === null || _getSourceCode2 === void 0 || (_getSourceCode2$getAn = _getSourceCode2.getAncestors) === null || _getSourceCode2$getAn === void 0 ? void 0 : _getSourceCode2$getAn.call(_getSourceCode2, node)) !== null && _getSourceCode$getAnc !== void 0 ? _getSourceCode$getAnc : context.getAncestors();
33
47
  };
@@ -1,5 +1,5 @@
1
1
  import { getImportSources, isCompiled, isAtlasKitCSS } from '@atlaskit/eslint-utils/is-supported-import';
2
- import { getScope } from '../../util/context-compat';
2
+ import { getAncestors, getScope } from '../../util/context-compat';
3
3
 
4
4
  // Checks if the function that holds the border property is using an import package that this rule is targeting
5
5
  const isCompiledAPI = (context, node) => {
@@ -7,7 +7,7 @@ const isCompiledAPI = (context, node) => {
7
7
  const {
8
8
  references
9
9
  } = getScope(context, node);
10
- const ancestors = context.getAncestors();
10
+ const ancestors = getAncestors(context, node);
11
11
  if (ancestors.some(ancestor => ancestor.type === 'CallExpression' && ancestor.callee && (isCompiled(ancestor.callee, references, importSources) || isAtlasKitCSS(ancestor.callee, references, importSources)))) {
12
12
  return true;
13
13
  }
@@ -18,10 +18,24 @@ const getSourceCode = context => {
18
18
  * A compatibility layer to support older versions of ESLint.
19
19
  * `context.sourceCode.getScope()` is the preferred way to access Scope, as
20
20
  * `context.getScope()` was removed in v9.
21
+ * https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getscope()
21
22
  * @param context - The ESLint rule context
22
23
  * @param node - The node to get the scope for
23
24
  */
24
25
  export const getScope = (context, node) => {
25
- var _getSourceCode$getSco, _getSourceCode;
26
- return (_getSourceCode$getSco = (_getSourceCode = getSourceCode(context)) === null || _getSourceCode === void 0 ? void 0 : _getSourceCode.getScope(node)) !== null && _getSourceCode$getSco !== void 0 ? _getSourceCode$getSco : context.getScope();
26
+ var _getSourceCode$getSco, _getSourceCode, _getSourceCode$getSco2;
27
+ return (_getSourceCode$getSco = (_getSourceCode = getSourceCode(context)) === null || _getSourceCode === void 0 ? void 0 : (_getSourceCode$getSco2 = _getSourceCode.getScope) === null || _getSourceCode$getSco2 === void 0 ? void 0 : _getSourceCode$getSco2.call(_getSourceCode, node)) !== null && _getSourceCode$getSco !== void 0 ? _getSourceCode$getSco : context.getScope();
28
+ };
29
+
30
+ /**
31
+ * A compatibility layer to support older versions of ESLint.
32
+ * `context.sourceCode.getAncestors()` is the preferred way to access Ancestors, as
33
+ * `context.getScope()` was removed in v9.
34
+ * https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getancestors()
35
+ * @param context - The ESLint rule context
36
+ * @param node - The node to get the scope for
37
+ */
38
+ export const getAncestors = (context, node) => {
39
+ var _getSourceCode$getAnc, _getSourceCode2, _getSourceCode2$getAn;
40
+ return (_getSourceCode$getAnc = (_getSourceCode2 = getSourceCode(context)) === null || _getSourceCode2 === void 0 ? void 0 : (_getSourceCode2$getAn = _getSourceCode2.getAncestors) === null || _getSourceCode2$getAn === void 0 ? void 0 : _getSourceCode2$getAn.call(_getSourceCode2, node)) !== null && _getSourceCode$getAnc !== void 0 ? _getSourceCode$getAnc : context.getAncestors();
27
41
  };
@@ -1,12 +1,12 @@
1
1
  import { getImportSources, isCompiled, isAtlasKitCSS } from '@atlaskit/eslint-utils/is-supported-import';
2
- import { getScope } from '../../util/context-compat';
2
+ import { getAncestors, getScope } from '../../util/context-compat';
3
3
 
4
4
  // Checks if the function that holds the border property is using an import package that this rule is targeting
5
5
  var isCompiledAPI = function isCompiledAPI(context, node) {
6
6
  var importSources = getImportSources(context);
7
7
  var _getScope = getScope(context, node),
8
8
  references = _getScope.references;
9
- var ancestors = context.getAncestors();
9
+ var ancestors = getAncestors(context, node);
10
10
  if (ancestors.some(function (ancestor) {
11
11
  return ancestor.type === 'CallExpression' && ancestor.callee && (isCompiled(ancestor.callee, references, importSources) || isAtlasKitCSS(ancestor.callee, references, importSources));
12
12
  })) {
@@ -18,10 +18,24 @@ var getSourceCode = function getSourceCode(context) {
18
18
  * A compatibility layer to support older versions of ESLint.
19
19
  * `context.sourceCode.getScope()` is the preferred way to access Scope, as
20
20
  * `context.getScope()` was removed in v9.
21
+ * https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getscope()
21
22
  * @param context - The ESLint rule context
22
23
  * @param node - The node to get the scope for
23
24
  */
24
25
  export var getScope = function getScope(context, node) {
25
- var _getSourceCode$getSco, _getSourceCode;
26
- return (_getSourceCode$getSco = (_getSourceCode = getSourceCode(context)) === null || _getSourceCode === void 0 ? void 0 : _getSourceCode.getScope(node)) !== null && _getSourceCode$getSco !== void 0 ? _getSourceCode$getSco : context.getScope();
26
+ var _getSourceCode$getSco, _getSourceCode, _getSourceCode$getSco2;
27
+ return (_getSourceCode$getSco = (_getSourceCode = getSourceCode(context)) === null || _getSourceCode === void 0 || (_getSourceCode$getSco2 = _getSourceCode.getScope) === null || _getSourceCode$getSco2 === void 0 ? void 0 : _getSourceCode$getSco2.call(_getSourceCode, node)) !== null && _getSourceCode$getSco !== void 0 ? _getSourceCode$getSco : context.getScope();
28
+ };
29
+
30
+ /**
31
+ * A compatibility layer to support older versions of ESLint.
32
+ * `context.sourceCode.getAncestors()` is the preferred way to access Ancestors, as
33
+ * `context.getScope()` was removed in v9.
34
+ * https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getancestors()
35
+ * @param context - The ESLint rule context
36
+ * @param node - The node to get the scope for
37
+ */
38
+ export var getAncestors = function getAncestors(context, node) {
39
+ var _getSourceCode$getAnc, _getSourceCode2, _getSourceCode2$getAn;
40
+ return (_getSourceCode$getAnc = (_getSourceCode2 = getSourceCode(context)) === null || _getSourceCode2 === void 0 || (_getSourceCode2$getAn = _getSourceCode2.getAncestors) === null || _getSourceCode2$getAn === void 0 ? void 0 : _getSourceCode2$getAn.call(_getSourceCode2, node)) !== null && _getSourceCode$getAnc !== void 0 ? _getSourceCode$getAnc : context.getAncestors();
27
41
  };
@@ -4,7 +4,17 @@ import type { Node } from 'estree';
4
4
  * A compatibility layer to support older versions of ESLint.
5
5
  * `context.sourceCode.getScope()` is the preferred way to access Scope, as
6
6
  * `context.getScope()` was removed in v9.
7
+ * https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getscope()
7
8
  * @param context - The ESLint rule context
8
9
  * @param node - The node to get the scope for
9
10
  */
10
11
  export declare const getScope: (context: Rule.RuleContext, node: Node) => Scope.Scope;
12
+ /**
13
+ * A compatibility layer to support older versions of ESLint.
14
+ * `context.sourceCode.getAncestors()` is the preferred way to access Ancestors, as
15
+ * `context.getScope()` was removed in v9.
16
+ * https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getancestors()
17
+ * @param context - The ESLint rule context
18
+ * @param node - The node to get the scope for
19
+ */
20
+ export declare const getAncestors: (context: Rule.RuleContext, node: Node) => Node[];
@@ -4,7 +4,17 @@ import type { Node } from 'estree';
4
4
  * A compatibility layer to support older versions of ESLint.
5
5
  * `context.sourceCode.getScope()` is the preferred way to access Scope, as
6
6
  * `context.getScope()` was removed in v9.
7
+ * https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getscope()
7
8
  * @param context - The ESLint rule context
8
9
  * @param node - The node to get the scope for
9
10
  */
10
11
  export declare const getScope: (context: Rule.RuleContext, node: Node) => Scope.Scope;
12
+ /**
13
+ * A compatibility layer to support older versions of ESLint.
14
+ * `context.sourceCode.getAncestors()` is the preferred way to access Ancestors, as
15
+ * `context.getScope()` was removed in v9.
16
+ * https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getancestors()
17
+ * @param context - The ESLint rule context
18
+ * @param node - The node to get the scope for
19
+ */
20
+ export declare const getAncestors: (context: Rule.RuleContext, node: Node) => Node[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-platform",
3
3
  "description": "The essential plugin for use with Atlassian frontend platform tools",
4
- "version": "2.0.0",
4
+ "version": "2.0.2",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "atlassian": {
7
7
  "team": "Build Infra",
@@ -31,9 +31,9 @@
31
31
  ".": "./src/index.tsx"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/eslint-utils": "^1.7.0",
34
+ "@atlaskit/eslint-utils": "^1.8.0",
35
35
  "@babel/runtime": "^7.0.0",
36
- "@compiled/eslint-plugin": "^0.17.0",
36
+ "@compiled/eslint-plugin": "^0.18.2",
37
37
  "@manypkg/find-root": "^1.1.0",
38
38
  "fuse.js": "^6.6.2",
39
39
  "read-pkg-up": "^7.0.1"
@@ -5,13 +5,13 @@ import {
5
5
  isCompiled,
6
6
  isAtlasKitCSS,
7
7
  } from '@atlaskit/eslint-utils/is-supported-import';
8
- import { getScope } from '../../util/context-compat';
8
+ import { getAncestors, getScope } from '../../util/context-compat';
9
9
 
10
10
  // Checks if the function that holds the border property is using an import package that this rule is targeting
11
11
  const isCompiledAPI = (context: Rule.RuleContext, node: Node): boolean => {
12
12
  const importSources = getImportSources(context);
13
13
  const { references } = getScope(context, node);
14
- const ancestors = context.getAncestors();
14
+ const ancestors = getAncestors(context, node);
15
15
  if (
16
16
  ancestors.some(
17
17
  (ancestor) =>
@@ -0,0 +1,122 @@
1
+ import type { Rule, Scope, SourceCode } from 'eslint';
2
+ import type { Node } from 'estree';
3
+
4
+ import { getAncestors, getScope } from '../context-compat';
5
+
6
+ describe('context-compat', () => {
7
+ describe('getAncestors', () => {
8
+ let context: Rule.RuleContext;
9
+ let node: Node;
10
+ let sourceCode: SourceCode;
11
+ let ancestors: Node[];
12
+
13
+ beforeEach(() => {
14
+ node = {} as Node;
15
+ ancestors = [];
16
+ sourceCode = {
17
+ getAncestors: jest.fn().mockReturnValue(ancestors),
18
+ } as unknown as SourceCode;
19
+ });
20
+
21
+ it('should return ancestor nodes from context.sourceCode.getAncestors if available', () => {
22
+ context = {
23
+ sourceCode,
24
+ } as unknown as Rule.RuleContext;
25
+
26
+ const result = getAncestors(context, node);
27
+ expect(result).toBe(ancestors);
28
+ expect(sourceCode.getAncestors).toHaveBeenCalledWith(node);
29
+ });
30
+
31
+ it('should return ancestors from context.getSourceCode().getAncestors if context.sourceCode is not available', () => {
32
+ context = {
33
+ getSourceCode: jest.fn().mockReturnValue(sourceCode),
34
+ } as unknown as Rule.RuleContext;
35
+
36
+ const result = getAncestors(context, node);
37
+ expect(result).toBe(ancestors);
38
+ expect(context.getSourceCode).toHaveBeenCalled();
39
+ expect(sourceCode.getAncestors).toHaveBeenCalledWith(node);
40
+ });
41
+
42
+ it('should return scope from context.getAncestors if neither context.sourceCode nor context.getSourceCode().getAncestors is available', () => {
43
+ context = {
44
+ getSourceCode: jest.fn().mockReturnValue({}),
45
+ getAncestors: jest.fn().mockReturnValue(ancestors),
46
+ } as unknown as Rule.RuleContext;
47
+
48
+ const result = getAncestors(context, node);
49
+ expect(result).toBe(ancestors);
50
+ expect(context.getAncestors).toHaveBeenCalled();
51
+ });
52
+
53
+ it('should return scope from context.getAncestors if context.sourceCode does not have getAncestors', () => {
54
+ context = {
55
+ sourceCode: {},
56
+ getAncestors: jest.fn().mockReturnValue(ancestors),
57
+ } as unknown as Rule.RuleContext;
58
+
59
+ const result = getAncestors(context, node);
60
+ expect(result).toBe(ancestors);
61
+ expect(context.getAncestors).toHaveBeenCalled();
62
+ });
63
+ });
64
+
65
+ describe('getScope', () => {
66
+ let context: Rule.RuleContext;
67
+ let node: Node;
68
+ let sourceCode: SourceCode;
69
+ let scope: Scope.Scope;
70
+
71
+ beforeEach(() => {
72
+ node = {} as Node;
73
+ scope = {} as Scope.Scope;
74
+ sourceCode = {
75
+ getScope: jest.fn().mockReturnValue(scope),
76
+ } as unknown as SourceCode;
77
+ });
78
+
79
+ it('should return scope from context.sourceCode.getScope if available', () => {
80
+ context = {
81
+ sourceCode,
82
+ } as unknown as Rule.RuleContext;
83
+
84
+ const result = getScope(context, node);
85
+ expect(result).toBe(scope);
86
+ expect(sourceCode.getScope).toHaveBeenCalledWith(node);
87
+ });
88
+
89
+ it('should return scope from context.getSourceCode().getScope if context.sourceCode is not available', () => {
90
+ context = {
91
+ getSourceCode: jest.fn().mockReturnValue(sourceCode),
92
+ } as unknown as Rule.RuleContext;
93
+
94
+ const result = getScope(context, node);
95
+ expect(result).toBe(scope);
96
+ expect(context.getSourceCode).toHaveBeenCalled();
97
+ expect(sourceCode.getScope).toHaveBeenCalledWith(node);
98
+ });
99
+
100
+ it('should return scope from context.getScope if neither context.sourceCode nor context.getSourceCode().getScope is available', () => {
101
+ context = {
102
+ getSourceCode: jest.fn().mockReturnValue({}),
103
+ getScope: jest.fn().mockReturnValue(scope),
104
+ } as unknown as Rule.RuleContext;
105
+
106
+ const result = getScope(context, node);
107
+ expect(result).toBe(scope);
108
+ expect(context.getScope).toHaveBeenCalled();
109
+ });
110
+
111
+ it('should return scope from context.getScope if context.sourceCode does not have getScope', () => {
112
+ context = {
113
+ sourceCode: {},
114
+ getScope: jest.fn().mockReturnValue(scope),
115
+ } as unknown as Rule.RuleContext;
116
+
117
+ const result = getScope(context, node);
118
+ expect(result).toBe(scope);
119
+ expect(context.getScope).toHaveBeenCalled();
120
+ });
121
+ });
122
+ });
@@ -20,9 +20,22 @@ const getSourceCode = (context: Rule.RuleContext): SourceCode => {
20
20
  * A compatibility layer to support older versions of ESLint.
21
21
  * `context.sourceCode.getScope()` is the preferred way to access Scope, as
22
22
  * `context.getScope()` was removed in v9.
23
+ * https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getscope()
23
24
  * @param context - The ESLint rule context
24
25
  * @param node - The node to get the scope for
25
26
  */
26
27
  export const getScope = (context: Rule.RuleContext, node: Node): Scope.Scope => {
27
- return getSourceCode(context)?.getScope(node) ?? context.getScope();
28
+ return getSourceCode(context)?.getScope?.(node) ?? context.getScope();
29
+ };
30
+
31
+ /**
32
+ * A compatibility layer to support older versions of ESLint.
33
+ * `context.sourceCode.getAncestors()` is the preferred way to access Ancestors, as
34
+ * `context.getScope()` was removed in v9.
35
+ * https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#context.getancestors()
36
+ * @param context - The ESLint rule context
37
+ * @param node - The node to get the scope for
38
+ */
39
+ export const getAncestors = (context: Rule.RuleContext, node: Node): Node[] => {
40
+ return getSourceCode(context)?.getAncestors?.(node) ?? context.getAncestors();
28
41
  };