@atlaskit/eslint-plugin-ui-styling-standard 2.1.4 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 2.1.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`fdedfb06aa229`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/fdedfb06aa229) -
|
|
8
|
+
Allow canonical typed media queries and typed container-query exceptions in styling lint rules.
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 2.1.4
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -21,6 +21,60 @@ var schema = [{
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}];
|
|
24
|
+
var unwrapTypeScriptExpression = function unwrapTypeScriptExpression(node) {
|
|
25
|
+
var expression = node;
|
|
26
|
+
while (expression.type === 'TSAsExpression' || expression.type === 'TSTypeAssertion' || expression.type === 'TSNonNullExpression' || expression.type === 'TSSatisfiesExpression') {
|
|
27
|
+
expression = expression.expression;
|
|
28
|
+
}
|
|
29
|
+
return expression;
|
|
30
|
+
};
|
|
31
|
+
var isStaticContainerKey = function isStaticContainerKey(node) {
|
|
32
|
+
var _expression$expressio;
|
|
33
|
+
var expression = unwrapTypeScriptExpression(node);
|
|
34
|
+
if (expression.type === 'Literal') {
|
|
35
|
+
return typeof expression.value === 'string';
|
|
36
|
+
}
|
|
37
|
+
return expression.type === 'TemplateLiteral' && ((_expression$expressio = expression.expressions) === null || _expression$expressio === void 0 ? void 0 : _expression$expressio.length) === 0;
|
|
38
|
+
};
|
|
39
|
+
var isImportedContainerType = function isImportedContainerType(node, context) {
|
|
40
|
+
var expression = node;
|
|
41
|
+
var _loop = function _loop() {
|
|
42
|
+
var _typeAnnotation$typeN;
|
|
43
|
+
var _expression = expression,
|
|
44
|
+
typeAnnotation = _expression.typeAnnotation;
|
|
45
|
+
if ((typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation.type) === 'TSTypeReference' && ((_typeAnnotation$typeN = typeAnnotation.typeName) === null || _typeAnnotation$typeN === void 0 ? void 0 : _typeAnnotation$typeN.type) === 'Identifier') {
|
|
46
|
+
var typeName = typeAnnotation.typeName.name;
|
|
47
|
+
var isImported = (0, _contextCompat.getSourceCode)(context).ast.body.some(function (statement) {
|
|
48
|
+
return statement.type === 'ImportDeclaration' && statement.source.value === '@atlaskit/css/at-rules/container' && statement.specifiers.some(function (specifier) {
|
|
49
|
+
return specifier.type === 'ImportDefaultSpecifier' && specifier.local.name === typeName;
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
if (isImported) {
|
|
53
|
+
return {
|
|
54
|
+
v: true
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
expression = expression.expression;
|
|
59
|
+
},
|
|
60
|
+
_ret;
|
|
61
|
+
while (expression.type === 'TSSatisfiesExpression') {
|
|
62
|
+
_ret = _loop();
|
|
63
|
+
if (_ret) return _ret.v;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
};
|
|
67
|
+
var isContainerQuery = function isContainerQuery(node) {
|
|
68
|
+
var _expression$quasis;
|
|
69
|
+
var expression = unwrapTypeScriptExpression(node);
|
|
70
|
+
if (expression.type === 'Literal' && typeof expression.value === 'string') {
|
|
71
|
+
return expression.value.includes('@container');
|
|
72
|
+
}
|
|
73
|
+
return expression.type === 'TemplateLiteral' && Boolean((_expression$quasis = expression.quasis) === null || _expression$quasis === void 0 ? void 0 : _expression$quasis.some(function (quasi) {
|
|
74
|
+
var _quasi$value;
|
|
75
|
+
return (_quasi$value = quasi.value) === null || _quasi$value === void 0 || (_quasi$value = _quasi$value.raw) === null || _quasi$value === void 0 ? void 0 : _quasi$value.includes('@container');
|
|
76
|
+
}));
|
|
77
|
+
};
|
|
24
78
|
var rule = (0, _createRule.createLintRule)({
|
|
25
79
|
meta: {
|
|
26
80
|
name: 'no-container-queries',
|
|
@@ -44,25 +98,20 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
44
98
|
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)) {
|
|
45
99
|
_estraverse.default.traverse(node, {
|
|
46
100
|
enter: function enter(node) {
|
|
47
|
-
var _node$key$value, _node$key$quasis$;
|
|
48
101
|
if (node.type !== 'Property') {
|
|
49
102
|
return;
|
|
50
103
|
}
|
|
51
|
-
|
|
104
|
+
var key = node.key;
|
|
105
|
+
if (!isContainerQuery(key)) {
|
|
52
106
|
return;
|
|
53
107
|
}
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
node: node.key,
|
|
57
|
-
messageId: 'no-container-queries'
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (node.key.type === 'TemplateLiteral' && (_node$key$quasis$ = node.key.quasis[0]) !== null && _node$key$quasis$ !== void 0 && _node$key$quasis$.value.raw.match(/@container/)) {
|
|
61
|
-
context.report({
|
|
62
|
-
node: node.key,
|
|
63
|
-
messageId: 'no-container-queries'
|
|
64
|
-
});
|
|
108
|
+
if (isImportedContainerType(key, context) && isStaticContainerKey(key.expression)) {
|
|
109
|
+
return;
|
|
65
110
|
}
|
|
111
|
+
context.report({
|
|
112
|
+
node: node.key,
|
|
113
|
+
messageId: 'no-container-queries'
|
|
114
|
+
});
|
|
66
115
|
},
|
|
67
116
|
/**
|
|
68
117
|
* This is needed to handle unknown node types. Otherwise an error is thrown.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import estraverse from 'estraverse';
|
|
2
|
-
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
2
|
+
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
3
3
|
import { getImportSources, isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
4
4
|
import { createLintRule } from '../utils/create-rule';
|
|
5
5
|
const schema = [{
|
|
@@ -14,6 +14,50 @@ const schema = [{
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}];
|
|
17
|
+
const unwrapTypeScriptExpression = node => {
|
|
18
|
+
let expression = node;
|
|
19
|
+
while (expression.type === 'TSAsExpression' || expression.type === 'TSTypeAssertion' || expression.type === 'TSNonNullExpression' || expression.type === 'TSSatisfiesExpression') {
|
|
20
|
+
expression = expression.expression;
|
|
21
|
+
}
|
|
22
|
+
return expression;
|
|
23
|
+
};
|
|
24
|
+
const isStaticContainerKey = node => {
|
|
25
|
+
var _expression$expressio;
|
|
26
|
+
const expression = unwrapTypeScriptExpression(node);
|
|
27
|
+
if (expression.type === 'Literal') {
|
|
28
|
+
return typeof expression.value === 'string';
|
|
29
|
+
}
|
|
30
|
+
return expression.type === 'TemplateLiteral' && ((_expression$expressio = expression.expressions) === null || _expression$expressio === void 0 ? void 0 : _expression$expressio.length) === 0;
|
|
31
|
+
};
|
|
32
|
+
const isImportedContainerType = (node, context) => {
|
|
33
|
+
let expression = node;
|
|
34
|
+
while (expression.type === 'TSSatisfiesExpression') {
|
|
35
|
+
var _typeAnnotation$typeN;
|
|
36
|
+
const {
|
|
37
|
+
typeAnnotation
|
|
38
|
+
} = expression;
|
|
39
|
+
if ((typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation.type) === 'TSTypeReference' && ((_typeAnnotation$typeN = typeAnnotation.typeName) === null || _typeAnnotation$typeN === void 0 ? void 0 : _typeAnnotation$typeN.type) === 'Identifier') {
|
|
40
|
+
const typeName = typeAnnotation.typeName.name;
|
|
41
|
+
const isImported = getSourceCode(context).ast.body.some(statement => statement.type === 'ImportDeclaration' && statement.source.value === '@atlaskit/css/at-rules/container' && statement.specifiers.some(specifier => specifier.type === 'ImportDefaultSpecifier' && specifier.local.name === typeName));
|
|
42
|
+
if (isImported) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
expression = expression.expression;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
};
|
|
50
|
+
const isContainerQuery = node => {
|
|
51
|
+
var _expression$quasis;
|
|
52
|
+
const expression = unwrapTypeScriptExpression(node);
|
|
53
|
+
if (expression.type === 'Literal' && typeof expression.value === 'string') {
|
|
54
|
+
return expression.value.includes('@container');
|
|
55
|
+
}
|
|
56
|
+
return expression.type === 'TemplateLiteral' && Boolean((_expression$quasis = expression.quasis) === null || _expression$quasis === void 0 ? void 0 : _expression$quasis.some(quasi => {
|
|
57
|
+
var _quasi$value, _quasi$value$raw;
|
|
58
|
+
return (_quasi$value = quasi.value) === null || _quasi$value === void 0 ? void 0 : (_quasi$value$raw = _quasi$value.raw) === null || _quasi$value$raw === void 0 ? void 0 : _quasi$value$raw.includes('@container');
|
|
59
|
+
}));
|
|
60
|
+
};
|
|
17
61
|
const rule = createLintRule({
|
|
18
62
|
meta: {
|
|
19
63
|
name: 'no-container-queries',
|
|
@@ -38,25 +82,20 @@ const rule = createLintRule({
|
|
|
38
82
|
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
83
|
estraverse.traverse(node, {
|
|
40
84
|
enter(node) {
|
|
41
|
-
var _node$key$value, _node$key$quasis$;
|
|
42
85
|
if (node.type !== 'Property') {
|
|
43
86
|
return;
|
|
44
87
|
}
|
|
45
|
-
|
|
88
|
+
const key = node.key;
|
|
89
|
+
if (!isContainerQuery(key)) {
|
|
46
90
|
return;
|
|
47
91
|
}
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
node: node.key,
|
|
51
|
-
messageId: 'no-container-queries'
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
if (node.key.type === 'TemplateLiteral' && (_node$key$quasis$ = node.key.quasis[0]) !== null && _node$key$quasis$ !== void 0 && _node$key$quasis$.value.raw.match(/@container/)) {
|
|
55
|
-
context.report({
|
|
56
|
-
node: node.key,
|
|
57
|
-
messageId: 'no-container-queries'
|
|
58
|
-
});
|
|
92
|
+
if (isImportedContainerType(key, context) && isStaticContainerKey(key.expression)) {
|
|
93
|
+
return;
|
|
59
94
|
}
|
|
95
|
+
context.report({
|
|
96
|
+
node: node.key,
|
|
97
|
+
messageId: 'no-container-queries'
|
|
98
|
+
});
|
|
60
99
|
},
|
|
61
100
|
/**
|
|
62
101
|
* This is needed to handle unknown node types. Otherwise an error is thrown.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import estraverse from 'estraverse';
|
|
2
|
-
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
2
|
+
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
3
3
|
import { getImportSources, isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
4
4
|
import { createLintRule } from '../utils/create-rule';
|
|
5
5
|
var schema = [{
|
|
@@ -14,6 +14,60 @@ var schema = [{
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}];
|
|
17
|
+
var unwrapTypeScriptExpression = function unwrapTypeScriptExpression(node) {
|
|
18
|
+
var expression = node;
|
|
19
|
+
while (expression.type === 'TSAsExpression' || expression.type === 'TSTypeAssertion' || expression.type === 'TSNonNullExpression' || expression.type === 'TSSatisfiesExpression') {
|
|
20
|
+
expression = expression.expression;
|
|
21
|
+
}
|
|
22
|
+
return expression;
|
|
23
|
+
};
|
|
24
|
+
var isStaticContainerKey = function isStaticContainerKey(node) {
|
|
25
|
+
var _expression$expressio;
|
|
26
|
+
var expression = unwrapTypeScriptExpression(node);
|
|
27
|
+
if (expression.type === 'Literal') {
|
|
28
|
+
return typeof expression.value === 'string';
|
|
29
|
+
}
|
|
30
|
+
return expression.type === 'TemplateLiteral' && ((_expression$expressio = expression.expressions) === null || _expression$expressio === void 0 ? void 0 : _expression$expressio.length) === 0;
|
|
31
|
+
};
|
|
32
|
+
var isImportedContainerType = function isImportedContainerType(node, context) {
|
|
33
|
+
var expression = node;
|
|
34
|
+
var _loop = function _loop() {
|
|
35
|
+
var _typeAnnotation$typeN;
|
|
36
|
+
var _expression = expression,
|
|
37
|
+
typeAnnotation = _expression.typeAnnotation;
|
|
38
|
+
if ((typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation.type) === 'TSTypeReference' && ((_typeAnnotation$typeN = typeAnnotation.typeName) === null || _typeAnnotation$typeN === void 0 ? void 0 : _typeAnnotation$typeN.type) === 'Identifier') {
|
|
39
|
+
var typeName = typeAnnotation.typeName.name;
|
|
40
|
+
var isImported = getSourceCode(context).ast.body.some(function (statement) {
|
|
41
|
+
return statement.type === 'ImportDeclaration' && statement.source.value === '@atlaskit/css/at-rules/container' && statement.specifiers.some(function (specifier) {
|
|
42
|
+
return specifier.type === 'ImportDefaultSpecifier' && specifier.local.name === typeName;
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
if (isImported) {
|
|
46
|
+
return {
|
|
47
|
+
v: true
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
expression = expression.expression;
|
|
52
|
+
},
|
|
53
|
+
_ret;
|
|
54
|
+
while (expression.type === 'TSSatisfiesExpression') {
|
|
55
|
+
_ret = _loop();
|
|
56
|
+
if (_ret) return _ret.v;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
};
|
|
60
|
+
var isContainerQuery = function isContainerQuery(node) {
|
|
61
|
+
var _expression$quasis;
|
|
62
|
+
var expression = unwrapTypeScriptExpression(node);
|
|
63
|
+
if (expression.type === 'Literal' && typeof expression.value === 'string') {
|
|
64
|
+
return expression.value.includes('@container');
|
|
65
|
+
}
|
|
66
|
+
return expression.type === 'TemplateLiteral' && Boolean((_expression$quasis = expression.quasis) === null || _expression$quasis === void 0 ? void 0 : _expression$quasis.some(function (quasi) {
|
|
67
|
+
var _quasi$value;
|
|
68
|
+
return (_quasi$value = quasi.value) === null || _quasi$value === void 0 || (_quasi$value = _quasi$value.raw) === null || _quasi$value === void 0 ? void 0 : _quasi$value.includes('@container');
|
|
69
|
+
}));
|
|
70
|
+
};
|
|
17
71
|
var rule = createLintRule({
|
|
18
72
|
meta: {
|
|
19
73
|
name: 'no-container-queries',
|
|
@@ -37,25 +91,20 @@ var rule = createLintRule({
|
|
|
37
91
|
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)) {
|
|
38
92
|
estraverse.traverse(node, {
|
|
39
93
|
enter: function enter(node) {
|
|
40
|
-
var _node$key$value, _node$key$quasis$;
|
|
41
94
|
if (node.type !== 'Property') {
|
|
42
95
|
return;
|
|
43
96
|
}
|
|
44
|
-
|
|
97
|
+
var key = node.key;
|
|
98
|
+
if (!isContainerQuery(key)) {
|
|
45
99
|
return;
|
|
46
100
|
}
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
node: node.key,
|
|
50
|
-
messageId: 'no-container-queries'
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
if (node.key.type === 'TemplateLiteral' && (_node$key$quasis$ = node.key.quasis[0]) !== null && _node$key$quasis$ !== void 0 && _node$key$quasis$.value.raw.match(/@container/)) {
|
|
54
|
-
context.report({
|
|
55
|
-
node: node.key,
|
|
56
|
-
messageId: 'no-container-queries'
|
|
57
|
-
});
|
|
101
|
+
if (isImportedContainerType(key, context) && isStaticContainerKey(key.expression)) {
|
|
102
|
+
return;
|
|
58
103
|
}
|
|
104
|
+
context.report({
|
|
105
|
+
node: node.key,
|
|
106
|
+
messageId: 'no-container-queries'
|
|
107
|
+
});
|
|
59
108
|
},
|
|
60
109
|
/**
|
|
61
110
|
* This is needed to handle unknown node types. Otherwise an error is thrown.
|
package/package.json
CHANGED