@atlaskit/eslint-plugin-ui-styling-standard 0.20.1 → 1.0.0
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 +23 -0
- package/README.md +2 -5
- package/dist/cjs/index.codegen.js +45 -10
- package/dist/cjs/index.js +22 -1
- package/dist/cjs/presets/all-flat.codegen.js +53 -0
- package/dist/cjs/presets/all.codegen.js +2 -9
- package/dist/cjs/presets/recommended-flat.codegen.js +53 -0
- package/dist/cjs/presets/recommended.codegen.js +2 -9
- package/dist/cjs/rules/enforce-style-prop/index.js +45 -17
- package/dist/cjs/rules/external-rules.js +0 -38
- package/dist/cjs/rules/index.codegen.js +4 -3
- package/dist/es2019/index.codegen.js +50 -6
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/presets/all-flat.codegen.js +44 -0
- package/dist/es2019/presets/all.codegen.js +2 -9
- package/dist/es2019/presets/recommended-flat.codegen.js +44 -0
- package/dist/es2019/presets/recommended.codegen.js +2 -9
- package/dist/es2019/rules/enforce-style-prop/index.js +45 -17
- package/dist/es2019/rules/external-rules.js +0 -38
- package/dist/es2019/rules/index.codegen.js +2 -2
- package/dist/esm/index.codegen.js +46 -6
- package/dist/esm/index.js +1 -1
- package/dist/esm/presets/all-flat.codegen.js +44 -0
- package/dist/esm/presets/all.codegen.js +2 -9
- package/dist/esm/presets/recommended-flat.codegen.js +44 -0
- package/dist/esm/presets/recommended.codegen.js +2 -9
- package/dist/esm/rules/enforce-style-prop/index.js +45 -17
- package/dist/esm/rules/external-rules.js +0 -38
- package/dist/esm/rules/index.codegen.js +2 -2
- package/dist/types/index.codegen.d.ts +370 -81
- package/dist/types/index.d.ts +1 -1
- package/dist/types/presets/all-flat.codegen.d.ts +44 -0
- package/dist/types/presets/all.codegen.d.ts +33 -40
- package/dist/types/presets/recommended-flat.codegen.d.ts +44 -0
- package/dist/types/presets/recommended.codegen.d.ts +33 -40
- package/dist/types/rules/index.codegen.d.ts +1 -2
- package/dist/types-ts4.5/index.codegen.d.ts +550 -81
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +65 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +57 -40
- package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +65 -0
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +57 -40
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -2
- package/package.json +11 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
-
import { createLintRule } from '../utils/create-rule';
|
|
3
2
|
import { getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
4
3
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
4
|
+
import { createLintRule } from '../utils/create-rule';
|
|
5
5
|
var isParameter = function isParameter(context, identifier) {
|
|
6
6
|
var _findVariable;
|
|
7
7
|
var definitions = (_findVariable = findVariable({
|
|
@@ -15,7 +15,7 @@ var isParameter = function isParameter(context, identifier) {
|
|
|
15
15
|
return result.type === 'Parameter';
|
|
16
16
|
};
|
|
17
17
|
var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
18
|
-
var
|
|
18
|
+
var _variable$identifiers;
|
|
19
19
|
var variable = findVariable({
|
|
20
20
|
sourceCode: context.getSourceCode(),
|
|
21
21
|
identifier: identifier
|
|
@@ -25,30 +25,44 @@ var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
|
25
25
|
}
|
|
26
26
|
var variableDefinition = variable.defs[0].node;
|
|
27
27
|
|
|
28
|
+
// console.log('@@variableDefinition', variableDefinition);
|
|
29
|
+
|
|
28
30
|
// If identifier is a RestElement, report warning
|
|
29
|
-
if (((
|
|
31
|
+
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') {
|
|
30
32
|
return false;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
// Checking if identifier has been destructured from props within function
|
|
34
36
|
if (variableDefinition.type === 'VariableDeclarator') {
|
|
35
|
-
var
|
|
37
|
+
var _init, _init2, _init3, _init4;
|
|
36
38
|
// If it's a let variable, ignore
|
|
37
39
|
if (variableDefinition.parent.kind === 'let') {
|
|
38
40
|
return true;
|
|
39
41
|
}
|
|
42
|
+
|
|
43
|
+
// Allow for `const { width } = props as Props` (etc)
|
|
44
|
+
var init = variableDefinition.init;
|
|
45
|
+
if (((_init = init) === null || _init === void 0 ? void 0 : _init.type) === 'TSAsExpression') {
|
|
46
|
+
init = init.expression;
|
|
47
|
+
}
|
|
48
|
+
|
|
40
49
|
// If it's initialised by a call expression, ignore
|
|
41
|
-
if (((
|
|
50
|
+
if (((_init2 = init) === null || _init2 === void 0 ? void 0 : _init2.type) === 'CallExpression') {
|
|
42
51
|
return true;
|
|
43
52
|
}
|
|
44
53
|
// Destructured from member expression
|
|
45
54
|
// e.g. const width = props.width
|
|
46
|
-
if (((
|
|
47
|
-
return isParameter(context,
|
|
55
|
+
if (((_init3 = init) === null || _init3 === void 0 ? void 0 : _init3.type) === 'MemberExpression') {
|
|
56
|
+
return isParameter(context, init.object);
|
|
57
|
+
}
|
|
58
|
+
// Destructured from an asserted
|
|
59
|
+
// e.g. const width = props.width
|
|
60
|
+
if (((_init4 = init) === null || _init4 === void 0 ? void 0 : _init4.type) === 'MemberExpression') {
|
|
61
|
+
return isParameter(context, init.object);
|
|
48
62
|
}
|
|
49
63
|
// Destructured from object pattern
|
|
50
64
|
// e.g. const { width } = props
|
|
51
|
-
return isParameter(context,
|
|
65
|
+
return isParameter(context, init);
|
|
52
66
|
}
|
|
53
67
|
// If identifier has not been deconstructed from parameter or is a RestElement, report warning
|
|
54
68
|
return isParameter(context, identifier);
|
|
@@ -121,26 +135,40 @@ export var rule = createLintRule({
|
|
|
121
135
|
create: function create(context) {
|
|
122
136
|
return {
|
|
123
137
|
'JSXAttribute[name.name="style"] > JSXExpressionContainer': function JSXAttributeNameNameStyleJSXExpressionContainer(node) {
|
|
138
|
+
var _node$expression$expr;
|
|
124
139
|
if (!isNodeOfType(node, 'JSXExpressionContainer')) {
|
|
125
140
|
return;
|
|
126
141
|
}
|
|
142
|
+
|
|
127
143
|
// we've reached an attribute named style
|
|
128
144
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
145
|
+
var expression;
|
|
146
|
+
if (
|
|
147
|
+
// @ts-expect-error -- TSAsExpression is not valid in estree
|
|
148
|
+
node.expression.type === 'TSAsExpression' &&
|
|
149
|
+
// @ts-expect-error -- TSAsExpression is not valid in estree
|
|
150
|
+
((_node$expression$expr = node.expression.expression) === null || _node$expression$expr === void 0 ? void 0 : _node$expression$expr.type) === 'ObjectExpression') {
|
|
151
|
+
// This is a `style={{ … } as React.CSSProperties}` scenario
|
|
152
|
+
// @ts-expect-error -- TSAsExpression is not valid in estree
|
|
153
|
+
expression = node.expression.expression;
|
|
154
|
+
} else if (node.expression.type === 'ObjectExpression') {
|
|
155
|
+
// Typical `style={{ … }}` scenario
|
|
156
|
+
expression = node.expression;
|
|
138
157
|
} else {
|
|
139
158
|
context.report({
|
|
140
159
|
node: node,
|
|
141
160
|
messageId: 'enforce-style-prop'
|
|
142
161
|
});
|
|
162
|
+
return;
|
|
143
163
|
}
|
|
164
|
+
expression.properties.forEach(function (value) {
|
|
165
|
+
if (!isPropertyValueAllowed(value, context)) {
|
|
166
|
+
context.report({
|
|
167
|
+
node: value,
|
|
168
|
+
messageId: 'enforce-style-prop'
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
144
172
|
}
|
|
145
173
|
};
|
|
146
174
|
}
|
|
@@ -61,28 +61,6 @@ export var externalRules = [{
|
|
|
61
61
|
recommended: true,
|
|
62
62
|
severity: 'error'
|
|
63
63
|
}
|
|
64
|
-
}, {
|
|
65
|
-
name: '@compiled/no-suppress-xcss',
|
|
66
|
-
displayName: 'no-suppress-xcss',
|
|
67
|
-
isExternal: true,
|
|
68
|
-
docs: {
|
|
69
|
-
description: 'Disallows supressing type violations when using the xcss prop.',
|
|
70
|
-
url: getRuleUrl('no-suppress-xcss'),
|
|
71
|
-
externalUrl: 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-suppress-xcss',
|
|
72
|
-
recommended: true,
|
|
73
|
-
severity: 'error'
|
|
74
|
-
}
|
|
75
|
-
}, {
|
|
76
|
-
name: '@compiled/no-js-xcss',
|
|
77
|
-
displayName: 'no-js-xcss',
|
|
78
|
-
isExternal: true,
|
|
79
|
-
docs: {
|
|
80
|
-
description: 'Disallows using xcss prop inside JavaScript files.',
|
|
81
|
-
url: getRuleUrl('no-js-xcss'),
|
|
82
|
-
externalUrl: 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-js-xcss',
|
|
83
|
-
recommended: true,
|
|
84
|
-
severity: 'error'
|
|
85
|
-
}
|
|
86
64
|
}, {
|
|
87
65
|
name: '@atlaskit/design-system/no-empty-styled-expression',
|
|
88
66
|
displayName: 'no-empty-styled-expression',
|
|
@@ -111,20 +89,4 @@ export var externalRules = [{
|
|
|
111
89
|
allowedFunctionCalls: [['@atlaskit/tokens', 'token']]
|
|
112
90
|
}
|
|
113
91
|
}
|
|
114
|
-
}, {
|
|
115
|
-
name: '@compiled/jsx-pragma',
|
|
116
|
-
displayName: 'jsx-pragma',
|
|
117
|
-
isExternal: true,
|
|
118
|
-
docs: {
|
|
119
|
-
description: 'Ensures that the Compiled JSX pragma is set when using Compiled',
|
|
120
|
-
url: getRuleUrl('jsx-pragma'),
|
|
121
|
-
externalUrl: 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/jsx-pragma',
|
|
122
|
-
recommended: true,
|
|
123
|
-
severity: 'error',
|
|
124
|
-
pluginConfig: {
|
|
125
|
-
runtime: 'classic',
|
|
126
|
-
onlyRunIfImportingCompiled: true,
|
|
127
|
-
importSources: ['@atlaskit/css']
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
92
|
}];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::71ba23a2a1467988c4fae8c2756447f9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -20,7 +20,7 @@ import noStyled from './no-styled';
|
|
|
20
20
|
import noUnsafeSelectors from './no-unsafe-selectors';
|
|
21
21
|
import noUnsafeValues from './no-unsafe-values';
|
|
22
22
|
import useCompiled from './use-compiled';
|
|
23
|
-
export
|
|
23
|
+
export var rules = {
|
|
24
24
|
'atlaskit-theme': atlaskitTheme,
|
|
25
25
|
'convert-props-syntax': convertPropsSyntax,
|
|
26
26
|
'enforce-style-prop': enforceStyleProp,
|