@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.
- package/CHANGELOG.md +15 -0
- package/README.md +17 -17
- package/dist/cjs/rules/atlaskit-theme/index.js +9 -8
- package/dist/cjs/rules/convert-props-syntax/index.js +5 -3
- package/dist/cjs/rules/enforce-style-prop/index.js +53 -14
- package/dist/cjs/rules/local-cx-xcss/index.js +3 -2
- package/dist/cjs/rules/no-array-arguments/index.js +4 -3
- package/dist/cjs/rules/no-container-queries/index.js +3 -2
- package/dist/cjs/rules/no-dynamic-styles/index.js +3 -2
- package/dist/cjs/rules/no-important-styles/index.js +3 -2
- package/dist/cjs/rules/no-imported-style-values/index.js +6 -5
- package/dist/cjs/rules/no-nested-selectors/index.js +4 -3
- package/dist/cjs/rules/no-styled/index.js +4 -3
- package/dist/cjs/rules/no-unsafe-selectors/index.js +3 -2
- package/dist/cjs/rules/no-unsafe-selectors/source-position-utils.js +2 -1
- package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +5 -4
- package/dist/cjs/rules/no-unsafe-values/index.js +3 -2
- package/dist/cjs/rules/no-unsafe-values/utils.js +1 -2
- package/dist/cjs/rules/use-compiled/index.js +3 -2
- package/dist/cjs/rules/use-compiled/is-safe.js +3 -2
- package/dist/cjs/rules/use-compiled/utils.js +2 -1
- package/dist/es2019/rules/atlaskit-theme/index.js +5 -4
- package/dist/es2019/rules/convert-props-syntax/index.js +6 -3
- package/dist/es2019/rules/enforce-style-prop/index.js +50 -13
- package/dist/es2019/rules/local-cx-xcss/index.js +3 -2
- package/dist/es2019/rules/no-array-arguments/index.js +3 -2
- package/dist/es2019/rules/no-container-queries/index.js +2 -1
- package/dist/es2019/rules/no-dynamic-styles/index.js +2 -2
- package/dist/es2019/rules/no-important-styles/index.js +2 -1
- package/dist/es2019/rules/no-imported-style-values/index.js +4 -3
- package/dist/es2019/rules/no-nested-selectors/index.js +3 -2
- package/dist/es2019/rules/no-styled/index.js +5 -4
- package/dist/es2019/rules/no-unsafe-selectors/index.js +2 -1
- package/dist/es2019/rules/no-unsafe-selectors/source-position-utils.js +2 -1
- package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +3 -2
- package/dist/es2019/rules/no-unsafe-values/index.js +2 -1
- package/dist/es2019/rules/use-compiled/index.js +3 -2
- package/dist/es2019/rules/use-compiled/is-safe.js +3 -2
- package/dist/es2019/rules/use-compiled/utils.js +2 -1
- package/dist/esm/rules/atlaskit-theme/index.js +9 -8
- package/dist/esm/rules/convert-props-syntax/index.js +5 -3
- package/dist/esm/rules/enforce-style-prop/index.js +53 -14
- package/dist/esm/rules/local-cx-xcss/index.js +3 -2
- package/dist/esm/rules/no-array-arguments/index.js +4 -3
- package/dist/esm/rules/no-container-queries/index.js +3 -2
- package/dist/esm/rules/no-dynamic-styles/index.js +3 -3
- package/dist/esm/rules/no-important-styles/index.js +3 -2
- package/dist/esm/rules/no-imported-style-values/index.js +6 -5
- package/dist/esm/rules/no-nested-selectors/index.js +4 -3
- package/dist/esm/rules/no-styled/index.js +5 -4
- package/dist/esm/rules/no-unsafe-selectors/index.js +3 -2
- package/dist/esm/rules/no-unsafe-selectors/source-position-utils.js +2 -1
- package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +5 -4
- package/dist/esm/rules/no-unsafe-values/index.js +3 -2
- package/dist/esm/rules/no-unsafe-values/utils.js +1 -2
- package/dist/esm/rules/use-compiled/index.js +3 -2
- package/dist/esm/rules/use-compiled/is-safe.js +3 -2
- package/dist/esm/rules/use-compiled/utils.js +2 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 1.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 1.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#178147](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/178147)
|
|
14
|
+
[`06f80813d818b`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/06f80813d818b) -
|
|
15
|
+
Handle the false-positive of enforce-style-prop when assigned via `style={style}` passing around
|
|
16
|
+
full objects, rather than simply inline `style={{ … }}` objects.
|
|
17
|
+
|
|
3
18
|
## 1.0.4
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -42,23 +42,23 @@ module.exports = {
|
|
|
42
42
|
|
|
43
43
|
| Rule | Description | Recommended | Fixable | Suggestions |
|
|
44
44
|
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
|
|
45
|
-
| <a href="./
|
|
46
|
-
| <a href="./
|
|
47
|
-
| <a href="./
|
|
48
|
-
| <a href="./
|
|
49
|
-
| <a href="./
|
|
50
|
-
| <a href="./
|
|
51
|
-
| <a href="./
|
|
52
|
-
| <a href="./
|
|
53
|
-
| <a href="./
|
|
54
|
-
| <a href="./
|
|
55
|
-
| <a href="./
|
|
56
|
-
| <a href="./
|
|
57
|
-
| <a href="./
|
|
58
|
-
| <a href="./
|
|
59
|
-
| <a href="./
|
|
60
|
-
| <a href="./
|
|
61
|
-
| <a href="./
|
|
45
|
+
| <a href="./src/rules/atlaskit-theme/README.md">atlaskit-theme</a> | Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand | Yes | | |
|
|
46
|
+
| <a href="./src/rules/convert-props-syntax/README.md">convert-props-syntax</a> | Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by those libraries. | Yes | Yes | |
|
|
47
|
+
| <a href="./src/rules/enforce-style-prop/README.md">enforce-style-prop</a> | Disallows usage of static styles in the `style` attribute in components | Yes | | |
|
|
48
|
+
| <a href="./src/rules/local-cx-xcss/README.md">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
|
|
49
|
+
| <a href="./src/rules/no-array-arguments/README.md">no-array-arguments</a> | Prevents usage of array arguments to style declaration functions | Yes | Yes | |
|
|
50
|
+
| <a href="./src/rules/no-classname-prop/README.md">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
|
|
51
|
+
| <a href="./src/rules/no-container-queries/README.md">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
|
|
52
|
+
| <a href="./src/rules/no-dynamic-styles/README.md">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
|
|
53
|
+
| <a href="./src/rules/no-exported-styles/README.md">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
|
|
54
|
+
| <a href="./src/rules/no-global-styles/README.md">no-global-styles</a> | Prevents global styles through CSS-in-JS or CSS module imports | Yes | | |
|
|
55
|
+
| <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
56
|
+
| <a href="./src/rules/no-imported-style-values/README.md">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
|
|
57
|
+
| <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
58
|
+
| <a href="./src/rules/no-styled/README.md">no-styled</a> | Disallows usage of the `styled` imports | Yes | | |
|
|
59
|
+
| <a href="./src/rules/no-unsafe-selectors/README.md">no-unsafe-selectors</a> | Disallows use of nested styles in `css` functions. | Yes | Yes | Yes |
|
|
60
|
+
| <a href="./src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
61
|
+
| <a href="./src/rules/use-compiled/README.md">use-compiled</a> | Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries | Yes | Yes | |
|
|
62
62
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
|
|
63
63
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-css-tagged-template-expression/usage">@atlaskit/design-system/no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
64
64
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-keyframes-tagged-template-expression/usage">@atlaskit/design-system/no-keyframes-tagged-template-expression</a> | Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.rule = exports.default = void 0;
|
|
7
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
7
8
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
8
9
|
var _createRule = require("../utils/create-rule");
|
|
9
10
|
var isIdentifierReferenced = function isIdentifierReferenced(hasImportSpecifier, node, references) {
|
|
@@ -63,10 +64,10 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
63
64
|
create: function create(context) {
|
|
64
65
|
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
65
66
|
return {
|
|
66
|
-
'CallExpression Identifier': function
|
|
67
|
-
var
|
|
68
|
-
references =
|
|
69
|
-
var ancestors =
|
|
67
|
+
'CallExpression Identifier': function CallExpression_Identifier(node) {
|
|
68
|
+
var _getScope = (0, _contextCompat.getScope)(context, node),
|
|
69
|
+
references = _getScope.references;
|
|
70
|
+
var ancestors = (0, _contextCompat.getAncestors)(context, node);
|
|
70
71
|
|
|
71
72
|
// Check if ancestor node is a call expression to Compiled
|
|
72
73
|
if (ancestors.some(function (ancestor) {
|
|
@@ -79,10 +80,10 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
},
|
|
82
|
-
'TaggedTemplateExpression Identifier': function
|
|
83
|
-
var
|
|
84
|
-
references =
|
|
85
|
-
var ancestors =
|
|
83
|
+
'TaggedTemplateExpression Identifier': function TaggedTemplateExpression_Identifier(node) {
|
|
84
|
+
var _getScope2 = (0, _contextCompat.getScope)(context, node),
|
|
85
|
+
references = _getScope2.references;
|
|
86
|
+
var ancestors = (0, _contextCompat.getAncestors)(context, node);
|
|
86
87
|
|
|
87
88
|
// Check if ancestor node is a tagged template expression to Compiled
|
|
88
89
|
if (ancestors.some(function (ancestor) {
|
|
@@ -8,6 +8,7 @@ exports.rule = exports.default = void 0;
|
|
|
8
8
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
9
9
|
var _eslintScope = require("eslint-scope");
|
|
10
10
|
var _estraverse = _interopRequireDefault(require("estraverse"));
|
|
11
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
11
12
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
12
13
|
var _createRule = require("../utils/create-rule");
|
|
13
14
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
@@ -218,7 +219,7 @@ var lintArguments = function lintArguments(context, args) {
|
|
|
218
219
|
_estraverse.default.traverse(property.value, {
|
|
219
220
|
enter: function enter(node, _parent) {
|
|
220
221
|
if (node.type === 'ArrowFunctionExpression') {
|
|
221
|
-
var propNames = parseArrowFunctionExpression(node,
|
|
222
|
+
var propNames = parseArrowFunctionExpression(node, (0, _contextCompat.getSourceCode)(context));
|
|
222
223
|
if (!propNames) {
|
|
223
224
|
// We've encountered a CSS value we don't recognise, skip.
|
|
224
225
|
return;
|
|
@@ -256,7 +257,7 @@ var lintArguments = function lintArguments(context, args) {
|
|
|
256
257
|
node: argument,
|
|
257
258
|
messageId: 'unsupported-prop-syntax',
|
|
258
259
|
fix: function fix(fixer) {
|
|
259
|
-
var sourceCode =
|
|
260
|
+
var sourceCode = (0, _contextCompat.getSourceCode)(context);
|
|
260
261
|
return fixPropsObjectUsages(fixer, sourceCode, argument,
|
|
261
262
|
// The
|
|
262
263
|
// allProps.some((propUsage) => !propUsage.valid)
|
|
@@ -387,7 +388,8 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
387
388
|
return {
|
|
388
389
|
CallExpression: function CallExpression(node) {
|
|
389
390
|
var _node$parent, _node$parent2;
|
|
390
|
-
var
|
|
391
|
+
var _getScope = (0, _contextCompat.getScope)(context, node),
|
|
392
|
+
references = _getScope.references;
|
|
391
393
|
|
|
392
394
|
// Rule should ignore .attrs() calls
|
|
393
395
|
if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'attrs') {
|
|
@@ -6,12 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.rule = exports.default = void 0;
|
|
7
7
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
8
|
var _allowedFunctionCalls = require("@atlaskit/eslint-utils/allowed-function-calls");
|
|
9
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
9
10
|
var _findVariable3 = require("@atlaskit/eslint-utils/find-variable");
|
|
10
11
|
var _createRule = require("../utils/create-rule");
|
|
11
12
|
var isParameter = function isParameter(context, identifier) {
|
|
12
13
|
var _findVariable;
|
|
13
14
|
var definitions = (_findVariable = (0, _findVariable3.findVariable)({
|
|
14
|
-
sourceCode:
|
|
15
|
+
sourceCode: (0, _contextCompat.getSourceCode)(context),
|
|
15
16
|
identifier: identifier
|
|
16
17
|
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
17
18
|
if (!definitions || !definitions.length) {
|
|
@@ -23,7 +24,7 @@ var isParameter = function isParameter(context, identifier) {
|
|
|
23
24
|
var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
24
25
|
var _variable$identifiers;
|
|
25
26
|
var variable = (0, _findVariable3.findVariable)({
|
|
26
|
-
sourceCode:
|
|
27
|
+
sourceCode: (0, _contextCompat.getSourceCode)(context),
|
|
27
28
|
identifier: identifier
|
|
28
29
|
});
|
|
29
30
|
if (!variable) {
|
|
@@ -31,8 +32,6 @@ var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
|
31
32
|
}
|
|
32
33
|
var variableDefinition = variable.defs[0].node;
|
|
33
34
|
|
|
34
|
-
// console.log('@@variableDefinition', variableDefinition);
|
|
35
|
-
|
|
36
35
|
// If identifier is a RestElement, report warning
|
|
37
36
|
if (((_variable$identifiers = variable.identifiers[0]) === null || _variable$identifiers === void 0 || (_variable$identifiers = _variable$identifiers.parent) === null || _variable$identifiers === void 0 ? void 0 : _variable$identifiers.type) === 'RestElement') {
|
|
38
37
|
return false;
|
|
@@ -77,6 +76,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
77
76
|
if (property.type === 'SpreadElement') {
|
|
78
77
|
return false;
|
|
79
78
|
}
|
|
79
|
+
|
|
80
80
|
// property.type === 'Property', moving on to check if value is static
|
|
81
81
|
if (property.value.type === 'Literal') {
|
|
82
82
|
return false;
|
|
@@ -84,7 +84,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
84
84
|
return isIdentifierAllowed(context, property.value);
|
|
85
85
|
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier') {
|
|
86
86
|
var variable = (0, _findVariable3.findVariable)({
|
|
87
|
-
sourceCode:
|
|
87
|
+
sourceCode: (0, _contextCompat.getSourceCode)(context),
|
|
88
88
|
identifier: property.value.callee
|
|
89
89
|
});
|
|
90
90
|
// Anything returned by getAllowedFunctionCalls should be used in css prop instead
|
|
@@ -98,7 +98,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
98
98
|
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
99
99
|
var _findVariable2;
|
|
100
100
|
var definitions = (_findVariable2 = (0, _findVariable3.findVariable)({
|
|
101
|
-
sourceCode:
|
|
101
|
+
sourceCode: (0, _contextCompat.getSourceCode)(context),
|
|
102
102
|
identifier: property.value.object
|
|
103
103
|
})) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
|
|
104
104
|
if (!definitions || !definitions.length) {
|
|
@@ -140,15 +140,16 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
140
140
|
},
|
|
141
141
|
create: function create(context) {
|
|
142
142
|
return {
|
|
143
|
-
'JSXAttribute[name.name="style"] > JSXExpressionContainer': function
|
|
144
|
-
var _node$expression$expr;
|
|
143
|
+
'JSXAttribute[name.name="style"] > JSXExpressionContainer': function JSXAttributeNameNameStyle__JSXExpressionContainer(node) {
|
|
144
|
+
var _node$expression$expr, _expression;
|
|
145
145
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXExpressionContainer')) {
|
|
146
146
|
return;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
// we've reached an attribute named style
|
|
150
150
|
|
|
151
|
-
var expression;
|
|
151
|
+
var expression = null;
|
|
152
|
+
var reportOnNodeExpression = false;
|
|
152
153
|
if (
|
|
153
154
|
// @ts-expect-error -- TSAsExpression is not valid in estree
|
|
154
155
|
node.expression.type === 'TSAsExpression' &&
|
|
@@ -160,21 +161,59 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
160
161
|
} else if (node.expression.type === 'ObjectExpression') {
|
|
161
162
|
// Typical `style={{ … }}` scenario
|
|
162
163
|
expression = node.expression;
|
|
163
|
-
} else {
|
|
164
|
+
} else if (node.expression.type === 'Identifier') {
|
|
165
|
+
var _variable$defs;
|
|
166
|
+
/*
|
|
167
|
+
* Example:
|
|
168
|
+
* ```tsx
|
|
169
|
+
* const style = { width: 100 };
|
|
170
|
+
* <div style={style} />
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
var variable = (0, _findVariable3.findVariable)({
|
|
174
|
+
sourceCode: (0, _contextCompat.getSourceCode)(context),
|
|
175
|
+
identifier: node.expression
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// Types are alluding us here, but we really only want an ObjectExpression here
|
|
179
|
+
// Additionally, if we have multiple variable definitions, we're in some unhandled scenario
|
|
180
|
+
// so we're only going to look at the first one…
|
|
181
|
+
var hopefulObjectExpression = variable === null || variable === void 0 || (_variable$defs = variable.defs) === null || _variable$defs === void 0 || (_variable$defs = _variable$defs[0]) === null || _variable$defs === void 0 || (_variable$defs = _variable$defs.node) === null || _variable$defs === void 0 ? void 0 : _variable$defs.init;
|
|
182
|
+
if ((hopefulObjectExpression === null || hopefulObjectExpression === void 0 ? void 0 : hopefulObjectExpression.type) === 'ObjectExpression') {
|
|
183
|
+
expression = hopefulObjectExpression;
|
|
184
|
+
}
|
|
185
|
+
reportOnNodeExpression = true;
|
|
186
|
+
}
|
|
187
|
+
if (!((_expression = expression) !== null && _expression !== void 0 && _expression.properties)) {
|
|
164
188
|
context.report({
|
|
165
189
|
node: node,
|
|
166
190
|
messageId: 'enforce-style-prop'
|
|
167
191
|
});
|
|
168
192
|
return;
|
|
169
193
|
}
|
|
170
|
-
|
|
171
|
-
|
|
194
|
+
if (reportOnNodeExpression) {
|
|
195
|
+
// In some cases we want to report on the `node.expression` itself, eg.
|
|
196
|
+
// `styles` in `style={styles}` should get the error
|
|
197
|
+
if (expression.properties.some(function (value) {
|
|
198
|
+
return !isPropertyValueAllowed(value, context);
|
|
199
|
+
})) {
|
|
172
200
|
context.report({
|
|
173
|
-
node:
|
|
201
|
+
node: node.expression,
|
|
174
202
|
messageId: 'enforce-style-prop'
|
|
175
203
|
});
|
|
176
204
|
}
|
|
177
|
-
}
|
|
205
|
+
} else {
|
|
206
|
+
// Typically we want to report on the individual styles, eg.
|
|
207
|
+
// `color: 'red'` in `style={{ color: 'red' }}` should get the error
|
|
208
|
+
expression.properties.forEach(function (value) {
|
|
209
|
+
if (!isPropertyValueAllowed(value, context)) {
|
|
210
|
+
context.report({
|
|
211
|
+
node: value,
|
|
212
|
+
messageId: 'enforce-style-prop'
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
178
217
|
}
|
|
179
218
|
};
|
|
180
219
|
}
|
|
@@ -4,8 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.rule = exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
8
8
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
9
|
+
var _createRule = require("../utils/create-rule");
|
|
9
10
|
var IMPORT_SOURCES = [_isSupportedImport.CSS_IN_JS_IMPORTS.compiled, _isSupportedImport.CSS_IN_JS_IMPORTS.atlaskitCss];
|
|
10
11
|
function getParentJSXAttribute(node) {
|
|
11
12
|
var parent = node.parent;
|
|
@@ -33,7 +34,7 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
33
34
|
create: function create(context) {
|
|
34
35
|
return {
|
|
35
36
|
'CallExpression[callee.name="cx"]': function CallExpressionCalleeNameCx(node) {
|
|
36
|
-
if (node.type === 'CallExpression' && (0, _isSupportedImport.isCxFunction)(node.callee,
|
|
37
|
+
if (node.type === 'CallExpression' && (0, _isSupportedImport.isCxFunction)(node.callee, (0, _contextCompat.getScope)(context, node).references, IMPORT_SOURCES)) {
|
|
37
38
|
var parentJSXAttribute = getParentJSXAttribute(node);
|
|
38
39
|
var propName = parentJSXAttribute === null || parentJSXAttribute === void 0 ? void 0 : parentJSXAttribute.name.name.toString();
|
|
39
40
|
if (propName && /[xX]css$/.test(propName)) {
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.rule = exports.default = void 0;
|
|
7
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
7
8
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
8
9
|
var _createRule = require("../utils/create-rule");
|
|
9
10
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
@@ -40,8 +41,8 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
40
41
|
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
41
42
|
return {
|
|
42
43
|
CallExpression: function CallExpression(node) {
|
|
43
|
-
var
|
|
44
|
-
references =
|
|
44
|
+
var _getScope = (0, _contextCompat.getScope)(context, node),
|
|
45
|
+
references = _getScope.references;
|
|
45
46
|
if (!(0, _isSupportedImport.hasStyleObjectArguments)(node.callee, references, importSources)) {
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
@@ -70,7 +71,7 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
70
71
|
var items = argument.elements.filter(function (value) {
|
|
71
72
|
return value !== null;
|
|
72
73
|
}).map(function (element) {
|
|
73
|
-
return
|
|
74
|
+
return (0, _contextCompat.getSourceCode)(context).getText(element);
|
|
74
75
|
});
|
|
75
76
|
return fixer.replaceText(argument, items.join(', '));
|
|
76
77
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.rule = exports.default = void 0;
|
|
8
8
|
var _estraverse = _interopRequireDefault(require("estraverse"));
|
|
9
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
9
10
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
10
11
|
var _createRule = require("../utils/create-rule");
|
|
11
12
|
/* eslint-disable @atlassian/tangerine/import/entry-points */
|
|
@@ -40,8 +41,8 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
40
41
|
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
41
42
|
return {
|
|
42
43
|
CallExpression: function CallExpression(node) {
|
|
43
|
-
var
|
|
44
|
-
references =
|
|
44
|
+
var _getScope = (0, _contextCompat.getScope)(context, node),
|
|
45
|
+
references = _getScope.references;
|
|
45
46
|
if ((0, _isSupportedImport.isCss)(node.callee, references, importSources) || (0, _isSupportedImport.isStyled)(node.callee, references, importSources) || (0, _isSupportedImport.isKeyframes)(node.callee, references, importSources) || (0, _isSupportedImport.isCssMap)(node.callee, references, importSources) || (0, _isSupportedImport.isXcss)(node.callee, references, importSources)) {
|
|
46
47
|
_estraverse.default.traverse(node, {
|
|
47
48
|
enter: function enter(node) {
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.rule = exports.default = void 0;
|
|
8
8
|
var _esquery = _interopRequireDefault(require("esquery"));
|
|
9
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
9
10
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
10
11
|
var _createRule = require("../utils/create-rule");
|
|
11
12
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
@@ -41,8 +42,8 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
41
42
|
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
42
43
|
return {
|
|
43
44
|
CallExpression: function CallExpression(node) {
|
|
44
|
-
var
|
|
45
|
-
references =
|
|
45
|
+
var _getScope = (0, _contextCompat.getScope)(context, node),
|
|
46
|
+
references = _getScope.references;
|
|
46
47
|
if (!(0, _isSupportedImport.hasStyleObjectArguments)(node.callee, references, importSources)) {
|
|
47
48
|
return;
|
|
48
49
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.rule = exports.default = void 0;
|
|
8
8
|
var _esquery = _interopRequireDefault(require("esquery"));
|
|
9
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
9
10
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
10
11
|
var _schema = require("@atlaskit/eslint-utils/schema");
|
|
11
12
|
var _createRuleWithTypedConfig = require("../utils/create-rule-with-typed-config");
|
|
@@ -35,8 +36,8 @@ var rule = exports.rule = (0, _createRuleWithTypedConfig.createLintRuleWithTyped
|
|
|
35
36
|
var importSources = _ref.importSources;
|
|
36
37
|
return {
|
|
37
38
|
CallExpression: function CallExpression(node) {
|
|
38
|
-
var
|
|
39
|
-
references =
|
|
39
|
+
var _getScope = (0, _contextCompat.getScope)(context, node),
|
|
40
|
+
references = _getScope.references;
|
|
40
41
|
if (!(0, _isSupportedImport.hasStyleObjectArguments)(node.callee, references, importSources)) {
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
@@ -8,6 +8,7 @@ exports.rule = exports.default = void 0;
|
|
|
8
8
|
var _esquery = _interopRequireDefault(require("esquery"));
|
|
9
9
|
var _estraverse = _interopRequireDefault(require("estraverse"));
|
|
10
10
|
var _allowedFunctionCalls = require("@atlaskit/eslint-utils/allowed-function-calls");
|
|
11
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
11
12
|
var _findVariable = require("@atlaskit/eslint-utils/find-variable");
|
|
12
13
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
13
14
|
var _createRule = require("../utils/create-rule");
|
|
@@ -58,7 +59,7 @@ var schema = [{
|
|
|
58
59
|
var isIdentifierImported = function isIdentifierImported(identifier, context, functionAllowList, keysAllowList) {
|
|
59
60
|
var variable = (0, _findVariable.findVariable)({
|
|
60
61
|
identifier: identifier,
|
|
61
|
-
sourceCode:
|
|
62
|
+
sourceCode: (0, _contextCompat.getSourceCode)(context)
|
|
62
63
|
});
|
|
63
64
|
if (!variable) {
|
|
64
65
|
return false;
|
|
@@ -158,19 +159,19 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
158
159
|
if (callExpression.callee !== identifier) {
|
|
159
160
|
return false;
|
|
160
161
|
}
|
|
161
|
-
return (0, _isSupportedImport.isCxFunction)(identifier,
|
|
162
|
+
return (0, _isSupportedImport.isCxFunction)(identifier, (0, _contextCompat.getScope)(context, identifier).references, importSources);
|
|
162
163
|
};
|
|
163
164
|
return {
|
|
164
165
|
// Checking css/cssMap/keyframes/styled/xcss calls
|
|
165
166
|
CallExpression: function CallExpression(node) {
|
|
166
|
-
var
|
|
167
|
-
references =
|
|
167
|
+
var _getScope = (0, _contextCompat.getScope)(context, node),
|
|
168
|
+
references = _getScope.references;
|
|
168
169
|
if (!(0, _isSupportedImport.hasStyleObjectArguments)(node.callee, references, importSources)) {
|
|
169
170
|
return;
|
|
170
171
|
}
|
|
171
172
|
node.arguments.forEach(checkForIdentifiers);
|
|
172
173
|
},
|
|
173
|
-
'JSXAttribute[name.name=/^(style|css|xcss)$/]': function
|
|
174
|
+
'JSXAttribute[name.name=/^(style|css|xcss)$/]': function JSXAttributeNameName_StyleCssXcss$_(jsxAttribute) {
|
|
174
175
|
if (jsxAttribute.type !== 'JSXAttribute') {
|
|
175
176
|
return;
|
|
176
177
|
}
|
|
@@ -8,8 +8,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.rule = exports.default = void 0;
|
|
9
9
|
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
|
|
10
10
|
var _postcssSelectorParser = _interopRequireWildcard(require("postcss-selector-parser"));
|
|
11
|
-
var
|
|
11
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
12
12
|
var _schema = require("@atlaskit/eslint-utils/schema");
|
|
13
|
+
var _walkStyleProperties = require("@atlaskit/eslint-utils/walk-style-properties");
|
|
13
14
|
var _createRuleWithTypedConfig = require("../utils/create-rule-with-typed-config");
|
|
14
15
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
15
16
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -63,8 +64,8 @@ var rule = exports.rule = (0, _createRuleWithTypedConfig.createLintRuleWithTyped
|
|
|
63
64
|
var importSources = _ref.importSources;
|
|
64
65
|
return {
|
|
65
66
|
CallExpression: function CallExpression(node) {
|
|
66
|
-
var
|
|
67
|
-
references =
|
|
67
|
+
var _getScope = (0, _contextCompat.getScope)(context, node),
|
|
68
|
+
references = _getScope.references;
|
|
68
69
|
(0, _walkStyleProperties.walkStyleProperties)(node, references, importSources, function (_ref2) {
|
|
69
70
|
var key = _ref2.key,
|
|
70
71
|
value = _ref2.value;
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.rule = exports.default = void 0;
|
|
7
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
7
8
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
8
9
|
var _createRule = require("../utils/create-rule");
|
|
9
10
|
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
@@ -22,7 +23,7 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
22
23
|
create: function create(context) {
|
|
23
24
|
return {
|
|
24
25
|
CallExpression: function CallExpression(node) {
|
|
25
|
-
var references =
|
|
26
|
+
var references = (0, _contextCompat.getScope)(context, node).references;
|
|
26
27
|
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
27
28
|
if ((0, _isSupportedImport.isStyled)(node, references, importSources)) {
|
|
28
29
|
context.report({
|
|
@@ -32,10 +33,10 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
32
33
|
}
|
|
33
34
|
},
|
|
34
35
|
MemberExpression: function MemberExpression(node) {
|
|
35
|
-
var references =
|
|
36
|
+
var references = (0, _contextCompat.getScope)(context, node).references;
|
|
36
37
|
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
37
38
|
if (node.object.type === 'Identifier' && (0, _isSupportedImport.isStyled)(node.object, references, importSources)) {
|
|
38
|
-
var parent =
|
|
39
|
+
var parent = (0, _contextCompat.getAncestors)(context, node).at(-1);
|
|
39
40
|
if (parent && (parent.type === 'CallExpression' || parent.type === 'MemberExpression')) {
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
|
|
9
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
9
10
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
10
11
|
var _schema = require("@atlaskit/eslint-utils/schema");
|
|
11
12
|
var _walkStyleProperties = require("@atlaskit/eslint-utils/walk-style-properties");
|
|
@@ -85,8 +86,8 @@ var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
|
85
86
|
});
|
|
86
87
|
},
|
|
87
88
|
CallExpression: function CallExpression(node) {
|
|
88
|
-
var
|
|
89
|
-
references =
|
|
89
|
+
var _getScope = (0, _contextCompat.getScope)(context, node),
|
|
90
|
+
references = _getScope.references;
|
|
90
91
|
var isXcssCall = (0, _isSupportedImport.isXcss)(node, references, config.importSources);
|
|
91
92
|
(0, _walkStyleProperties.walkStyleProperties)(node, references, config.importSources, function (_ref) {
|
|
92
93
|
var key = _ref.key,
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.getRangeFromNode = getRangeFromNode;
|
|
8
8
|
exports.getSourceLocationFromRange = getSourceLocationFromRange;
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
10
11
|
function getRangeFromNode(_ref) {
|
|
11
12
|
var node = _ref.node,
|
|
12
13
|
sourceNode = _ref.sourceNode;
|
|
@@ -34,7 +35,7 @@ function getSourceLocationFromRange(context, _ref2) {
|
|
|
34
35
|
var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
|
|
35
36
|
start = _ref3[0],
|
|
36
37
|
end = _ref3[1];
|
|
37
|
-
var sourceCode =
|
|
38
|
+
var sourceCode = (0, _contextCompat.getSourceCode)(context);
|
|
38
39
|
return {
|
|
39
40
|
start: sourceCode.getLocFromIndex(start),
|
|
40
41
|
end: sourceCode.getLocFromIndex(end)
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.walkCssMap = walkCssMap;
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
9
10
|
/**
|
|
10
11
|
* This util is intentionally not in `@atlaskit/eslint-utils` at this time.
|
|
11
12
|
*
|
|
@@ -16,7 +17,7 @@ function walkCssMap(_ref) {
|
|
|
16
17
|
var context = _ref.context,
|
|
17
18
|
importSources = _ref.importSources,
|
|
18
19
|
visitor = _ref.visitor;
|
|
19
|
-
var program =
|
|
20
|
+
var program = (0, _contextCompat.getSourceCode)(context).ast;
|
|
20
21
|
var importDeclaration = program.body.find(function (node) {
|
|
21
22
|
return node.type === 'ImportDeclaration' && importSources.includes(node.source.value);
|
|
22
23
|
});
|
|
@@ -26,9 +27,9 @@ function walkCssMap(_ref) {
|
|
|
26
27
|
if (!specifier) {
|
|
27
28
|
return;
|
|
28
29
|
}
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
variable =
|
|
30
|
+
var _getSourceCode$scopeM = (0, _contextCompat.getSourceCode)(context).scopeManager.getDeclaredVariables(specifier),
|
|
31
|
+
_getSourceCode$scopeM2 = (0, _slicedToArray2.default)(_getSourceCode$scopeM, 1),
|
|
32
|
+
variable = _getSourceCode$scopeM2[0];
|
|
32
33
|
if (!variable) {
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.rule = exports.default = void 0;
|
|
7
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
7
8
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
8
9
|
var _createRule = require("../utils/create-rule");
|
|
9
10
|
var _messages = require("./messages");
|
|
@@ -67,8 +68,8 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
67
68
|
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
68
69
|
return {
|
|
69
70
|
CallExpression: function CallExpression(node) {
|
|
70
|
-
var
|
|
71
|
-
references =
|
|
71
|
+
var _getScope = (0, _contextCompat.getScope)(context, node),
|
|
72
|
+
references = _getScope.references;
|
|
72
73
|
if (!(0, _isSupportedImport.isCss)(node.callee, references, importSources) && !(0, _isSupportedImport.isStyled)(node.callee, references, importSources) && !(0, _isSupportedImport.isKeyframes)(node.callee, references, importSources) && !(0, _isSupportedImport.isCssMap)(node.callee, references, importSources) && !(0, _isSupportedImport.isXcss)(node.callee, references, importSources)) {
|
|
73
74
|
return;
|
|
74
75
|
}
|