@atlaskit/eslint-plugin-ui-styling-standard 0.8.2 → 0.8.3

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,11 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 0.8.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#87496](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/87496) [`d5b439e94043`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d5b439e94043) - Improve coverage of `convert-props-syntax` rule. Previously cases such as `css()` and `styled(BaseComponent)()` were not covered by the rule.
8
+
3
9
  ## 0.8.2
4
10
 
5
11
  ### Patch Changes
@@ -9,6 +9,7 @@ var _eslintScope = require("eslint-scope");
9
9
  var _createRule = require("../utils/create-rule");
10
10
  var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
11
11
  var _estraverse = _interopRequireDefault(require("estraverse"));
12
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
12
13
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
13
14
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
14
15
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
@@ -224,7 +225,11 @@ var lintArguments = function lintArguments(context, args) {
224
225
  }
225
226
  allProps.push(propNames);
226
227
  }
227
- }
228
+ },
229
+ /**
230
+ * This is needed to handle unknown node types. Otherwise an error is thrown.
231
+ */
232
+ fallback: 'iteration'
228
233
  });
229
234
  }
230
235
  }
@@ -380,7 +385,16 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
380
385
  },
381
386
  create: function create(context) {
382
387
  return {
383
- 'CallExpression[callee.type="MemberExpression"]': function CallExpressionCalleeTypeMemberExpression(node) {
388
+ CallExpression: function (_CallExpression) {
389
+ function CallExpression(_x) {
390
+ return _CallExpression.apply(this, arguments);
391
+ }
392
+ CallExpression.toString = function () {
393
+ return _CallExpression.toString();
394
+ };
395
+ return CallExpression;
396
+ }(function (node) {
397
+ var _node$parent, _node$parent2;
384
398
  var references = context.getScope().references;
385
399
 
386
400
  // Rule should ignore .attrs() calls
@@ -391,8 +405,21 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
391
405
  if (!(0, _isSupportedImport.isStyledComponents)(callee, references) && !(0, _isSupportedImport.isEmotion)(callee, references)) {
392
406
  return;
393
407
  }
408
+
409
+ /**
410
+ * We only want to lint the second set of arguments in the following cases:
411
+ *
412
+ * 1. styled(BaseComponent)({ ... })
413
+ * 2. styled(BaseComponent)``
414
+ */
415
+ if (
416
+ // Using this type assertion to cast into a more useful type
417
+ // For some reason the estree types are missing useful things like `parent`
418
+ (0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression') && (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) === 'CallExpression' || ((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.type) === 'TaggedTemplateExpression')) {
419
+ return;
420
+ }
394
421
  lintArguments(context, node.arguments);
395
- }
422
+ })
396
423
  };
397
424
  }
398
425
  });
@@ -2,6 +2,7 @@ import { analyze } from 'eslint-scope';
2
2
  import { createLintRule } from '../utils/create-rule';
3
3
  import { isStyledComponents, isEmotion } from '@atlaskit/eslint-utils/is-supported-import';
4
4
  import ESTraverse from 'estraverse';
5
+ import { isNodeOfType } from 'eslint-codemod-utils';
5
6
 
6
7
  /**
7
8
  * Represents some information about single line that contains some props, e.g.
@@ -168,7 +169,11 @@ const lintArguments = (context, args) => {
168
169
  }
169
170
  allProps.push(propNames);
170
171
  }
171
- }
172
+ },
173
+ /**
174
+ * This is needed to handle unknown node types. Otherwise an error is thrown.
175
+ */
176
+ fallback: 'iteration'
172
177
  });
173
178
  }
174
179
  }
@@ -276,7 +281,8 @@ export const rule = createLintRule({
276
281
  },
277
282
  create(context) {
278
283
  return {
279
- 'CallExpression[callee.type="MemberExpression"]': node => {
284
+ CallExpression: node => {
285
+ var _node$parent, _node$parent2;
280
286
  const references = context.getScope().references;
281
287
 
282
288
  // Rule should ignore .attrs() calls
@@ -287,6 +293,19 @@ export const rule = createLintRule({
287
293
  if (!isStyledComponents(callee, references) && !isEmotion(callee, references)) {
288
294
  return;
289
295
  }
296
+
297
+ /**
298
+ * We only want to lint the second set of arguments in the following cases:
299
+ *
300
+ * 1. styled(BaseComponent)({ ... })
301
+ * 2. styled(BaseComponent)``
302
+ */
303
+ if (
304
+ // Using this type assertion to cast into a more useful type
305
+ // For some reason the estree types are missing useful things like `parent`
306
+ isNodeOfType(node, 'CallExpression') && (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) === 'CallExpression' || ((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.type) === 'TaggedTemplateExpression')) {
307
+ return;
308
+ }
290
309
  lintArguments(context, node.arguments);
291
310
  }
292
311
  };
@@ -5,6 +5,7 @@ import { analyze } from 'eslint-scope';
5
5
  import { createLintRule } from '../utils/create-rule';
6
6
  import { isStyledComponents, isEmotion } from '@atlaskit/eslint-utils/is-supported-import';
7
7
  import ESTraverse from 'estraverse';
8
+ import { isNodeOfType } from 'eslint-codemod-utils';
8
9
 
9
10
  /**
10
11
  * Represents some information about single line that contains some props, e.g.
@@ -218,7 +219,11 @@ var lintArguments = function lintArguments(context, args) {
218
219
  }
219
220
  allProps.push(propNames);
220
221
  }
221
- }
222
+ },
223
+ /**
224
+ * This is needed to handle unknown node types. Otherwise an error is thrown.
225
+ */
226
+ fallback: 'iteration'
222
227
  });
223
228
  }
224
229
  }
@@ -374,7 +379,16 @@ export var rule = createLintRule({
374
379
  },
375
380
  create: function create(context) {
376
381
  return {
377
- 'CallExpression[callee.type="MemberExpression"]': function CallExpressionCalleeTypeMemberExpression(node) {
382
+ CallExpression: function (_CallExpression) {
383
+ function CallExpression(_x) {
384
+ return _CallExpression.apply(this, arguments);
385
+ }
386
+ CallExpression.toString = function () {
387
+ return _CallExpression.toString();
388
+ };
389
+ return CallExpression;
390
+ }(function (node) {
391
+ var _node$parent, _node$parent2;
378
392
  var references = context.getScope().references;
379
393
 
380
394
  // Rule should ignore .attrs() calls
@@ -385,8 +399,21 @@ export var rule = createLintRule({
385
399
  if (!isStyledComponents(callee, references) && !isEmotion(callee, references)) {
386
400
  return;
387
401
  }
402
+
403
+ /**
404
+ * We only want to lint the second set of arguments in the following cases:
405
+ *
406
+ * 1. styled(BaseComponent)({ ... })
407
+ * 2. styled(BaseComponent)``
408
+ */
409
+ if (
410
+ // Using this type assertion to cast into a more useful type
411
+ // For some reason the estree types are missing useful things like `parent`
412
+ isNodeOfType(node, 'CallExpression') && (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) === 'CallExpression' || ((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.type) === 'TaggedTemplateExpression')) {
413
+ return;
414
+ }
388
415
  lintArguments(context, node.arguments);
389
- }
416
+ })
390
417
  };
391
418
  }
392
419
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "author": "Atlassian Pty Ltd",
5
5
  "description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
6
6
  "license": "Apache-2.0",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@atlaskit/ds-lib": "^2.2.0",
48
- "@atlaskit/eslint-plugin-design-system": "^9.3.0",
48
+ "@atlaskit/eslint-plugin-design-system": "^9.4.0",
49
49
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
50
50
  "@atlassian/codegen": "*",
51
51
  "@compiled/eslint-plugin": "^0.13.6",
@@ -107,7 +107,7 @@ typescriptEslintTester.run(
107
107
  name: 'ignores styled(...).attrs() call',
108
108
  code: `
109
109
  import { styled } from 'styled-components';
110
-
110
+
111
111
  const StyledMinimized = styled(Minimized).attrs({
112
112
  className: (props) => props.transitionClass,
113
113
  })\`
@@ -119,7 +119,7 @@ typescriptEslintTester.run(
119
119
  name: 'ignores styled.div.attrs<...>() call',
120
120
  code: `
121
121
  import { styled } from '@compiled/react';
122
-
122
+
123
123
  export const ModalAnchorOld = styled.div.attrs<ModalAnchorProps>({
124
124
  style: ({ left, top }: ModalAnchorProps) => ({
125
125
  left,
@@ -155,6 +155,46 @@ typescriptEslintTester.run(
155
155
  \`;
156
156
  `,
157
157
  },
158
+ {
159
+ name: 'ignores options passed to base components',
160
+ code: `
161
+ import styled from '@emotion/styled';
162
+ import { token } from 'some-package';
163
+ import { someFallback } from 'other-package';
164
+
165
+ styled(BaseComponent, {
166
+ // This should not get flagged
167
+ shouldForwardProp: prop => prop !== 'seen'
168
+ })({
169
+ color: token('some-token', someFallback),
170
+ });
171
+ `,
172
+ },
173
+ {
174
+ name: 'ignores options passed to base components when using template string',
175
+ code: `
176
+ import styled from '@emotion/styled';
177
+ import { token } from 'some-package';
178
+ import { someFallback } from 'other-package';
179
+
180
+ styled(Link, {
181
+ // This should not get flagged
182
+ shouldForwardProp: prop => prop !== 'seen',
183
+ })<{ seen?: boolean }>\`
184
+ cursor: pointer;
185
+ \`;
186
+ `,
187
+ },
188
+ {
189
+ name: 'No error on TSAsExpression node type when using ESTraverse',
190
+ code: `
191
+ import styled from '@emotion/styled';
192
+
193
+ const Component = styled.div({
194
+ color: token('color.text') as string,
195
+ });
196
+ `,
197
+ },
158
198
  ],
159
199
  invalid: [
160
200
  {
@@ -499,6 +539,46 @@ typescriptEslintTester.run(
499
539
  `,
500
540
  errors: [{ messageId: 'unsupported-prop-syntax' }],
501
541
  },
542
+ {
543
+ name: 'converts styled-components props argument when extending existing component',
544
+ code: `
545
+ import styled from 'styled-components';
546
+
547
+ styled(BaseComponent)({
548
+ color: (props) => props.color,
549
+ backgroundColor: (props) => props.backgroundColor,
550
+ });
551
+ `,
552
+ output: `
553
+ import styled from 'styled-components';
554
+
555
+ styled(BaseComponent)((props) => ({
556
+ color: props.color,
557
+ backgroundColor: props.backgroundColor,
558
+ }));
559
+ `,
560
+ errors: [{ messageId: 'unsupported-prop-syntax' }],
561
+ },
562
+ {
563
+ name: 'converts styled-components props argument when using css function',
564
+ code: `
565
+ import { css } from 'styled-components';
566
+
567
+ css({
568
+ color: (props) => props.color,
569
+ backgroundColor: (props) => props.backgroundColor,
570
+ });
571
+ `,
572
+ output: `
573
+ import { css } from 'styled-components';
574
+
575
+ css((props) => ({
576
+ color: props.color,
577
+ backgroundColor: props.backgroundColor,
578
+ }));
579
+ `,
580
+ errors: [{ messageId: 'unsupported-prop-syntax' }],
581
+ },
502
582
  ],
503
583
  },
504
584
  );
@@ -14,6 +14,7 @@ import {
14
14
  } from '@atlaskit/eslint-utils/is-supported-import';
15
15
  import type { Rule, Scope, SourceCode } from 'eslint';
16
16
  import ESTraverse from 'estraverse';
17
+ import { isNodeOfType } from 'eslint-codemod-utils';
17
18
 
18
19
  type PropInfo = {
19
20
  /**
@@ -227,6 +228,10 @@ const lintArguments = (
227
228
  allProps.push(propNames);
228
229
  }
229
230
  },
231
+ /**
232
+ * This is needed to handle unknown node types. Otherwise an error is thrown.
233
+ */
234
+ fallback: 'iteration',
230
235
  });
231
236
  }
232
237
  }
@@ -390,9 +395,7 @@ export const rule = createLintRule({
390
395
  },
391
396
  create(context) {
392
397
  return {
393
- 'CallExpression[callee.type="MemberExpression"]': (
394
- node: CallExpression,
395
- ) => {
398
+ CallExpression: (node: CallExpression) => {
396
399
  const references = context.getScope().references;
397
400
 
398
401
  // Rule should ignore .attrs() calls
@@ -416,6 +419,22 @@ export const rule = createLintRule({
416
419
  return;
417
420
  }
418
421
 
422
+ /**
423
+ * We only want to lint the second set of arguments in the following cases:
424
+ *
425
+ * 1. styled(BaseComponent)({ ... })
426
+ * 2. styled(BaseComponent)``
427
+ */
428
+ if (
429
+ // Using this type assertion to cast into a more useful type
430
+ // For some reason the estree types are missing useful things like `parent`
431
+ isNodeOfType(node, 'CallExpression') &&
432
+ (node.parent?.type === 'CallExpression' ||
433
+ node.parent?.type === 'TaggedTemplateExpression')
434
+ ) {
435
+ return;
436
+ }
437
+
419
438
  lintArguments(context, node.arguments);
420
439
  },
421
440
  };