@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.
Files changed (44) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +2 -5
  3. package/dist/cjs/index.codegen.js +45 -10
  4. package/dist/cjs/index.js +22 -1
  5. package/dist/cjs/presets/all-flat.codegen.js +53 -0
  6. package/dist/cjs/presets/all.codegen.js +2 -9
  7. package/dist/cjs/presets/recommended-flat.codegen.js +53 -0
  8. package/dist/cjs/presets/recommended.codegen.js +2 -9
  9. package/dist/cjs/rules/enforce-style-prop/index.js +45 -17
  10. package/dist/cjs/rules/external-rules.js +0 -38
  11. package/dist/cjs/rules/index.codegen.js +4 -3
  12. package/dist/es2019/index.codegen.js +50 -6
  13. package/dist/es2019/index.js +1 -1
  14. package/dist/es2019/presets/all-flat.codegen.js +44 -0
  15. package/dist/es2019/presets/all.codegen.js +2 -9
  16. package/dist/es2019/presets/recommended-flat.codegen.js +44 -0
  17. package/dist/es2019/presets/recommended.codegen.js +2 -9
  18. package/dist/es2019/rules/enforce-style-prop/index.js +45 -17
  19. package/dist/es2019/rules/external-rules.js +0 -38
  20. package/dist/es2019/rules/index.codegen.js +2 -2
  21. package/dist/esm/index.codegen.js +46 -6
  22. package/dist/esm/index.js +1 -1
  23. package/dist/esm/presets/all-flat.codegen.js +44 -0
  24. package/dist/esm/presets/all.codegen.js +2 -9
  25. package/dist/esm/presets/recommended-flat.codegen.js +44 -0
  26. package/dist/esm/presets/recommended.codegen.js +2 -9
  27. package/dist/esm/rules/enforce-style-prop/index.js +45 -17
  28. package/dist/esm/rules/external-rules.js +0 -38
  29. package/dist/esm/rules/index.codegen.js +2 -2
  30. package/dist/types/index.codegen.d.ts +370 -81
  31. package/dist/types/index.d.ts +1 -1
  32. package/dist/types/presets/all-flat.codegen.d.ts +44 -0
  33. package/dist/types/presets/all.codegen.d.ts +33 -40
  34. package/dist/types/presets/recommended-flat.codegen.d.ts +44 -0
  35. package/dist/types/presets/recommended.codegen.d.ts +33 -40
  36. package/dist/types/rules/index.codegen.d.ts +1 -2
  37. package/dist/types-ts4.5/index.codegen.d.ts +550 -81
  38. package/dist/types-ts4.5/index.d.ts +1 -1
  39. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +65 -0
  40. package/dist/types-ts4.5/presets/all.codegen.d.ts +57 -40
  41. package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +65 -0
  42. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +57 -40
  43. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -2
  44. 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 _parent;
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 (((_parent = variable.identifiers[0].parent) === null || _parent === void 0 ? void 0 : _parent.type) === 'RestElement') {
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 _variableDefinition$i, _variableDefinition$i2;
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 (((_variableDefinition$i = variableDefinition.init) === null || _variableDefinition$i === void 0 ? void 0 : _variableDefinition$i.type) === 'CallExpression') {
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 (((_variableDefinition$i2 = variableDefinition.init) === null || _variableDefinition$i2 === void 0 ? void 0 : _variableDefinition$i2.type) === 'MemberExpression') {
47
- return isParameter(context, variableDefinition.init.object);
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, variableDefinition.init);
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
- if (node.expression.type === 'ObjectExpression') {
130
- node.expression.properties.forEach(function (value) {
131
- if (!isPropertyValueAllowed(value, context)) {
132
- context.report({
133
- node: value,
134
- messageId: 'enforce-style-prop'
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::6ad0de2d4bdac726387f27681ad9fcf4>>
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 default {
23
+ export var rules = {
24
24
  'atlaskit-theme': atlaskitTheme,
25
25
  'convert-props-syntax': convertPropsSyntax,
26
26
  'enforce-style-prop': enforceStyleProp,