@atlaskit/eslint-plugin-design-system 10.7.0 → 10.7.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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 10.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#111413](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/111413)
8
+ [`492737dbcfc65`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/492737dbcfc65) -
9
+ Fixes `consistent-css-prop-usage` to prevent unsafe auto-fixes. Previously style declarations
10
+ could be hoisted out of components even if they referenced variables only defined in the
11
+ component's scope.
12
+
3
13
  ## 10.7.0
4
14
 
5
15
  ### Minor Changes
@@ -12,6 +12,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
12
12
  var _eslintCodemodUtils = require("eslint-codemod-utils");
13
13
  var _estraverse = _interopRequireDefault(require("estraverse"));
14
14
  var _assign = _interopRequireDefault(require("lodash/assign"));
15
+ var _findVariable = require("@atlaskit/eslint-utils/find-variable");
15
16
  var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
16
17
  var _astNodes = require("../../ast-nodes");
17
18
  var _createRule = require("../utils/create-rule");
@@ -250,11 +251,40 @@ var JSXExpressionLinter = /*#__PURE__*/function () {
250
251
  key: "potentiallyHasLocalVariable",
251
252
  value: function potentiallyHasLocalVariable(node) {
252
253
  var _this2 = this;
254
+ /**
255
+ * If we've passed an `Identifier` then it is an identifier that's been
256
+ * passed to the `css` prop.
257
+ *
258
+ * We need to check its initializer to see if it is safe to auto-fix.
259
+ */
260
+ if (node.type === 'Identifier') {
261
+ var variable = (0, _findVariable.findVariable)({
262
+ identifier: node,
263
+ sourceCode: this.context.getSourceCode()
264
+ });
265
+ if (!variable) {
266
+ // If we cannot resolve the variable then we cannot check it, so assume worst-case.
267
+ return true;
268
+ }
269
+ return variable.defs.some(function (def) {
270
+ // If the binding isn't from a variable declaration we assume worst-case.
271
+ if (def.type !== 'Variable') {
272
+ return true;
273
+ }
274
+ var init = def.node.init;
275
+ if (!init) {
276
+ // If there is no initializer something weird is happening so assume worst-case.
277
+ return true;
278
+ }
279
+ return _this2.potentiallyHasLocalVariable(init);
280
+ });
281
+ }
253
282
  var hasPotentiallyLocalVariable = false;
254
283
  var isImportedVariable = function isImportedVariable(identifier) {
255
284
  return !!(0, _getImportNodeBySource.getModuleOfIdentifier)(_this2.context.getSourceCode(), identifier);
256
285
  };
257
286
  _estraverse.default.traverse(node, {
287
+ fallback: 'iteration',
258
288
  enter: function enter(node, _parent) {
259
289
  if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'SpreadElement') ||
260
290
  // @ts-expect-error remove once we can be sure that no parser interprets
@@ -342,15 +372,15 @@ var JSXExpressionLinter = /*#__PURE__*/function () {
342
372
  }
343
373
  var moduleString;
344
374
  var fixes = [];
375
+ if (this.potentiallyHasLocalVariable(node)) {
376
+ return [];
377
+ }
345
378
  if (node.type === 'Identifier') {
346
379
  var identifier = node;
347
380
  var declarator = identifier.parent.parent;
348
381
  moduleString = sourceCode.getText(declarator);
349
382
  fixes.push(fixer.remove(declarator));
350
383
  } else {
351
- if (this.potentiallyHasLocalVariable(node)) {
352
- return [];
353
- }
354
384
  var _declarator = this.getDeclaratorString();
355
385
  var text = sourceCode.getText(node);
356
386
 
@@ -3,6 +3,7 @@
3
3
  import { getIdentifierInParentScope, insertAtStartOfFile, insertImportDeclaration, isNodeOfType } from 'eslint-codemod-utils';
4
4
  import estraverse from 'estraverse';
5
5
  import assign from 'lodash/assign';
6
+ import { findVariable } from '@atlaskit/eslint-utils/find-variable';
6
7
  import { CSS_IN_JS_IMPORTS } from '@atlaskit/eslint-utils/is-supported-import';
7
8
  import { Import } from '../../ast-nodes';
8
9
  import { createLintRule } from '../utils/create-rule';
@@ -217,9 +218,40 @@ class JSXExpressionLinter {
217
218
  * @returns Whether the node potentially has a local variable (and thus is not safe to hoist).
218
219
  */
219
220
  potentiallyHasLocalVariable(node) {
221
+ /**
222
+ * If we've passed an `Identifier` then it is an identifier that's been
223
+ * passed to the `css` prop.
224
+ *
225
+ * We need to check its initializer to see if it is safe to auto-fix.
226
+ */
227
+ if (node.type === 'Identifier') {
228
+ const variable = findVariable({
229
+ identifier: node,
230
+ sourceCode: this.context.getSourceCode()
231
+ });
232
+ if (!variable) {
233
+ // If we cannot resolve the variable then we cannot check it, so assume worst-case.
234
+ return true;
235
+ }
236
+ return variable.defs.some(def => {
237
+ // If the binding isn't from a variable declaration we assume worst-case.
238
+ if (def.type !== 'Variable') {
239
+ return true;
240
+ }
241
+ const {
242
+ init
243
+ } = def.node;
244
+ if (!init) {
245
+ // If there is no initializer something weird is happening so assume worst-case.
246
+ return true;
247
+ }
248
+ return this.potentiallyHasLocalVariable(init);
249
+ });
250
+ }
220
251
  let hasPotentiallyLocalVariable = false;
221
252
  const isImportedVariable = identifier => !!getModuleOfIdentifier(this.context.getSourceCode(), identifier);
222
253
  estraverse.traverse(node, {
254
+ fallback: 'iteration',
223
255
  enter: function (node, _parent) {
224
256
  if (isNodeOfType(node, 'SpreadElement') ||
225
257
  // @ts-expect-error remove once we can be sure that no parser interprets
@@ -303,15 +335,15 @@ class JSXExpressionLinter {
303
335
  }
304
336
  let moduleString;
305
337
  let fixes = [];
338
+ if (this.potentiallyHasLocalVariable(node)) {
339
+ return [];
340
+ }
306
341
  if (node.type === 'Identifier') {
307
342
  const identifier = node;
308
343
  const declarator = identifier.parent.parent;
309
344
  moduleString = sourceCode.getText(declarator);
310
345
  fixes.push(fixer.remove(declarator));
311
346
  } else {
312
- if (this.potentiallyHasLocalVariable(node)) {
313
- return [];
314
- }
315
347
  const declarator = this.getDeclaratorString();
316
348
  const text = sourceCode.getText(node);
317
349
 
@@ -7,6 +7,7 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
7
7
  import { getIdentifierInParentScope, insertAtStartOfFile, insertImportDeclaration, isNodeOfType } from 'eslint-codemod-utils';
8
8
  import estraverse from 'estraverse';
9
9
  import assign from 'lodash/assign';
10
+ import { findVariable } from '@atlaskit/eslint-utils/find-variable';
10
11
  import { CSS_IN_JS_IMPORTS } from '@atlaskit/eslint-utils/is-supported-import';
11
12
  import { Import } from '../../ast-nodes';
12
13
  import { createLintRule } from '../utils/create-rule';
@@ -243,11 +244,40 @@ var JSXExpressionLinter = /*#__PURE__*/function () {
243
244
  key: "potentiallyHasLocalVariable",
244
245
  value: function potentiallyHasLocalVariable(node) {
245
246
  var _this2 = this;
247
+ /**
248
+ * If we've passed an `Identifier` then it is an identifier that's been
249
+ * passed to the `css` prop.
250
+ *
251
+ * We need to check its initializer to see if it is safe to auto-fix.
252
+ */
253
+ if (node.type === 'Identifier') {
254
+ var variable = findVariable({
255
+ identifier: node,
256
+ sourceCode: this.context.getSourceCode()
257
+ });
258
+ if (!variable) {
259
+ // If we cannot resolve the variable then we cannot check it, so assume worst-case.
260
+ return true;
261
+ }
262
+ return variable.defs.some(function (def) {
263
+ // If the binding isn't from a variable declaration we assume worst-case.
264
+ if (def.type !== 'Variable') {
265
+ return true;
266
+ }
267
+ var init = def.node.init;
268
+ if (!init) {
269
+ // If there is no initializer something weird is happening so assume worst-case.
270
+ return true;
271
+ }
272
+ return _this2.potentiallyHasLocalVariable(init);
273
+ });
274
+ }
246
275
  var hasPotentiallyLocalVariable = false;
247
276
  var isImportedVariable = function isImportedVariable(identifier) {
248
277
  return !!getModuleOfIdentifier(_this2.context.getSourceCode(), identifier);
249
278
  };
250
279
  estraverse.traverse(node, {
280
+ fallback: 'iteration',
251
281
  enter: function enter(node, _parent) {
252
282
  if (isNodeOfType(node, 'SpreadElement') ||
253
283
  // @ts-expect-error remove once we can be sure that no parser interprets
@@ -335,15 +365,15 @@ var JSXExpressionLinter = /*#__PURE__*/function () {
335
365
  }
336
366
  var moduleString;
337
367
  var fixes = [];
368
+ if (this.potentiallyHasLocalVariable(node)) {
369
+ return [];
370
+ }
338
371
  if (node.type === 'Identifier') {
339
372
  var identifier = node;
340
373
  var declarator = identifier.parent.parent;
341
374
  moduleString = sourceCode.getText(declarator);
342
375
  fixes.push(fixer.remove(declarator));
343
376
  } else {
344
- if (this.potentiallyHasLocalVariable(node)) {
345
- return [];
346
- }
347
377
  var _declarator = this.getDeclaratorString();
348
378
  var text = sourceCode.getText(node);
349
379
 
package/package.json CHANGED
@@ -1,96 +1,88 @@
1
1
  {
2
- "name": "@atlaskit/eslint-plugin-design-system",
3
- "description": "The essential plugin for use with the Atlassian Design System.",
4
- "version": "10.7.0",
5
- "author": "Atlassian Pty Ltd",
6
- "license": "Apache-2.0",
7
- "publishConfig": {
8
- "registry": "https://registry.npmjs.org/"
9
- },
10
- "atlassian": {
11
- "team": "Design System Team",
12
- "releaseModel": "continuous",
13
- "productPushConsumption": [
14
- "jira"
15
- ],
16
- "website": {
17
- "name": "ESLint plugin",
18
- "category": "Tooling"
19
- },
20
- "runReact18": true
21
- },
22
- "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
23
- "main": "dist/cjs/index.js",
24
- "module": "dist/esm/index.js",
25
- "module:es2019": "dist/es2019/index.js",
26
- "types": "dist/types/index.d.ts",
27
- "typesVersions": {
28
- ">=4.5 <4.9": {
29
- "*": [
30
- "dist/types-ts4.5/*",
31
- "dist/types-ts4.5/index.d.ts"
32
- ]
33
- }
34
- },
35
- "sideEffects": false,
36
- "atlaskit:src": "src/index.tsx",
37
- "af:exports": {
38
- ".": "./src/index.tsx"
39
- },
40
- "peerDependencies": {
41
- "react": "^16.8.0 || ^17.0.0 || ~18.2.0"
42
- },
43
- "dependencies": {
44
- "@atlaskit/eslint-utils": "^1.6.0",
45
- "@atlaskit/tokens": "*",
46
- "@babel/runtime": "^7.0.0",
47
- "@typescript-eslint/utils": "^5.48.1",
48
- "ajv": "^6.12.6",
49
- "eslint-codemod-utils": "^1.8.6",
50
- "esquery": "^1.5.0",
51
- "estraverse": "^5.3.0",
52
- "lodash": "^4.17.21",
53
- "semver": "^7.5.2"
54
- },
55
- "devDependencies": {
56
- "@af/formatting": "*",
57
- "@atlaskit/ds-lib": "^2.3.0",
58
- "@atlaskit/theme": "^12.9.0",
59
- "@atlassian/codegen": "*",
60
- "@atlassian/eslint-utils": "^0.5.0",
61
- "@emotion/react": "^11.7.1",
62
- "@emotion/styled": "^11.0.0",
63
- "@types/eslint": "^8.56.6",
64
- "@types/esquery": "^1.5.3",
65
- "@types/estraverse": "^5.1.7",
66
- "eslint": "^8.49.0",
67
- "jscodeshift": "^0.13.0",
68
- "outdent": "^0.5.0",
69
- "react": "^16.8.0",
70
- "ts-jest": "26.5.6",
71
- "ts-node": "^10.9.1",
72
- "tsconfig-paths": "^4.2.0",
73
- "typescript": "~5.4.2"
74
- },
75
- "scripts": {
76
- "ak-postbuild": "cp -r configs dist",
77
- "codegen": "ts-node -r tsconfig-paths/register ./scripts/codegen.tsx",
78
- "codegen-token-maps": "ts-node -r tsconfig-paths/register ./scripts/token-maps/codegen-token-maps.tsx"
79
- },
80
- "techstack": {
81
- "@atlassian/frontend": {
82
- "import-structure": "atlassian-conventions",
83
- "circular-dependencies": "file-and-folder-level"
84
- },
85
- "@repo/internal": {
86
- "dom-events": "use-bind-event-listener",
87
- "design-system": "v1",
88
- "deprecation": "no-deprecated-imports",
89
- "styling": [
90
- "static",
91
- "emotion"
92
- ]
93
- }
94
- },
95
- "homepage": "https://atlassian.design/components/eslint-plugin-design-system"
96
- }
2
+ "name": "@atlaskit/eslint-plugin-design-system",
3
+ "description": "The essential plugin for use with the Atlassian Design System.",
4
+ "version": "10.7.1",
5
+ "author": "Atlassian Pty Ltd",
6
+ "license": "Apache-2.0",
7
+ "publishConfig": {
8
+ "registry": "https://registry.npmjs.org/"
9
+ },
10
+ "atlassian": {
11
+ "team": "Design System Team",
12
+ "releaseModel": "continuous",
13
+ "productPushConsumption": ["jira"],
14
+ "website": {
15
+ "name": "ESLint plugin",
16
+ "category": "Tooling"
17
+ },
18
+ "runReact18": true
19
+ },
20
+ "repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
21
+ "main": "dist/cjs/index.js",
22
+ "module": "dist/esm/index.js",
23
+ "module:es2019": "dist/es2019/index.js",
24
+ "types": "dist/types/index.d.ts",
25
+ "typesVersions": {
26
+ ">=4.5 <4.9": {
27
+ "*": ["dist/types-ts4.5/*", "dist/types-ts4.5/index.d.ts"]
28
+ }
29
+ },
30
+ "sideEffects": false,
31
+ "atlaskit:src": "src/index.tsx",
32
+ "af:exports": {
33
+ ".": "./src/index.tsx"
34
+ },
35
+ "peerDependencies": {
36
+ "react": "^16.8.0 || ^17.0.0 || ~18.2.0"
37
+ },
38
+ "dependencies": {
39
+ "@atlaskit/eslint-utils": "^1.6.0",
40
+ "@atlaskit/tokens": "*",
41
+ "@babel/runtime": "^7.0.0",
42
+ "@typescript-eslint/utils": "^5.48.1",
43
+ "ajv": "^6.12.6",
44
+ "eslint-codemod-utils": "^1.8.6",
45
+ "esquery": "^1.5.0",
46
+ "estraverse": "^5.3.0",
47
+ "lodash": "^4.17.21",
48
+ "semver": "^7.5.2"
49
+ },
50
+ "devDependencies": {
51
+ "@af/formatting": "*",
52
+ "@atlaskit/ds-lib": "^2.3.0",
53
+ "@atlaskit/theme": "^12.9.0",
54
+ "@atlassian/codegen": "*",
55
+ "@atlassian/eslint-utils": "^0.5.0",
56
+ "@emotion/react": "^11.7.1",
57
+ "@emotion/styled": "^11.0.0",
58
+ "@types/eslint": "^8.56.6",
59
+ "@types/esquery": "^1.5.3",
60
+ "@types/estraverse": "^5.1.7",
61
+ "eslint": "^8.49.0",
62
+ "jscodeshift": "^0.13.0",
63
+ "outdent": "^0.5.0",
64
+ "react": "^16.8.0",
65
+ "ts-jest": "26.5.6",
66
+ "ts-node": "^10.9.1",
67
+ "tsconfig-paths": "^4.2.0",
68
+ "typescript": "~5.4.2"
69
+ },
70
+ "scripts": {
71
+ "ak-postbuild": "cp -r configs dist",
72
+ "codegen": "ts-node -r tsconfig-paths/register ./scripts/codegen.tsx",
73
+ "codegen-token-maps": "ts-node -r tsconfig-paths/register ./scripts/token-maps/codegen-token-maps.tsx"
74
+ },
75
+ "techstack": {
76
+ "@atlassian/frontend": {
77
+ "import-structure": "atlassian-conventions",
78
+ "circular-dependencies": "file-and-folder-level"
79
+ },
80
+ "@repo/internal": {
81
+ "dom-events": "use-bind-event-listener",
82
+ "design-system": "v1",
83
+ "deprecation": "no-deprecated-imports",
84
+ "styling": ["static", "emotion"]
85
+ }
86
+ },
87
+ "homepage": "https://atlassian.design/components/eslint-plugin-design-system"
88
+ }