@atlaskit/eslint-plugin-ui-styling-standard 0.16.4 → 0.16.6
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 +18 -0
- package/dist/cjs/rules/enforce-style-prop/index.js +4 -4
- package/dist/cjs/rules/no-imported-style-values/index.js +51 -3
- package/dist/cjs/rules/no-unsafe-values/utils.js +3 -3
- package/dist/es2019/rules/enforce-style-prop/index.js +4 -4
- package/dist/es2019/rules/no-imported-style-values/index.js +50 -3
- package/dist/es2019/rules/no-unsafe-values/utils.js +3 -3
- package/dist/esm/rules/enforce-style-prop/index.js +4 -4
- package/dist/esm/rules/no-imported-style-values/index.js +51 -3
- package/dist/esm/rules/no-unsafe-values/utils.js +3 -3
- package/package.json +1 -1
- package/src/rules/enforce-style-prop/index.tsx +4 -4
- package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +208 -0
- package/src/rules/no-imported-style-values/index.tsx +52 -5
- package/src/rules/no-unsafe-values/utils.tsx +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.16.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#112386](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/112386)
|
|
8
|
+
[`762c18186f898`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/762c18186f898) -
|
|
9
|
+
Internal refactoring to use `context.getSourceCode()` instead of `context.sourceCode` to better
|
|
10
|
+
support older versions of eslint.
|
|
11
|
+
|
|
12
|
+
## 0.16.5
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#111807](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/111807)
|
|
17
|
+
[`a0bd2ff79dc32`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a0bd2ff79dc32) -
|
|
18
|
+
Fixes `no-imported-style-values` to allow imported identifiers when used in the LHS of conditional
|
|
19
|
+
expressions in the `css` prop. This enables dynamic application of styles using feature flags.
|
|
20
|
+
|
|
3
21
|
## 0.16.4
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -11,7 +11,7 @@ var _findVariable3 = require("@atlaskit/eslint-utils/find-variable");
|
|
|
11
11
|
var isParameter = function isParameter(context, identifier) {
|
|
12
12
|
var _findVariable;
|
|
13
13
|
var definitions = (_findVariable = (0, _findVariable3.findVariable)({
|
|
14
|
-
sourceCode: context.
|
|
14
|
+
sourceCode: context.getSourceCode(),
|
|
15
15
|
identifier: identifier
|
|
16
16
|
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
17
17
|
if (!definitions || !definitions.length) {
|
|
@@ -23,7 +23,7 @@ var isParameter = function isParameter(context, identifier) {
|
|
|
23
23
|
var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
24
24
|
var _parent;
|
|
25
25
|
var variable = (0, _findVariable3.findVariable)({
|
|
26
|
-
sourceCode: context.
|
|
26
|
+
sourceCode: context.getSourceCode(),
|
|
27
27
|
identifier: identifier
|
|
28
28
|
});
|
|
29
29
|
if (!variable) {
|
|
@@ -70,7 +70,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
70
70
|
return isIdentifierAllowed(context, property.value);
|
|
71
71
|
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier') {
|
|
72
72
|
var variable = (0, _findVariable3.findVariable)({
|
|
73
|
-
sourceCode: context.
|
|
73
|
+
sourceCode: context.getSourceCode(),
|
|
74
74
|
identifier: property.value.callee
|
|
75
75
|
});
|
|
76
76
|
// Anything returned by getAllowedFunctionCalls should be used in css prop instead
|
|
@@ -84,7 +84,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
84
84
|
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
85
85
|
var _findVariable2;
|
|
86
86
|
var definitions = (_findVariable2 = (0, _findVariable3.findVariable)({
|
|
87
|
-
sourceCode: context.
|
|
87
|
+
sourceCode: context.getSourceCode(),
|
|
88
88
|
identifier: property.value.object
|
|
89
89
|
})) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
|
|
90
90
|
if (!definitions || !definitions.length) {
|
|
@@ -10,6 +10,7 @@ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
|
10
10
|
var _findVariable = require("@atlaskit/eslint-utils/find-variable");
|
|
11
11
|
var _allowedFunctionCalls = require("@atlaskit/eslint-utils/allowed-function-calls");
|
|
12
12
|
var _esquery = _interopRequireDefault(require("esquery"));
|
|
13
|
+
var _estraverse = _interopRequireDefault(require("estraverse"));
|
|
13
14
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
14
15
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
16
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
@@ -56,7 +57,7 @@ var schema = [{
|
|
|
56
57
|
var isIdentifierImported = function isIdentifierImported(identifier, context, functionAllowList, keysAllowList) {
|
|
57
58
|
var variable = (0, _findVariable.findVariable)({
|
|
58
59
|
identifier: identifier,
|
|
59
|
-
sourceCode: context.
|
|
60
|
+
sourceCode: context.getSourceCode()
|
|
60
61
|
});
|
|
61
62
|
if (!variable) {
|
|
62
63
|
return false;
|
|
@@ -75,6 +76,22 @@ var isIdentifierImported = function isIdentifierImported(identifier, context, fu
|
|
|
75
76
|
});
|
|
76
77
|
};
|
|
77
78
|
var checkIdentifier = function checkIdentifier(identifier, context, functionAllowList, keysAllowList) {
|
|
79
|
+
var _ref = identifier,
|
|
80
|
+
parent = _ref.parent;
|
|
81
|
+
|
|
82
|
+
// Even though `member` in `object.member` is syntactically an identifier,
|
|
83
|
+
// it should be ignored as `.member` is syntax sugar for `['member']` here.
|
|
84
|
+
// We should still lint `object[member]` (when `parent.computed` === true)
|
|
85
|
+
if (parent.type === 'MemberExpression' && identifier === parent.property && !parent.computed) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Even though `key` in `{ key: 'value' }` is syntactically an identifier,
|
|
90
|
+
// it should be ignored as `key` is syntax sugar for `'key'` here.
|
|
91
|
+
// We should still lint `[key]` (when `parent.computed` === true)
|
|
92
|
+
if (parent && parent.type === 'Property' && identifier === parent.key && !parent.computed) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
78
95
|
if (isIdentifierImported(identifier, context, functionAllowList, keysAllowList)) {
|
|
79
96
|
context.report({
|
|
80
97
|
node: identifier,
|
|
@@ -127,8 +144,39 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
127
144
|
}
|
|
128
145
|
node.arguments.forEach(checkForIdentifiers);
|
|
129
146
|
},
|
|
130
|
-
'JSXAttribute[name.name=/^style|css$/]
|
|
131
|
-
|
|
147
|
+
'JSXAttribute[name.name=/^style|css$/]': function JSXAttributeNameNameStyleCss$(jsxAttribute) {
|
|
148
|
+
_estraverse.default.traverse(jsxAttribute, {
|
|
149
|
+
fallback: function fallback(node) {
|
|
150
|
+
// estraverse does not know about nodes not in the ESTree standard.
|
|
151
|
+
// This includes JSX nodes, so we must provide a fallback method to handle them.
|
|
152
|
+
// Using `fallback: 'iteration'` can cause cycles because it will iterate
|
|
153
|
+
// over the `parent` attribute on JSX nodes.
|
|
154
|
+
return Object.keys(node).filter(function (key) {
|
|
155
|
+
return key !== 'parent';
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
enter: function enter(node, parent) {
|
|
159
|
+
// Ignore type contexts
|
|
160
|
+
// Cast required because ESTree is not aware of TypeScript nodes
|
|
161
|
+
if (node.type === 'TSTypeReference') {
|
|
162
|
+
return _estraverse.default.VisitorOption.Skip;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Ignore conditions of ternary expressions
|
|
166
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ConditionalExpression' && node === parent.test) {
|
|
167
|
+
return _estraverse.default.VisitorOption.Skip;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Ignore LHS of logical expressions (&&, ||)
|
|
171
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'LogicalExpression' && node === parent.left) {
|
|
172
|
+
return _estraverse.default.VisitorOption.Skip;
|
|
173
|
+
}
|
|
174
|
+
if (node.type !== 'Identifier') {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
checkIdentifier(node, context, functionAllowList, keysAllowList);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
132
180
|
}
|
|
133
181
|
};
|
|
134
182
|
}
|
|
@@ -71,7 +71,7 @@ var Linter = exports.Linter = /*#__PURE__*/function () {
|
|
|
71
71
|
}
|
|
72
72
|
var variable = (0, _findVariable.findVariable)({
|
|
73
73
|
identifier: value,
|
|
74
|
-
sourceCode: this.context.
|
|
74
|
+
sourceCode: this.context.getSourceCode()
|
|
75
75
|
});
|
|
76
76
|
if (!variable) {
|
|
77
77
|
this.lintUnhandledIdentifier(value);
|
|
@@ -172,7 +172,7 @@ var Linter = exports.Linter = /*#__PURE__*/function () {
|
|
|
172
172
|
}
|
|
173
173
|
var variable = (0, _findVariable.findVariable)({
|
|
174
174
|
identifier: identifier,
|
|
175
|
-
sourceCode: this.context.
|
|
175
|
+
sourceCode: this.context.getSourceCode()
|
|
176
176
|
});
|
|
177
177
|
if (!variable) {
|
|
178
178
|
return false;
|
|
@@ -215,7 +215,7 @@ var Linter = exports.Linter = /*#__PURE__*/function () {
|
|
|
215
215
|
}
|
|
216
216
|
var variable = (0, _findVariable.findVariable)({
|
|
217
217
|
identifier: identifier,
|
|
218
|
-
sourceCode: this.context.
|
|
218
|
+
sourceCode: this.context.getSourceCode()
|
|
219
219
|
});
|
|
220
220
|
if (!variable) {
|
|
221
221
|
return false;
|
|
@@ -5,7 +5,7 @@ import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
|
5
5
|
const isParameter = (context, identifier) => {
|
|
6
6
|
var _findVariable;
|
|
7
7
|
const definitions = (_findVariable = findVariable({
|
|
8
|
-
sourceCode: context.
|
|
8
|
+
sourceCode: context.getSourceCode(),
|
|
9
9
|
identifier: identifier
|
|
10
10
|
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
11
11
|
if (!definitions || !definitions.length) {
|
|
@@ -17,7 +17,7 @@ const isParameter = (context, identifier) => {
|
|
|
17
17
|
const isIdentifierAllowed = (context, identifier) => {
|
|
18
18
|
var _parent;
|
|
19
19
|
const variable = findVariable({
|
|
20
|
-
sourceCode: context.
|
|
20
|
+
sourceCode: context.getSourceCode(),
|
|
21
21
|
identifier: identifier
|
|
22
22
|
});
|
|
23
23
|
if (!variable) {
|
|
@@ -64,7 +64,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
64
64
|
return isIdentifierAllowed(context, property.value);
|
|
65
65
|
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier') {
|
|
66
66
|
const variable = findVariable({
|
|
67
|
-
sourceCode: context.
|
|
67
|
+
sourceCode: context.getSourceCode(),
|
|
68
68
|
identifier: property.value.callee
|
|
69
69
|
});
|
|
70
70
|
// Anything returned by getAllowedFunctionCalls should be used in css prop instead
|
|
@@ -78,7 +78,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
78
78
|
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
79
79
|
var _findVariable2;
|
|
80
80
|
const definitions = (_findVariable2 = findVariable({
|
|
81
|
-
sourceCode: context.
|
|
81
|
+
sourceCode: context.getSourceCode(),
|
|
82
82
|
identifier: property.value.object
|
|
83
83
|
})) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
|
|
84
84
|
if (!definitions || !definitions.length) {
|
|
@@ -3,6 +3,7 @@ import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-util
|
|
|
3
3
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
4
4
|
import { getAllowedDynamicKeys, getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
5
5
|
import esquery from 'esquery';
|
|
6
|
+
import estraverse from 'estraverse';
|
|
6
7
|
const schema = [{
|
|
7
8
|
type: 'object',
|
|
8
9
|
properties: {
|
|
@@ -46,7 +47,7 @@ const schema = [{
|
|
|
46
47
|
const isIdentifierImported = (identifier, context, functionAllowList, keysAllowList) => {
|
|
47
48
|
const variable = findVariable({
|
|
48
49
|
identifier: identifier,
|
|
49
|
-
sourceCode: context.
|
|
50
|
+
sourceCode: context.getSourceCode()
|
|
50
51
|
});
|
|
51
52
|
if (!variable) {
|
|
52
53
|
return false;
|
|
@@ -63,6 +64,23 @@ const isIdentifierImported = (identifier, context, functionAllowList, keysAllowL
|
|
|
63
64
|
});
|
|
64
65
|
};
|
|
65
66
|
const checkIdentifier = (identifier, context, functionAllowList, keysAllowList) => {
|
|
67
|
+
const {
|
|
68
|
+
parent
|
|
69
|
+
} = identifier;
|
|
70
|
+
|
|
71
|
+
// Even though `member` in `object.member` is syntactically an identifier,
|
|
72
|
+
// it should be ignored as `.member` is syntax sugar for `['member']` here.
|
|
73
|
+
// We should still lint `object[member]` (when `parent.computed` === true)
|
|
74
|
+
if (parent.type === 'MemberExpression' && identifier === parent.property && !parent.computed) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Even though `key` in `{ key: 'value' }` is syntactically an identifier,
|
|
79
|
+
// it should be ignored as `key` is syntax sugar for `'key'` here.
|
|
80
|
+
// We should still lint `[key]` (when `parent.computed` === true)
|
|
81
|
+
if (parent && parent.type === 'Property' && identifier === parent.key && !parent.computed) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
66
84
|
if (isIdentifierImported(identifier, context, functionAllowList, keysAllowList)) {
|
|
67
85
|
context.report({
|
|
68
86
|
node: identifier,
|
|
@@ -107,8 +125,37 @@ export const rule = createLintRule({
|
|
|
107
125
|
}
|
|
108
126
|
node.arguments.forEach(checkForIdentifiers);
|
|
109
127
|
},
|
|
110
|
-
'JSXAttribute[name.name=/^style|css$/]
|
|
111
|
-
|
|
128
|
+
'JSXAttribute[name.name=/^style|css$/]'(jsxAttribute) {
|
|
129
|
+
estraverse.traverse(jsxAttribute, {
|
|
130
|
+
fallback(node) {
|
|
131
|
+
// estraverse does not know about nodes not in the ESTree standard.
|
|
132
|
+
// This includes JSX nodes, so we must provide a fallback method to handle them.
|
|
133
|
+
// Using `fallback: 'iteration'` can cause cycles because it will iterate
|
|
134
|
+
// over the `parent` attribute on JSX nodes.
|
|
135
|
+
return Object.keys(node).filter(key => key !== 'parent');
|
|
136
|
+
},
|
|
137
|
+
enter(node, parent) {
|
|
138
|
+
// Ignore type contexts
|
|
139
|
+
// Cast required because ESTree is not aware of TypeScript nodes
|
|
140
|
+
if (node.type === 'TSTypeReference') {
|
|
141
|
+
return estraverse.VisitorOption.Skip;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Ignore conditions of ternary expressions
|
|
145
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ConditionalExpression' && node === parent.test) {
|
|
146
|
+
return estraverse.VisitorOption.Skip;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Ignore LHS of logical expressions (&&, ||)
|
|
150
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'LogicalExpression' && node === parent.left) {
|
|
151
|
+
return estraverse.VisitorOption.Skip;
|
|
152
|
+
}
|
|
153
|
+
if (node.type !== 'Identifier') {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
checkIdentifier(node, context, functionAllowList, keysAllowList);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
112
159
|
}
|
|
113
160
|
};
|
|
114
161
|
}
|
|
@@ -51,7 +51,7 @@ export class Linter {
|
|
|
51
51
|
}
|
|
52
52
|
const variable = findVariable({
|
|
53
53
|
identifier: value,
|
|
54
|
-
sourceCode: this.context.
|
|
54
|
+
sourceCode: this.context.getSourceCode()
|
|
55
55
|
});
|
|
56
56
|
if (!variable) {
|
|
57
57
|
this.lintUnhandledIdentifier(value);
|
|
@@ -141,7 +141,7 @@ export class Linter {
|
|
|
141
141
|
}
|
|
142
142
|
const variable = findVariable({
|
|
143
143
|
identifier,
|
|
144
|
-
sourceCode: this.context.
|
|
144
|
+
sourceCode: this.context.getSourceCode()
|
|
145
145
|
});
|
|
146
146
|
if (!variable) {
|
|
147
147
|
return false;
|
|
@@ -180,7 +180,7 @@ export class Linter {
|
|
|
180
180
|
}
|
|
181
181
|
const variable = findVariable({
|
|
182
182
|
identifier,
|
|
183
|
-
sourceCode: this.context.
|
|
183
|
+
sourceCode: this.context.getSourceCode()
|
|
184
184
|
});
|
|
185
185
|
if (!variable) {
|
|
186
186
|
return false;
|
|
@@ -5,7 +5,7 @@ import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
|
5
5
|
var isParameter = function isParameter(context, identifier) {
|
|
6
6
|
var _findVariable;
|
|
7
7
|
var definitions = (_findVariable = findVariable({
|
|
8
|
-
sourceCode: context.
|
|
8
|
+
sourceCode: context.getSourceCode(),
|
|
9
9
|
identifier: identifier
|
|
10
10
|
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
11
11
|
if (!definitions || !definitions.length) {
|
|
@@ -17,7 +17,7 @@ var isParameter = function isParameter(context, identifier) {
|
|
|
17
17
|
var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
18
18
|
var _parent;
|
|
19
19
|
var variable = findVariable({
|
|
20
|
-
sourceCode: context.
|
|
20
|
+
sourceCode: context.getSourceCode(),
|
|
21
21
|
identifier: identifier
|
|
22
22
|
});
|
|
23
23
|
if (!variable) {
|
|
@@ -64,7 +64,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
64
64
|
return isIdentifierAllowed(context, property.value);
|
|
65
65
|
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier') {
|
|
66
66
|
var variable = findVariable({
|
|
67
|
-
sourceCode: context.
|
|
67
|
+
sourceCode: context.getSourceCode(),
|
|
68
68
|
identifier: property.value.callee
|
|
69
69
|
});
|
|
70
70
|
// Anything returned by getAllowedFunctionCalls should be used in css prop instead
|
|
@@ -78,7 +78,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
78
78
|
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
79
79
|
var _findVariable2;
|
|
80
80
|
var definitions = (_findVariable2 = findVariable({
|
|
81
|
-
sourceCode: context.
|
|
81
|
+
sourceCode: context.getSourceCode(),
|
|
82
82
|
identifier: property.value.object
|
|
83
83
|
})) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
|
|
84
84
|
if (!definitions || !definitions.length) {
|
|
@@ -6,6 +6,7 @@ import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-util
|
|
|
6
6
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
7
7
|
import { getAllowedDynamicKeys, getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
8
8
|
import esquery from 'esquery';
|
|
9
|
+
import estraverse from 'estraverse';
|
|
9
10
|
var schema = [{
|
|
10
11
|
type: 'object',
|
|
11
12
|
properties: {
|
|
@@ -49,7 +50,7 @@ var schema = [{
|
|
|
49
50
|
var isIdentifierImported = function isIdentifierImported(identifier, context, functionAllowList, keysAllowList) {
|
|
50
51
|
var variable = findVariable({
|
|
51
52
|
identifier: identifier,
|
|
52
|
-
sourceCode: context.
|
|
53
|
+
sourceCode: context.getSourceCode()
|
|
53
54
|
});
|
|
54
55
|
if (!variable) {
|
|
55
56
|
return false;
|
|
@@ -68,6 +69,22 @@ var isIdentifierImported = function isIdentifierImported(identifier, context, fu
|
|
|
68
69
|
});
|
|
69
70
|
};
|
|
70
71
|
var checkIdentifier = function checkIdentifier(identifier, context, functionAllowList, keysAllowList) {
|
|
72
|
+
var _ref = identifier,
|
|
73
|
+
parent = _ref.parent;
|
|
74
|
+
|
|
75
|
+
// Even though `member` in `object.member` is syntactically an identifier,
|
|
76
|
+
// it should be ignored as `.member` is syntax sugar for `['member']` here.
|
|
77
|
+
// We should still lint `object[member]` (when `parent.computed` === true)
|
|
78
|
+
if (parent.type === 'MemberExpression' && identifier === parent.property && !parent.computed) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Even though `key` in `{ key: 'value' }` is syntactically an identifier,
|
|
83
|
+
// it should be ignored as `key` is syntax sugar for `'key'` here.
|
|
84
|
+
// We should still lint `[key]` (when `parent.computed` === true)
|
|
85
|
+
if (parent && parent.type === 'Property' && identifier === parent.key && !parent.computed) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
71
88
|
if (isIdentifierImported(identifier, context, functionAllowList, keysAllowList)) {
|
|
72
89
|
context.report({
|
|
73
90
|
node: identifier,
|
|
@@ -120,8 +137,39 @@ export var rule = createLintRule({
|
|
|
120
137
|
}
|
|
121
138
|
node.arguments.forEach(checkForIdentifiers);
|
|
122
139
|
},
|
|
123
|
-
'JSXAttribute[name.name=/^style|css$/]
|
|
124
|
-
|
|
140
|
+
'JSXAttribute[name.name=/^style|css$/]': function JSXAttributeNameNameStyleCss$(jsxAttribute) {
|
|
141
|
+
estraverse.traverse(jsxAttribute, {
|
|
142
|
+
fallback: function fallback(node) {
|
|
143
|
+
// estraverse does not know about nodes not in the ESTree standard.
|
|
144
|
+
// This includes JSX nodes, so we must provide a fallback method to handle them.
|
|
145
|
+
// Using `fallback: 'iteration'` can cause cycles because it will iterate
|
|
146
|
+
// over the `parent` attribute on JSX nodes.
|
|
147
|
+
return Object.keys(node).filter(function (key) {
|
|
148
|
+
return key !== 'parent';
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
enter: function enter(node, parent) {
|
|
152
|
+
// Ignore type contexts
|
|
153
|
+
// Cast required because ESTree is not aware of TypeScript nodes
|
|
154
|
+
if (node.type === 'TSTypeReference') {
|
|
155
|
+
return estraverse.VisitorOption.Skip;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Ignore conditions of ternary expressions
|
|
159
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ConditionalExpression' && node === parent.test) {
|
|
160
|
+
return estraverse.VisitorOption.Skip;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Ignore LHS of logical expressions (&&, ||)
|
|
164
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'LogicalExpression' && node === parent.left) {
|
|
165
|
+
return estraverse.VisitorOption.Skip;
|
|
166
|
+
}
|
|
167
|
+
if (node.type !== 'Identifier') {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
checkIdentifier(node, context, functionAllowList, keysAllowList);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
125
173
|
}
|
|
126
174
|
};
|
|
127
175
|
}
|
|
@@ -64,7 +64,7 @@ export var Linter = /*#__PURE__*/function () {
|
|
|
64
64
|
}
|
|
65
65
|
var variable = findVariable({
|
|
66
66
|
identifier: value,
|
|
67
|
-
sourceCode: this.context.
|
|
67
|
+
sourceCode: this.context.getSourceCode()
|
|
68
68
|
});
|
|
69
69
|
if (!variable) {
|
|
70
70
|
this.lintUnhandledIdentifier(value);
|
|
@@ -165,7 +165,7 @@ export var Linter = /*#__PURE__*/function () {
|
|
|
165
165
|
}
|
|
166
166
|
var variable = findVariable({
|
|
167
167
|
identifier: identifier,
|
|
168
|
-
sourceCode: this.context.
|
|
168
|
+
sourceCode: this.context.getSourceCode()
|
|
169
169
|
});
|
|
170
170
|
if (!variable) {
|
|
171
171
|
return false;
|
|
@@ -208,7 +208,7 @@ export var Linter = /*#__PURE__*/function () {
|
|
|
208
208
|
}
|
|
209
209
|
var variable = findVariable({
|
|
210
210
|
identifier: identifier,
|
|
211
|
-
sourceCode: this.context.
|
|
211
|
+
sourceCode: this.context.getSourceCode()
|
|
212
212
|
});
|
|
213
213
|
if (!variable) {
|
|
214
214
|
return false;
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@ type IdentifierWithParent = Scope.Reference['identifier'] & Rule.NodeParentExten
|
|
|
14
14
|
|
|
15
15
|
const isParameter = (context: Rule.RuleContext, identifier: Identifier): boolean => {
|
|
16
16
|
const definitions = findVariable({
|
|
17
|
-
sourceCode: context.
|
|
17
|
+
sourceCode: context.getSourceCode(),
|
|
18
18
|
identifier: identifier,
|
|
19
19
|
})?.defs;
|
|
20
20
|
if (!definitions || !definitions.length) {
|
|
@@ -27,7 +27,7 @@ const isParameter = (context: Rule.RuleContext, identifier: Identifier): boolean
|
|
|
27
27
|
|
|
28
28
|
const isIdentifierAllowed = (context: Rule.RuleContext, identifier: Identifier): boolean => {
|
|
29
29
|
const variable = findVariable({
|
|
30
|
-
sourceCode: context.
|
|
30
|
+
sourceCode: context.getSourceCode(),
|
|
31
31
|
identifier: identifier,
|
|
32
32
|
});
|
|
33
33
|
|
|
@@ -79,7 +79,7 @@ function isPropertyValueAllowed(property: ObjPropertyType, context: Rule.RuleCon
|
|
|
79
79
|
property.value.callee.type === 'Identifier'
|
|
80
80
|
) {
|
|
81
81
|
const variable = findVariable({
|
|
82
|
-
sourceCode: context.
|
|
82
|
+
sourceCode: context.getSourceCode(),
|
|
83
83
|
identifier: property.value.callee,
|
|
84
84
|
});
|
|
85
85
|
// Anything returned by getAllowedFunctionCalls should be used in css prop instead
|
|
@@ -98,7 +98,7 @@ function isPropertyValueAllowed(property: ObjPropertyType, context: Rule.RuleCon
|
|
|
98
98
|
property.value.object.type === 'Identifier'
|
|
99
99
|
) {
|
|
100
100
|
const definitions = findVariable({
|
|
101
|
-
sourceCode: context.
|
|
101
|
+
sourceCode: context.getSourceCode(),
|
|
102
102
|
identifier: property.value.object,
|
|
103
103
|
})?.defs;
|
|
104
104
|
if (!definitions || !definitions.length) {
|
|
@@ -141,6 +141,90 @@ typescriptEslintTester.run(
|
|
|
141
141
|
`,
|
|
142
142
|
options: [],
|
|
143
143
|
},
|
|
144
|
+
{
|
|
145
|
+
name: 'Imported value in LHS of conditional expression in css prop',
|
|
146
|
+
code: `
|
|
147
|
+
import { css } from '@compiled/react';
|
|
148
|
+
import { ff } from '@atlassian/jira-feature-flagging';
|
|
149
|
+
import { IS_FF_ENABLED } from '../shared';
|
|
150
|
+
|
|
151
|
+
const baseStyles = css({ margin: 0 });
|
|
152
|
+
const styles = css({ color: token('color.text') });
|
|
153
|
+
const stylesFF = css({ color: token('color.text.danger') });
|
|
154
|
+
|
|
155
|
+
const Component = () => (
|
|
156
|
+
<>
|
|
157
|
+
<div css={IS_FF_ENABLED ? stylesFF : styles} />
|
|
158
|
+
<div css={[baseStyles, IS_FF_ENABLED ? stylesFF : styles]} />
|
|
159
|
+
<div css={ff('my-feature-flag') ? stylesFF : styles} />
|
|
160
|
+
<div css={[baseStyles, ff('my-feature-flag') ? stylesFF : styles]} />
|
|
161
|
+
</>
|
|
162
|
+
);
|
|
163
|
+
`,
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: 'Imported value as entire LHS of logical expression in css prop',
|
|
167
|
+
code: `
|
|
168
|
+
import { css } from '@compiled/react';
|
|
169
|
+
import { ff } from '@atlassian/jira-feature-flagging';
|
|
170
|
+
import { IS_FF_ENABLED } from '../shared';
|
|
171
|
+
|
|
172
|
+
const baseStyles = css({ margin: 0 });
|
|
173
|
+
const stylesFF = css({ color: token('color.text.danger') });
|
|
174
|
+
|
|
175
|
+
const Component = () => (
|
|
176
|
+
<>
|
|
177
|
+
<div css={IS_FF_ENABLED && stylesFF} />
|
|
178
|
+
<div css={[baseStyles, IS_FF_ENABLED && stylesFF]} />
|
|
179
|
+
<div css={ff('my-feature-flag') && stylesFF} />
|
|
180
|
+
<div css={[baseStyles, ff('my-feature-flag') && stylesFF]} />
|
|
181
|
+
</>
|
|
182
|
+
);
|
|
183
|
+
`,
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: 'Imported value in LHS of conditional expression in style prop',
|
|
187
|
+
code: `
|
|
188
|
+
import { css } from '@compiled/react';
|
|
189
|
+
import { ff } from '@atlassian/jira-feature-flagging';
|
|
190
|
+
import { IS_FF_ENABLED } from '../shared';
|
|
191
|
+
|
|
192
|
+
const Component = (props: { width: number }) => (
|
|
193
|
+
<>
|
|
194
|
+
<div style={{ width: IS_FF_ENABLED ? Math.abs(width) : width }} />
|
|
195
|
+
<div style={{ width: ff('my-feature-flag') ? Math.abs(width) : width }} />
|
|
196
|
+
</>
|
|
197
|
+
);
|
|
198
|
+
`,
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: 'Non-computed member access that collides with imported name',
|
|
202
|
+
code: `
|
|
203
|
+
import { abs } from '../shared';
|
|
204
|
+
|
|
205
|
+
const Component = (props: { width: number }) => (
|
|
206
|
+
<div style={{ width: Math.abs(width) }} />
|
|
207
|
+
);
|
|
208
|
+
`,
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
name: 'Non-computed property key that collides with imported name',
|
|
212
|
+
code: `
|
|
213
|
+
import { css } from '@compiled/react';
|
|
214
|
+
import { color } from '../shared';
|
|
215
|
+
|
|
216
|
+
const styles = css({
|
|
217
|
+
color: token('color.text'),
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
const Component = (props: { color: string }) => (
|
|
221
|
+
<div
|
|
222
|
+
css={styles}
|
|
223
|
+
style={{ color: props.color }}
|
|
224
|
+
/>
|
|
225
|
+
);
|
|
226
|
+
`,
|
|
227
|
+
},
|
|
144
228
|
],
|
|
145
229
|
invalid: [
|
|
146
230
|
{
|
|
@@ -278,6 +362,130 @@ typescriptEslintTester.run(
|
|
|
278
362
|
`,
|
|
279
363
|
errors: [{ messageId: 'no-imported-style-values' }],
|
|
280
364
|
},
|
|
365
|
+
{
|
|
366
|
+
name: 'Imported value in LHS of conditional expression in style declaration',
|
|
367
|
+
code: `
|
|
368
|
+
import { css } from '@compiled/react';
|
|
369
|
+
import { ff } from '@atlassian/jira-feature-flagging';
|
|
370
|
+
import { IS_FF_ENABLED } from '../shared';
|
|
371
|
+
|
|
372
|
+
const stylesA = css({
|
|
373
|
+
color: IS_FF_ENABLED ? token('color.text.danger'): token('color.text'),
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
const stylesB = css({
|
|
377
|
+
color: ff('my-feature-flag') ? token('color.text.danger') : token('color.text'),
|
|
378
|
+
});
|
|
379
|
+
`,
|
|
380
|
+
errors: [
|
|
381
|
+
{ messageId: 'no-imported-style-values', line: 7 },
|
|
382
|
+
{ messageId: 'no-imported-style-values', line: 11 },
|
|
383
|
+
],
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
name: 'Imported value in RHS of conditional expression in css prop',
|
|
387
|
+
code: `
|
|
388
|
+
import { css } from '@compiled/react';
|
|
389
|
+
import { ff } from '@atlassian/jira-feature-flagging';
|
|
390
|
+
import { IS_FF_ENABLED, stylesFF } from '../shared';
|
|
391
|
+
|
|
392
|
+
const baseStyles = css({ margin: 0 });
|
|
393
|
+
const styles = css({ color: token('color.text' )});
|
|
394
|
+
|
|
395
|
+
const Component = () => (
|
|
396
|
+
<>
|
|
397
|
+
<div css={IS_FF_ENABLED ? stylesFF : styles} />
|
|
398
|
+
<div css={[baseStyles, IS_FF_ENABLED ? stylesFF : styles]} />
|
|
399
|
+
<div css={ff('my-feature-flag') ? stylesFF : styles} />
|
|
400
|
+
<div css={[baseStyles, ff('my-feature-flag') ? stylesFF : styles]} />
|
|
401
|
+
</>
|
|
402
|
+
);
|
|
403
|
+
`,
|
|
404
|
+
errors: [
|
|
405
|
+
{ messageId: 'no-imported-style-values', line: 11 },
|
|
406
|
+
{ messageId: 'no-imported-style-values', line: 12 },
|
|
407
|
+
{ messageId: 'no-imported-style-values', line: 13 },
|
|
408
|
+
{ messageId: 'no-imported-style-values', line: 14 },
|
|
409
|
+
],
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
name: 'Imported value in RHS of logical expression in css prop',
|
|
413
|
+
code: `
|
|
414
|
+
import { css } from '@compiled/react';
|
|
415
|
+
import { ff } from '@atlassian/jira-feature-flagging';
|
|
416
|
+
import { IS_FF_ENABLED, stylesFF } from '../shared';
|
|
417
|
+
|
|
418
|
+
const baseStyles = css({ margin: 0 });
|
|
419
|
+
const styles = css({ color: token('color.text' )});
|
|
420
|
+
|
|
421
|
+
const Component = () => (
|
|
422
|
+
<>
|
|
423
|
+
<div css={IS_FF_ENABLED && stylesFF} />
|
|
424
|
+
<div css={[baseStyles, IS_FF_ENABLED && stylesFF]} />
|
|
425
|
+
<div css={ff('my-feature-flag') && stylesFF} />
|
|
426
|
+
<div css={[baseStyles, ff('my-feature-flag') && stylesFF]} />
|
|
427
|
+
</>
|
|
428
|
+
);
|
|
429
|
+
`,
|
|
430
|
+
errors: [
|
|
431
|
+
{ messageId: 'no-imported-style-values', line: 11 },
|
|
432
|
+
{ messageId: 'no-imported-style-values', line: 12 },
|
|
433
|
+
{ messageId: 'no-imported-style-values', line: 13 },
|
|
434
|
+
{ messageId: 'no-imported-style-values', line: 14 },
|
|
435
|
+
],
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
name: 'Imported value in RHS of conditional expression in style prop',
|
|
439
|
+
code: `
|
|
440
|
+
import { css } from '@compiled/react';
|
|
441
|
+
import { ff } from '@atlassian/jira-feature-flagging';
|
|
442
|
+
import { IS_FF_ENABLED, abs } from '../shared';
|
|
443
|
+
|
|
444
|
+
const Component = (props: { width: number }) => (
|
|
445
|
+
<>
|
|
446
|
+
<div style={{ width: IS_FF_ENABLED ? abs(width) : width }} />
|
|
447
|
+
<div style={{ width: ff('my-feature-flag') ? abs(width) : width }} />
|
|
448
|
+
</>
|
|
449
|
+
);
|
|
450
|
+
`,
|
|
451
|
+
errors: [
|
|
452
|
+
{ messageId: 'no-imported-style-values', line: 8 },
|
|
453
|
+
{ messageId: 'no-imported-style-values', line: 9 },
|
|
454
|
+
],
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
name: 'Computed member access with imported name',
|
|
458
|
+
code: `
|
|
459
|
+
import { abs } from '../shared';
|
|
460
|
+
|
|
461
|
+
const Component = (props: { width: number }) => (
|
|
462
|
+
<div style={{ width: Math[abs](width) }} />
|
|
463
|
+
);
|
|
464
|
+
`,
|
|
465
|
+
errors: [{ messageId: 'no-imported-style-values' }],
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
name: 'Computed property key with imported name',
|
|
469
|
+
code: `
|
|
470
|
+
import { css } from '@compiled/react';
|
|
471
|
+
import { color } from '../shared';
|
|
472
|
+
|
|
473
|
+
const styles = css({
|
|
474
|
+
[color]: token('color.text'),
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
const Component = (props: { color: string }) => (
|
|
478
|
+
<div
|
|
479
|
+
css={styles}
|
|
480
|
+
style={{ [color]: props.color }}
|
|
481
|
+
/>
|
|
482
|
+
);
|
|
483
|
+
`,
|
|
484
|
+
errors: [
|
|
485
|
+
{ messageId: 'no-imported-style-values' },
|
|
486
|
+
{ messageId: 'no-imported-style-values' },
|
|
487
|
+
],
|
|
488
|
+
},
|
|
281
489
|
],
|
|
282
490
|
},
|
|
283
491
|
);
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
hasStyleObjectArguments,
|
|
5
5
|
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
6
6
|
import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
|
|
7
|
+
import type { AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
|
|
7
8
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
8
9
|
import type { Rule } from 'eslint';
|
|
9
10
|
import {
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
} from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
15
16
|
import type * as ESTree from 'eslint-codemod-utils';
|
|
16
17
|
import esquery from 'esquery';
|
|
18
|
+
import estraverse from 'estraverse';
|
|
17
19
|
|
|
18
20
|
const schema: JSONSchema4 = [
|
|
19
21
|
{
|
|
@@ -56,7 +58,7 @@ const isIdentifierImported = (
|
|
|
56
58
|
): boolean => {
|
|
57
59
|
const variable = findVariable({
|
|
58
60
|
identifier: identifier,
|
|
59
|
-
sourceCode: context.
|
|
61
|
+
sourceCode: context.getSourceCode(),
|
|
60
62
|
});
|
|
61
63
|
if (!variable) {
|
|
62
64
|
return false;
|
|
@@ -81,6 +83,22 @@ const checkIdentifier = (
|
|
|
81
83
|
functionAllowList: AllowList,
|
|
82
84
|
keysAllowList: AllowList,
|
|
83
85
|
) => {
|
|
86
|
+
const { parent } = identifier as Rule.Node;
|
|
87
|
+
|
|
88
|
+
// Even though `member` in `object.member` is syntactically an identifier,
|
|
89
|
+
// it should be ignored as `.member` is syntax sugar for `['member']` here.
|
|
90
|
+
// We should still lint `object[member]` (when `parent.computed` === true)
|
|
91
|
+
if (parent.type === 'MemberExpression' && identifier === parent.property && !parent.computed) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Even though `key` in `{ key: 'value' }` is syntactically an identifier,
|
|
96
|
+
// it should be ignored as `key` is syntax sugar for `'key'` here.
|
|
97
|
+
// We should still lint `[key]` (when `parent.computed` === true)
|
|
98
|
+
if (parent && parent.type === 'Property' && identifier === parent.key && !parent.computed) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
84
102
|
if (isIdentifierImported(identifier, context, functionAllowList, keysAllowList)) {
|
|
85
103
|
context.report({
|
|
86
104
|
node: identifier,
|
|
@@ -129,10 +147,39 @@ export const rule = createLintRule({
|
|
|
129
147
|
}
|
|
130
148
|
node.arguments.forEach(checkForIdentifiers);
|
|
131
149
|
},
|
|
132
|
-
'JSXAttribute[name.name=/^style|css$/]
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
150
|
+
'JSXAttribute[name.name=/^style|css$/]'(jsxAttribute: ESTree.Node) {
|
|
151
|
+
estraverse.traverse(jsxAttribute, {
|
|
152
|
+
fallback(node) {
|
|
153
|
+
// estraverse does not know about nodes not in the ESTree standard.
|
|
154
|
+
// This includes JSX nodes, so we must provide a fallback method to handle them.
|
|
155
|
+
// Using `fallback: 'iteration'` can cause cycles because it will iterate
|
|
156
|
+
// over the `parent` attribute on JSX nodes.
|
|
157
|
+
return Object.keys(node).filter((key) => key !== 'parent');
|
|
158
|
+
},
|
|
159
|
+
enter(node, parent) {
|
|
160
|
+
// Ignore type contexts
|
|
161
|
+
// Cast required because ESTree is not aware of TypeScript nodes
|
|
162
|
+
if ((node.type as AST_NODE_TYPES) === 'TSTypeReference') {
|
|
163
|
+
return estraverse.VisitorOption.Skip;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Ignore conditions of ternary expressions
|
|
167
|
+
if (parent?.type === 'ConditionalExpression' && node === parent.test) {
|
|
168
|
+
return estraverse.VisitorOption.Skip;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Ignore LHS of logical expressions (&&, ||)
|
|
172
|
+
if (parent?.type === 'LogicalExpression' && node === parent.left) {
|
|
173
|
+
return estraverse.VisitorOption.Skip;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (node.type !== 'Identifier') {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
checkIdentifier(node, context, functionAllowList, keysAllowList);
|
|
181
|
+
},
|
|
182
|
+
});
|
|
136
183
|
},
|
|
137
184
|
};
|
|
138
185
|
},
|
|
@@ -81,7 +81,7 @@ export class Linter {
|
|
|
81
81
|
|
|
82
82
|
const variable = findVariable({
|
|
83
83
|
identifier: value,
|
|
84
|
-
sourceCode: this.context.
|
|
84
|
+
sourceCode: this.context.getSourceCode(),
|
|
85
85
|
});
|
|
86
86
|
if (!variable) {
|
|
87
87
|
this.lintUnhandledIdentifier(value);
|
|
@@ -170,7 +170,7 @@ export class Linter {
|
|
|
170
170
|
|
|
171
171
|
const variable = findVariable({
|
|
172
172
|
identifier,
|
|
173
|
-
sourceCode: this.context.
|
|
173
|
+
sourceCode: this.context.getSourceCode(),
|
|
174
174
|
});
|
|
175
175
|
if (!variable) {
|
|
176
176
|
return false;
|
|
@@ -211,7 +211,7 @@ export class Linter {
|
|
|
211
211
|
|
|
212
212
|
const variable = findVariable({
|
|
213
213
|
identifier,
|
|
214
|
-
sourceCode: this.context.
|
|
214
|
+
sourceCode: this.context.getSourceCode(),
|
|
215
215
|
});
|
|
216
216
|
if (!variable) {
|
|
217
217
|
return false;
|