@atlaskit/eslint-plugin-platform 2.0.0 → 2.0.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.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/rules/util/context-compat.js +2 -2
- package/dist/es2019/rules/util/context-compat.js +2 -2
- package/dist/esm/rules/util/context-compat.js +2 -2
- package/package.json +1 -1
- package/src/rules/util/__tests__/context-compat.test.ts +64 -0
- package/src/rules/util/context-compat.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-platform
|
|
2
2
|
|
|
3
|
+
## 2.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`2034d96c50c40`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2034d96c50c40) -
|
|
8
|
+
fixed backwards compatibility with older versions of eslint
|
|
9
|
+
|
|
3
10
|
## 2.0.0
|
|
4
11
|
|
|
5
12
|
### Major Changes
|
|
@@ -28,6 +28,6 @@ var getSourceCode = function getSourceCode(context) {
|
|
|
28
28
|
* @param node - The node to get the scope for
|
|
29
29
|
*/
|
|
30
30
|
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.
|
|
31
|
+
var _getSourceCode$getSco, _getSourceCode, _getSourceCode$getSco2;
|
|
32
|
+
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();
|
|
33
33
|
};
|
|
@@ -22,6 +22,6 @@ const getSourceCode = context => {
|
|
|
22
22
|
* @param node - The node to get the scope for
|
|
23
23
|
*/
|
|
24
24
|
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();
|
|
25
|
+
var _getSourceCode$getSco, _getSourceCode, _getSourceCode$getSco2;
|
|
26
|
+
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();
|
|
27
27
|
};
|
|
@@ -22,6 +22,6 @@ var getSourceCode = function getSourceCode(context) {
|
|
|
22
22
|
* @param node - The node to get the scope for
|
|
23
23
|
*/
|
|
24
24
|
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.
|
|
25
|
+
var _getSourceCode$getSco, _getSourceCode, _getSourceCode$getSco2;
|
|
26
|
+
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();
|
|
27
27
|
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Rule, Scope, SourceCode } from 'eslint';
|
|
2
|
+
import type { Node } from 'estree';
|
|
3
|
+
|
|
4
|
+
import { getScope } from '../context-compat';
|
|
5
|
+
|
|
6
|
+
describe('context-compat', () => {
|
|
7
|
+
describe('getScope', () => {
|
|
8
|
+
let context: Rule.RuleContext;
|
|
9
|
+
let node: Node;
|
|
10
|
+
let sourceCode: SourceCode;
|
|
11
|
+
let scope: Scope.Scope;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
node = {} as Node;
|
|
15
|
+
scope = {} as Scope.Scope;
|
|
16
|
+
sourceCode = {
|
|
17
|
+
getScope: jest.fn().mockReturnValue(scope),
|
|
18
|
+
} as unknown as SourceCode;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should return scope from context.sourceCode.getScope if available', () => {
|
|
22
|
+
context = {
|
|
23
|
+
sourceCode,
|
|
24
|
+
} as unknown as Rule.RuleContext;
|
|
25
|
+
|
|
26
|
+
const result = getScope(context, node);
|
|
27
|
+
expect(result).toBe(scope);
|
|
28
|
+
expect(sourceCode.getScope).toHaveBeenCalledWith(node);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should return scope from context.getSourceCode().getScope if context.sourceCode is not available', () => {
|
|
32
|
+
context = {
|
|
33
|
+
getSourceCode: jest.fn().mockReturnValue(sourceCode),
|
|
34
|
+
} as unknown as Rule.RuleContext;
|
|
35
|
+
|
|
36
|
+
const result = getScope(context, node);
|
|
37
|
+
expect(result).toBe(scope);
|
|
38
|
+
expect(context.getSourceCode).toHaveBeenCalled();
|
|
39
|
+
expect(sourceCode.getScope).toHaveBeenCalledWith(node);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should return scope from context.getScope if neither context.sourceCode nor context.getSourceCode().getScope is available', () => {
|
|
43
|
+
context = {
|
|
44
|
+
getSourceCode: jest.fn().mockReturnValue({}),
|
|
45
|
+
getScope: jest.fn().mockReturnValue(scope),
|
|
46
|
+
} as unknown as Rule.RuleContext;
|
|
47
|
+
|
|
48
|
+
const result = getScope(context, node);
|
|
49
|
+
expect(result).toBe(scope);
|
|
50
|
+
expect(context.getScope).toHaveBeenCalled();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should return scope from context.getScope if context.sourceCode does not have getScope', () => {
|
|
54
|
+
context = {
|
|
55
|
+
sourceCode: {},
|
|
56
|
+
getScope: jest.fn().mockReturnValue(scope),
|
|
57
|
+
} as unknown as Rule.RuleContext;
|
|
58
|
+
|
|
59
|
+
const result = getScope(context, node);
|
|
60
|
+
expect(result).toBe(scope);
|
|
61
|
+
expect(context.getScope).toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -24,5 +24,5 @@ const getSourceCode = (context: Rule.RuleContext): SourceCode => {
|
|
|
24
24
|
* @param node - The node to get the scope for
|
|
25
25
|
*/
|
|
26
26
|
export const getScope = (context: Rule.RuleContext, node: Node): Scope.Scope => {
|
|
27
|
-
return getSourceCode(context)?.getScope(node) ?? context.getScope();
|
|
27
|
+
return getSourceCode(context)?.getScope?.(node) ?? context.getScope();
|
|
28
28
|
};
|