@atlaskit/eslint-plugin-ui-styling-standard 1.1.0 → 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 +6 -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 +7 -6
- 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/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 +6 -5
- 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 -1
- 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 +7 -6
- 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 -2
- 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/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 +4 -4
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
2
|
import { analyze } from 'eslint-scope';
|
|
3
3
|
import ESTraverse from 'estraverse';
|
|
4
|
+
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
4
5
|
import { isEmotion, isStyledComponents } from '@atlaskit/eslint-utils/is-supported-import';
|
|
5
6
|
import { createLintRule } from '../utils/create-rule';
|
|
6
7
|
|
|
@@ -162,7 +163,7 @@ const lintArguments = (context, args) => {
|
|
|
162
163
|
ESTraverse.traverse(property.value, {
|
|
163
164
|
enter: function (node, _parent) {
|
|
164
165
|
if (node.type === 'ArrowFunctionExpression') {
|
|
165
|
-
const propNames = parseArrowFunctionExpression(node,
|
|
166
|
+
const propNames = parseArrowFunctionExpression(node, getSourceCode(context));
|
|
166
167
|
if (!propNames) {
|
|
167
168
|
// We've encountered a CSS value we don't recognise, skip.
|
|
168
169
|
return;
|
|
@@ -191,7 +192,7 @@ const lintArguments = (context, args) => {
|
|
|
191
192
|
node: argument,
|
|
192
193
|
messageId: 'unsupported-prop-syntax',
|
|
193
194
|
fix(fixer) {
|
|
194
|
-
const sourceCode =
|
|
195
|
+
const sourceCode = getSourceCode(context);
|
|
195
196
|
return fixPropsObjectUsages(fixer, sourceCode, argument,
|
|
196
197
|
// The
|
|
197
198
|
// allProps.some((propUsage) => !propUsage.valid)
|
|
@@ -283,7 +284,9 @@ export const rule = createLintRule({
|
|
|
283
284
|
return {
|
|
284
285
|
CallExpression: node => {
|
|
285
286
|
var _node$parent, _node$parent2;
|
|
286
|
-
const
|
|
287
|
+
const {
|
|
288
|
+
references
|
|
289
|
+
} = getScope(context, node);
|
|
287
290
|
|
|
288
291
|
// Rule should ignore .attrs() calls
|
|
289
292
|
if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'attrs') {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
2
|
import { getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
3
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
3
4
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
4
5
|
import { createLintRule } from '../utils/create-rule';
|
|
5
6
|
const isParameter = (context, identifier) => {
|
|
6
7
|
var _findVariable;
|
|
7
8
|
const definitions = (_findVariable = findVariable({
|
|
8
|
-
sourceCode:
|
|
9
|
+
sourceCode: getSourceCode(context),
|
|
9
10
|
identifier: identifier
|
|
10
11
|
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
11
12
|
if (!definitions || !definitions.length) {
|
|
@@ -17,7 +18,7 @@ const isParameter = (context, identifier) => {
|
|
|
17
18
|
const isIdentifierAllowed = (context, identifier) => {
|
|
18
19
|
var _variable$identifiers, _variable$identifiers2;
|
|
19
20
|
const variable = findVariable({
|
|
20
|
-
sourceCode:
|
|
21
|
+
sourceCode: getSourceCode(context),
|
|
21
22
|
identifier: identifier
|
|
22
23
|
});
|
|
23
24
|
if (!variable) {
|
|
@@ -77,7 +78,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
77
78
|
return isIdentifierAllowed(context, property.value);
|
|
78
79
|
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier') {
|
|
79
80
|
const variable = findVariable({
|
|
80
|
-
sourceCode:
|
|
81
|
+
sourceCode: getSourceCode(context),
|
|
81
82
|
identifier: property.value.callee
|
|
82
83
|
});
|
|
83
84
|
// Anything returned by getAllowedFunctionCalls should be used in css prop instead
|
|
@@ -91,7 +92,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
91
92
|
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
92
93
|
var _findVariable2;
|
|
93
94
|
const definitions = (_findVariable2 = findVariable({
|
|
94
|
-
sourceCode:
|
|
95
|
+
sourceCode: getSourceCode(context),
|
|
95
96
|
identifier: property.value.object
|
|
96
97
|
})) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
|
|
97
98
|
if (!definitions || !definitions.length) {
|
|
@@ -164,7 +165,7 @@ export const rule = createLintRule({
|
|
|
164
165
|
* ```
|
|
165
166
|
*/
|
|
166
167
|
const variable = findVariable({
|
|
167
|
-
sourceCode:
|
|
168
|
+
sourceCode: getSourceCode(context),
|
|
168
169
|
identifier: node.expression
|
|
169
170
|
});
|
|
170
171
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
2
2
|
import { CSS_IN_JS_IMPORTS, isCxFunction } from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
|
+
import { createLintRule } from '../utils/create-rule';
|
|
3
4
|
const IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
|
|
4
5
|
function getParentJSXAttribute(node) {
|
|
5
6
|
let parent = node.parent;
|
|
@@ -27,7 +28,7 @@ export const rule = createLintRule({
|
|
|
27
28
|
create(context) {
|
|
28
29
|
return {
|
|
29
30
|
'CallExpression[callee.name="cx"]': node => {
|
|
30
|
-
if (node.type === 'CallExpression' && isCxFunction(node.callee,
|
|
31
|
+
if (node.type === 'CallExpression' && isCxFunction(node.callee, getScope(context, node).references, IMPORT_SOURCES)) {
|
|
31
32
|
const parentJSXAttribute = getParentJSXAttribute(node);
|
|
32
33
|
const propName = parentJSXAttribute === null || parentJSXAttribute === void 0 ? void 0 : parentJSXAttribute.name.name.toString();
|
|
33
34
|
if (propName && /[xX]css$/.test(propName)) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
2
2
|
|
|
3
|
+
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
3
4
|
import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
4
5
|
import { createLintRule } from '../utils/create-rule';
|
|
5
6
|
const schema = [{
|
|
@@ -35,7 +36,7 @@ export const rule = createLintRule({
|
|
|
35
36
|
CallExpression(node) {
|
|
36
37
|
const {
|
|
37
38
|
references
|
|
38
|
-
} =
|
|
39
|
+
} = getScope(context, node);
|
|
39
40
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
@@ -57,7 +58,7 @@ export const rule = createLintRule({
|
|
|
57
58
|
*/
|
|
58
59
|
return null;
|
|
59
60
|
}
|
|
60
|
-
const items = argument.elements.filter(value => value !== null).map(element =>
|
|
61
|
+
const items = argument.elements.filter(value => value !== null).map(element => getSourceCode(context).getText(element));
|
|
61
62
|
return fixer.replaceText(argument, items.join(', '));
|
|
62
63
|
}
|
|
63
64
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @atlassian/tangerine/import/entry-points */
|
|
2
2
|
|
|
3
3
|
import estraverse from 'estraverse';
|
|
4
|
+
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
4
5
|
import { getImportSources, isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
5
6
|
import { createLintRule } from '../utils/create-rule';
|
|
6
7
|
const schema = [{
|
|
@@ -35,7 +36,7 @@ export const rule = createLintRule({
|
|
|
35
36
|
CallExpression(node) {
|
|
36
37
|
const {
|
|
37
38
|
references
|
|
38
|
-
} =
|
|
39
|
+
} = getScope(context, node);
|
|
39
40
|
if (isCss(node.callee, references, importSources) || isStyled(node.callee, references, importSources) || isKeyframes(node.callee, references, importSources) || isCssMap(node.callee, references, importSources) || isXcss(node.callee, references, importSources)) {
|
|
40
41
|
estraverse.traverse(node, {
|
|
41
42
|
enter(node) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
2
2
|
import esquery from 'esquery';
|
|
3
|
+
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
3
4
|
import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
4
5
|
import { createLintRule } from '../utils/create-rule';
|
|
5
6
|
const schema = [{
|
|
@@ -34,7 +35,7 @@ export const rule = createLintRule({
|
|
|
34
35
|
CallExpression(node) {
|
|
35
36
|
const {
|
|
36
37
|
references
|
|
37
|
-
} =
|
|
38
|
+
} = getScope(context, node);
|
|
38
39
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
39
40
|
return;
|
|
40
41
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import esquery from 'esquery';
|
|
2
|
+
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
2
3
|
import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
4
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
4
5
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
@@ -28,7 +29,7 @@ export const rule = createLintRuleWithTypedConfig({
|
|
|
28
29
|
CallExpression(node) {
|
|
29
30
|
const {
|
|
30
31
|
references
|
|
31
|
-
} =
|
|
32
|
+
} = getScope(context, node);
|
|
32
33
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import esquery from 'esquery';
|
|
6
6
|
import estraverse from 'estraverse';
|
|
7
7
|
import { getAllowedDynamicKeys, getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
8
|
+
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
8
9
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
9
10
|
import { getImportSources, hasStyleObjectArguments, isCxFunction } from '@atlaskit/eslint-utils/is-supported-import';
|
|
10
11
|
import { createLintRule } from '../utils/create-rule';
|
|
@@ -51,7 +52,7 @@ const schema = [{
|
|
|
51
52
|
const isIdentifierImported = (identifier, context, functionAllowList, keysAllowList) => {
|
|
52
53
|
const variable = findVariable({
|
|
53
54
|
identifier: identifier,
|
|
54
|
-
sourceCode:
|
|
55
|
+
sourceCode: getSourceCode(context)
|
|
55
56
|
});
|
|
56
57
|
if (!variable) {
|
|
57
58
|
return false;
|
|
@@ -141,14 +142,14 @@ export const rule = createLintRule({
|
|
|
141
142
|
if (callExpression.callee !== identifier) {
|
|
142
143
|
return false;
|
|
143
144
|
}
|
|
144
|
-
return isCxFunction(identifier,
|
|
145
|
+
return isCxFunction(identifier, getScope(context, identifier).references, importSources);
|
|
145
146
|
};
|
|
146
147
|
return {
|
|
147
148
|
// Checking css/cssMap/keyframes/styled/xcss calls
|
|
148
149
|
CallExpression(node) {
|
|
149
150
|
const {
|
|
150
151
|
references
|
|
151
|
-
} =
|
|
152
|
+
} = getScope(context, node);
|
|
152
153
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
153
154
|
return;
|
|
154
155
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import cssSelectorParser, { isNesting, isPseudo } from 'postcss-selector-parser';
|
|
2
|
-
import {
|
|
2
|
+
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
3
3
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
4
|
+
import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
|
|
4
5
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
5
6
|
const getCssSelector = key => {
|
|
6
7
|
if (key.type === 'Literal' && typeof key.value === 'string') {
|
|
@@ -51,7 +52,7 @@ export const rule = createLintRuleWithTypedConfig({
|
|
|
51
52
|
CallExpression(node) {
|
|
52
53
|
const {
|
|
53
54
|
references
|
|
54
|
-
} =
|
|
55
|
+
} = getScope(context, node);
|
|
55
56
|
walkStyleProperties(node, references, importSources, ({
|
|
56
57
|
key,
|
|
57
58
|
value
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getAncestors, getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
2
|
+
import { getImportSources, isStyled } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
3
|
import { createLintRule } from '../utils/create-rule';
|
|
3
4
|
export const rule = createLintRule({
|
|
4
5
|
meta: {
|
|
@@ -16,7 +17,7 @@ export const rule = createLintRule({
|
|
|
16
17
|
create(context) {
|
|
17
18
|
return {
|
|
18
19
|
CallExpression: node => {
|
|
19
|
-
const references =
|
|
20
|
+
const references = getScope(context, node).references;
|
|
20
21
|
const importSources = getImportSources(context);
|
|
21
22
|
if (isStyled(node, references, importSources)) {
|
|
22
23
|
context.report({
|
|
@@ -26,10 +27,10 @@ export const rule = createLintRule({
|
|
|
26
27
|
}
|
|
27
28
|
},
|
|
28
29
|
MemberExpression: node => {
|
|
29
|
-
const references =
|
|
30
|
+
const references = getScope(context, node).references;
|
|
30
31
|
const importSources = getImportSources(context);
|
|
31
32
|
if (node.object.type === 'Identifier' && isStyled(node.object, references, importSources)) {
|
|
32
|
-
const parent =
|
|
33
|
+
const parent = getAncestors(context, node).at(-1);
|
|
33
34
|
if (parent && (parent.type === 'CallExpression' || parent.type === 'MemberExpression')) {
|
|
34
35
|
return;
|
|
35
36
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import cssSelectorParser from 'postcss-selector-parser';
|
|
2
|
+
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
2
3
|
import { isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
4
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
4
5
|
import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
|
|
@@ -82,7 +83,7 @@ const rule = createLintRuleWithTypedConfig({
|
|
|
82
83
|
CallExpression(node) {
|
|
83
84
|
const {
|
|
84
85
|
references
|
|
85
|
-
} =
|
|
86
|
+
} = getScope(context, node);
|
|
86
87
|
const isXcssCall = isXcss(node, references, config.importSources);
|
|
87
88
|
walkStyleProperties(node, references, config.importSources, ({
|
|
88
89
|
key,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
1
2
|
export function getRangeFromNode({
|
|
2
3
|
node,
|
|
3
4
|
sourceNode
|
|
@@ -23,7 +24,7 @@ export function getRangeFromNode({
|
|
|
23
24
|
return [start, end];
|
|
24
25
|
}
|
|
25
26
|
export function getSourceLocationFromRange(context, [start, end]) {
|
|
26
|
-
const sourceCode =
|
|
27
|
+
const sourceCode = getSourceCode(context);
|
|
27
28
|
return {
|
|
28
29
|
start: sourceCode.getLocFromIndex(start),
|
|
29
30
|
end: sourceCode.getLocFromIndex(end)
|
|
@@ -4,18 +4,19 @@
|
|
|
4
4
|
* This is because the API is likely to change and should not be considered stable.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
7
8
|
export function walkCssMap({
|
|
8
9
|
context,
|
|
9
10
|
importSources,
|
|
10
11
|
visitor
|
|
11
12
|
}) {
|
|
12
|
-
const program =
|
|
13
|
+
const program = getSourceCode(context).ast;
|
|
13
14
|
const importDeclaration = program.body.find(node => node.type === 'ImportDeclaration' && importSources.includes(node.source.value));
|
|
14
15
|
const specifier = importDeclaration === null || importDeclaration === void 0 ? void 0 : importDeclaration.specifiers.find(specifier => specifier.type === 'ImportSpecifier' && specifier.imported.name === 'cssMap');
|
|
15
16
|
if (!specifier) {
|
|
16
17
|
return;
|
|
17
18
|
}
|
|
18
|
-
const [variable] =
|
|
19
|
+
const [variable] = getSourceCode(context).scopeManager.getDeclaredVariables(specifier);
|
|
19
20
|
if (!variable) {
|
|
20
21
|
return;
|
|
21
22
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @atlassian/tangerine/import/entry-points */
|
|
2
2
|
|
|
3
|
+
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
3
4
|
import { getImportSources, isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
4
5
|
import { createLintRule } from '../utils/create-rule';
|
|
5
6
|
import { messages } from './messages';
|
|
@@ -63,7 +64,7 @@ export const rule = createLintRule({
|
|
|
63
64
|
CallExpression(node) {
|
|
64
65
|
const {
|
|
65
66
|
references
|
|
66
|
-
} =
|
|
67
|
+
} = getScope(context, node);
|
|
67
68
|
if (!isCss(node.callee, references, importSources) && !isStyled(node.callee, references, importSources) && !isKeyframes(node.callee, references, importSources) && !isCssMap(node.callee, references, importSources) && !isXcss(node.callee, references, importSources)) {
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { identifier, importDeclaration, importSpecifier, literal } from 'eslint-codemod-utils';
|
|
2
|
+
import { getAllComments } from '@atlaskit/eslint-utils/context-compat';
|
|
2
3
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
3
4
|
import { createLintRule } from '../utils/create-rule';
|
|
4
|
-
import { getFirstImportFromSource, isImportDefaultSpecifier, isImportNamespaceSpecifier, isImportSpecifier } from './utils';
|
|
5
5
|
import { isSafeStyled, isSafeUsage } from './is-safe';
|
|
6
|
+
import { getFirstImportFromSource, isImportDefaultSpecifier, isImportNamespaceSpecifier, isImportSpecifier } from './utils';
|
|
6
7
|
const SUPPORTED_EMOTION_IMPORTS = new Set(['css', 'keyframes', 'ClassNames', 'jsx']);
|
|
7
8
|
const SUPPORTED_IMPORT_MAP = {
|
|
8
9
|
'@emotion/core': SUPPORTED_EMOTION_IMPORTS,
|
|
@@ -51,7 +52,7 @@ export const rule = createLintRule({
|
|
|
51
52
|
const config = readConfig(context);
|
|
52
53
|
return {
|
|
53
54
|
Program() {
|
|
54
|
-
const pragma =
|
|
55
|
+
const pragma = getAllComments(context).find(n => n.value.includes('@jsxImportSource @emotion/react'));
|
|
55
56
|
if (!pragma) {
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { closestOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
2
3
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
3
4
|
export function isSafeUsage({
|
|
4
5
|
context,
|
|
@@ -12,14 +13,14 @@ export function isSafeUsage({
|
|
|
12
13
|
if (importName === 'css') {
|
|
13
14
|
const css = findVariable({
|
|
14
15
|
identifier: specifier.local,
|
|
15
|
-
sourceCode:
|
|
16
|
+
sourceCode: getSourceCode(context)
|
|
16
17
|
});
|
|
17
18
|
return css !== null && isSafeCss(css);
|
|
18
19
|
}
|
|
19
20
|
if (importName === 'keyframes') {
|
|
20
21
|
const keyframes = findVariable({
|
|
21
22
|
identifier: specifier.local,
|
|
22
|
-
sourceCode:
|
|
23
|
+
sourceCode: getSourceCode(context)
|
|
23
24
|
});
|
|
24
25
|
return keyframes !== null && isSafeKeyframes(keyframes);
|
|
25
26
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
1
2
|
export function getFirstImportFromSource(context, source) {
|
|
2
|
-
return
|
|
3
|
+
return getSourceCode(context).ast.body.filter(isImportDeclaration).find(node => node.source.value === source);
|
|
3
4
|
}
|
|
4
5
|
function isImportDeclaration(node) {
|
|
5
6
|
return node.type === 'ImportDeclaration';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getAncestors, getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
1
2
|
import { getImportSources, isCompiled } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
3
|
import { createLintRule } from '../utils/create-rule';
|
|
3
4
|
var isIdentifierReferenced = function isIdentifierReferenced(hasImportSpecifier, node, references) {
|
|
@@ -57,10 +58,10 @@ export var rule = createLintRule({
|
|
|
57
58
|
create: function create(context) {
|
|
58
59
|
var importSources = getImportSources(context);
|
|
59
60
|
return {
|
|
60
|
-
'CallExpression Identifier': function
|
|
61
|
-
var
|
|
62
|
-
references =
|
|
63
|
-
var ancestors =
|
|
61
|
+
'CallExpression Identifier': function CallExpression_Identifier(node) {
|
|
62
|
+
var _getScope = getScope(context, node),
|
|
63
|
+
references = _getScope.references;
|
|
64
|
+
var ancestors = getAncestors(context, node);
|
|
64
65
|
|
|
65
66
|
// Check if ancestor node is a call expression to Compiled
|
|
66
67
|
if (ancestors.some(function (ancestor) {
|
|
@@ -73,10 +74,10 @@ export var rule = createLintRule({
|
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
},
|
|
76
|
-
'TaggedTemplateExpression Identifier': function
|
|
77
|
-
var
|
|
78
|
-
references =
|
|
79
|
-
var ancestors =
|
|
77
|
+
'TaggedTemplateExpression Identifier': function TaggedTemplateExpression_Identifier(node) {
|
|
78
|
+
var _getScope2 = getScope(context, node),
|
|
79
|
+
references = _getScope2.references;
|
|
80
|
+
var ancestors = getAncestors(context, node);
|
|
80
81
|
|
|
81
82
|
// Check if ancestor node is a tagged template expression to Compiled
|
|
82
83
|
if (ancestors.some(function (ancestor) {
|
|
@@ -4,6 +4,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
4
4
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
5
|
import { analyze } from 'eslint-scope';
|
|
6
6
|
import ESTraverse from 'estraverse';
|
|
7
|
+
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
7
8
|
import { isEmotion, isStyledComponents } from '@atlaskit/eslint-utils/is-supported-import';
|
|
8
9
|
import { createLintRule } from '../utils/create-rule';
|
|
9
10
|
|
|
@@ -212,7 +213,7 @@ var lintArguments = function lintArguments(context, args) {
|
|
|
212
213
|
ESTraverse.traverse(property.value, {
|
|
213
214
|
enter: function enter(node, _parent) {
|
|
214
215
|
if (node.type === 'ArrowFunctionExpression') {
|
|
215
|
-
var propNames = parseArrowFunctionExpression(node,
|
|
216
|
+
var propNames = parseArrowFunctionExpression(node, getSourceCode(context));
|
|
216
217
|
if (!propNames) {
|
|
217
218
|
// We've encountered a CSS value we don't recognise, skip.
|
|
218
219
|
return;
|
|
@@ -250,7 +251,7 @@ var lintArguments = function lintArguments(context, args) {
|
|
|
250
251
|
node: argument,
|
|
251
252
|
messageId: 'unsupported-prop-syntax',
|
|
252
253
|
fix: function fix(fixer) {
|
|
253
|
-
var sourceCode =
|
|
254
|
+
var sourceCode = getSourceCode(context);
|
|
254
255
|
return fixPropsObjectUsages(fixer, sourceCode, argument,
|
|
255
256
|
// The
|
|
256
257
|
// allProps.some((propUsage) => !propUsage.valid)
|
|
@@ -381,7 +382,8 @@ export var rule = createLintRule({
|
|
|
381
382
|
return {
|
|
382
383
|
CallExpression: function CallExpression(node) {
|
|
383
384
|
var _node$parent, _node$parent2;
|
|
384
|
-
var
|
|
385
|
+
var _getScope = getScope(context, node),
|
|
386
|
+
references = _getScope.references;
|
|
385
387
|
|
|
386
388
|
// Rule should ignore .attrs() calls
|
|
387
389
|
if (node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'attrs') {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
2
|
import { getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
3
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
3
4
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
4
5
|
import { createLintRule } from '../utils/create-rule';
|
|
5
6
|
var isParameter = function isParameter(context, identifier) {
|
|
6
7
|
var _findVariable;
|
|
7
8
|
var definitions = (_findVariable = findVariable({
|
|
8
|
-
sourceCode:
|
|
9
|
+
sourceCode: getSourceCode(context),
|
|
9
10
|
identifier: identifier
|
|
10
11
|
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
11
12
|
if (!definitions || !definitions.length) {
|
|
@@ -17,7 +18,7 @@ var isParameter = function isParameter(context, identifier) {
|
|
|
17
18
|
var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
18
19
|
var _variable$identifiers;
|
|
19
20
|
var variable = findVariable({
|
|
20
|
-
sourceCode:
|
|
21
|
+
sourceCode: getSourceCode(context),
|
|
21
22
|
identifier: identifier
|
|
22
23
|
});
|
|
23
24
|
if (!variable) {
|
|
@@ -77,7 +78,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
77
78
|
return isIdentifierAllowed(context, property.value);
|
|
78
79
|
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier') {
|
|
79
80
|
var variable = findVariable({
|
|
80
|
-
sourceCode:
|
|
81
|
+
sourceCode: getSourceCode(context),
|
|
81
82
|
identifier: property.value.callee
|
|
82
83
|
});
|
|
83
84
|
// Anything returned by getAllowedFunctionCalls should be used in css prop instead
|
|
@@ -91,7 +92,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
91
92
|
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
92
93
|
var _findVariable2;
|
|
93
94
|
var definitions = (_findVariable2 = findVariable({
|
|
94
|
-
sourceCode:
|
|
95
|
+
sourceCode: getSourceCode(context),
|
|
95
96
|
identifier: property.value.object
|
|
96
97
|
})) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
|
|
97
98
|
if (!definitions || !definitions.length) {
|
|
@@ -133,7 +134,7 @@ export var rule = createLintRule({
|
|
|
133
134
|
},
|
|
134
135
|
create: function create(context) {
|
|
135
136
|
return {
|
|
136
|
-
'JSXAttribute[name.name="style"] > JSXExpressionContainer': function
|
|
137
|
+
'JSXAttribute[name.name="style"] > JSXExpressionContainer': function JSXAttributeNameNameStyle__JSXExpressionContainer(node) {
|
|
137
138
|
var _node$expression$expr, _expression;
|
|
138
139
|
if (!isNodeOfType(node, 'JSXExpressionContainer')) {
|
|
139
140
|
return;
|
|
@@ -164,7 +165,7 @@ export var rule = createLintRule({
|
|
|
164
165
|
* ```
|
|
165
166
|
*/
|
|
166
167
|
var variable = findVariable({
|
|
167
|
-
sourceCode:
|
|
168
|
+
sourceCode: getSourceCode(context),
|
|
168
169
|
identifier: node.expression
|
|
169
170
|
});
|
|
170
171
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
2
2
|
import { CSS_IN_JS_IMPORTS, isCxFunction } from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
|
+
import { createLintRule } from '../utils/create-rule';
|
|
3
4
|
var IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
|
|
4
5
|
function getParentJSXAttribute(node) {
|
|
5
6
|
var parent = node.parent;
|
|
@@ -27,7 +28,7 @@ export var rule = createLintRule({
|
|
|
27
28
|
create: function create(context) {
|
|
28
29
|
return {
|
|
29
30
|
'CallExpression[callee.name="cx"]': function CallExpressionCalleeNameCx(node) {
|
|
30
|
-
if (node.type === 'CallExpression' && isCxFunction(node.callee,
|
|
31
|
+
if (node.type === 'CallExpression' && isCxFunction(node.callee, getScope(context, node).references, IMPORT_SOURCES)) {
|
|
31
32
|
var parentJSXAttribute = getParentJSXAttribute(node);
|
|
32
33
|
var propName = parentJSXAttribute === null || parentJSXAttribute === void 0 ? void 0 : parentJSXAttribute.name.name.toString();
|
|
33
34
|
if (propName && /[xX]css$/.test(propName)) {
|
|
@@ -3,6 +3,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
3
3
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
4
|
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
5
5
|
|
|
6
|
+
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
6
7
|
import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
7
8
|
import { createLintRule } from '../utils/create-rule';
|
|
8
9
|
var schema = [{
|
|
@@ -36,8 +37,8 @@ export var rule = createLintRule({
|
|
|
36
37
|
var importSources = getImportSources(context);
|
|
37
38
|
return {
|
|
38
39
|
CallExpression: function CallExpression(node) {
|
|
39
|
-
var
|
|
40
|
-
references =
|
|
40
|
+
var _getScope = getScope(context, node),
|
|
41
|
+
references = _getScope.references;
|
|
41
42
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
42
43
|
return;
|
|
43
44
|
}
|
|
@@ -66,7 +67,7 @@ export var rule = createLintRule({
|
|
|
66
67
|
var items = argument.elements.filter(function (value) {
|
|
67
68
|
return value !== null;
|
|
68
69
|
}).map(function (element) {
|
|
69
|
-
return
|
|
70
|
+
return getSourceCode(context).getText(element);
|
|
70
71
|
});
|
|
71
72
|
return fixer.replaceText(argument, items.join(', '));
|
|
72
73
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @atlassian/tangerine/import/entry-points */
|
|
2
2
|
|
|
3
3
|
import estraverse from 'estraverse';
|
|
4
|
+
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
4
5
|
import { getImportSources, isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
5
6
|
import { createLintRule } from '../utils/create-rule';
|
|
6
7
|
var schema = [{
|
|
@@ -33,8 +34,8 @@ export var rule = createLintRule({
|
|
|
33
34
|
var importSources = getImportSources(context);
|
|
34
35
|
return {
|
|
35
36
|
CallExpression: function CallExpression(node) {
|
|
36
|
-
var
|
|
37
|
-
references =
|
|
37
|
+
var _getScope = getScope(context, node),
|
|
38
|
+
references = _getScope.references;
|
|
38
39
|
if (isCss(node.callee, references, importSources) || isStyled(node.callee, references, importSources) || isKeyframes(node.callee, references, importSources) || isCssMap(node.callee, references, importSources) || isXcss(node.callee, references, importSources)) {
|
|
39
40
|
estraverse.traverse(node, {
|
|
40
41
|
enter: function enter(node) {
|
|
@@ -3,6 +3,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
3
3
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
4
|
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
5
5
|
import esquery from 'esquery';
|
|
6
|
+
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
6
7
|
import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
7
8
|
import { createLintRule } from '../utils/create-rule';
|
|
8
9
|
var schema = [{
|
|
@@ -35,8 +36,8 @@ export var rule = createLintRule({
|
|
|
35
36
|
var importSources = getImportSources(context);
|
|
36
37
|
return {
|
|
37
38
|
CallExpression: function CallExpression(node) {
|
|
38
|
-
var
|
|
39
|
-
references =
|
|
39
|
+
var _getScope = getScope(context, node),
|
|
40
|
+
references = _getScope.references;
|
|
40
41
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
@@ -2,6 +2,7 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
|
|
|
2
2
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
3
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
4
|
import esquery from 'esquery';
|
|
5
|
+
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
5
6
|
import { hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
6
7
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
7
8
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
@@ -28,8 +29,8 @@ export var rule = createLintRuleWithTypedConfig({
|
|
|
28
29
|
var importSources = _ref.importSources;
|
|
29
30
|
return {
|
|
30
31
|
CallExpression: function CallExpression(node) {
|
|
31
|
-
var
|
|
32
|
-
references =
|
|
32
|
+
var _getScope = getScope(context, node),
|
|
33
|
+
references = _getScope.references;
|
|
33
34
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
34
35
|
return;
|
|
35
36
|
}
|