@atlaskit/eslint-plugin-design-system 13.6.0 → 13.7.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 (84) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/presets/all-flat.codegen.js +2 -1
  4. package/dist/cjs/presets/all.codegen.js +2 -1
  5. package/dist/cjs/presets/recommended-flat.codegen.js +2 -1
  6. package/dist/cjs/presets/recommended.codegen.js +2 -1
  7. package/dist/cjs/rules/index.codegen.js +3 -1
  8. package/dist/cjs/rules/no-html-anchor/node-types/styled-component/index.js +2 -2
  9. package/dist/cjs/rules/no-html-button/node-types/styled-component/index.js +2 -2
  10. package/dist/cjs/rules/no-html-image/index.js +40 -0
  11. package/dist/cjs/rules/no-html-image/node-types/index.js +19 -0
  12. package/dist/cjs/rules/no-html-image/node-types/jsx-element/index.js +115 -0
  13. package/dist/cjs/rules/no-html-image/node-types/styled-component/index.js +42 -0
  14. package/dist/cjs/rules/no-html-image/node-types/supported.js +72 -0
  15. package/dist/cjs/rules/utils/get-styled-component-call.js +1 -1
  16. package/dist/es2019/presets/all-flat.codegen.js +2 -1
  17. package/dist/es2019/presets/all.codegen.js +2 -1
  18. package/dist/es2019/presets/recommended-flat.codegen.js +2 -1
  19. package/dist/es2019/presets/recommended.codegen.js +2 -1
  20. package/dist/es2019/rules/index.codegen.js +3 -1
  21. package/dist/es2019/rules/no-html-anchor/node-types/styled-component/index.js +2 -2
  22. package/dist/es2019/rules/no-html-button/node-types/styled-component/index.js +2 -2
  23. package/dist/es2019/rules/no-html-image/index.js +34 -0
  24. package/dist/es2019/rules/no-html-image/node-types/index.js +2 -0
  25. package/dist/es2019/rules/no-html-image/node-types/jsx-element/index.js +80 -0
  26. package/dist/es2019/rules/no-html-image/node-types/styled-component/index.js +37 -0
  27. package/dist/es2019/rules/no-html-image/node-types/supported.js +62 -0
  28. package/dist/es2019/rules/utils/get-styled-component-call.js +1 -1
  29. package/dist/esm/presets/all-flat.codegen.js +2 -1
  30. package/dist/esm/presets/all.codegen.js +2 -1
  31. package/dist/esm/presets/recommended-flat.codegen.js +2 -1
  32. package/dist/esm/presets/recommended.codegen.js +2 -1
  33. package/dist/esm/rules/index.codegen.js +3 -1
  34. package/dist/esm/rules/no-html-anchor/node-types/styled-component/index.js +2 -2
  35. package/dist/esm/rules/no-html-button/node-types/styled-component/index.js +2 -2
  36. package/dist/esm/rules/no-html-image/index.js +34 -0
  37. package/dist/esm/rules/no-html-image/node-types/index.js +2 -0
  38. package/dist/esm/rules/no-html-image/node-types/jsx-element/index.js +106 -0
  39. package/dist/esm/rules/no-html-image/node-types/styled-component/index.js +36 -0
  40. package/dist/esm/rules/no-html-image/node-types/supported.js +63 -0
  41. package/dist/esm/rules/utils/get-styled-component-call.js +1 -1
  42. package/dist/types/index.codegen.d.ts +9 -0
  43. package/dist/types/presets/all-flat.codegen.d.ts +1 -0
  44. package/dist/types/presets/all.codegen.d.ts +1 -0
  45. package/dist/types/presets/recommended-flat.codegen.d.ts +1 -0
  46. package/dist/types/presets/recommended.codegen.d.ts +1 -0
  47. package/dist/types/rules/index.codegen.d.ts +1 -0
  48. package/dist/types/rules/no-html-image/index.d.ts +3 -0
  49. package/dist/types/rules/no-html-image/node-types/index.d.ts +2 -0
  50. package/dist/types/rules/no-html-image/node-types/jsx-element/index.d.ts +8 -0
  51. package/dist/types/rules/no-html-image/node-types/styled-component/index.d.ts +8 -0
  52. package/dist/types/rules/no-html-image/node-types/supported.d.ts +7 -0
  53. package/dist/types-ts4.5/index.codegen.d.ts +9 -0
  54. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -0
  55. package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -0
  56. package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +1 -0
  57. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -0
  58. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  59. package/dist/types-ts4.5/rules/no-html-image/index.d.ts +3 -0
  60. package/dist/types-ts4.5/rules/no-html-image/node-types/index.d.ts +2 -0
  61. package/dist/types-ts4.5/rules/no-html-image/node-types/jsx-element/index.d.ts +8 -0
  62. package/dist/types-ts4.5/rules/no-html-image/node-types/styled-component/index.d.ts +8 -0
  63. package/dist/types-ts4.5/rules/no-html-image/node-types/supported.d.ts +7 -0
  64. package/package.json +1 -1
  65. package/dist/cjs/rules/no-html-anchor/node-types/styled-component/get-styled-component-call.js +0 -47
  66. package/dist/cjs/rules/no-html-button/node-types/styled-component/get-styled-component-call.js +0 -47
  67. package/dist/cjs/rules/no-html-button/utils/get-jsx-element-by-name.js +0 -53
  68. package/dist/es2019/rules/no-html-anchor/node-types/styled-component/get-styled-component-call.js +0 -42
  69. package/dist/es2019/rules/no-html-button/node-types/styled-component/get-styled-component-call.js +0 -42
  70. package/dist/es2019/rules/no-html-button/utils/get-jsx-element-by-name.js +0 -39
  71. package/dist/esm/rules/no-html-anchor/node-types/styled-component/get-styled-component-call.js +0 -42
  72. package/dist/esm/rules/no-html-button/node-types/styled-component/get-styled-component-call.js +0 -42
  73. package/dist/esm/rules/no-html-button/utils/get-jsx-element-by-name.js +0 -47
  74. package/dist/types/rules/no-html-anchor/node-types/styled-component/get-styled-component-call.d.ts +0 -6
  75. package/dist/types/rules/no-html-anchor/utils/get-jsx-element-by-name.d.ts +0 -6
  76. package/dist/types/rules/no-html-button/node-types/styled-component/get-styled-component-call.d.ts +0 -6
  77. package/dist/types/rules/no-html-button/utils/get-jsx-element-by-name.d.ts +0 -6
  78. package/dist/types-ts4.5/rules/no-html-anchor/node-types/styled-component/get-styled-component-call.d.ts +0 -6
  79. package/dist/types-ts4.5/rules/no-html-button/node-types/styled-component/get-styled-component-call.d.ts +0 -6
  80. /package/dist/cjs/rules/{no-html-anchor → no-html-image}/utils/get-jsx-element-by-name.js +0 -0
  81. /package/dist/es2019/rules/{no-html-anchor → no-html-image}/utils/get-jsx-element-by-name.js +0 -0
  82. /package/dist/esm/rules/{no-html-anchor → no-html-image}/utils/get-jsx-element-by-name.js +0 -0
  83. /package/dist/{types-ts4.5/rules/no-html-button → types/rules/no-html-image}/utils/get-jsx-element-by-name.d.ts +0 -0
  84. /package/dist/types-ts4.5/rules/{no-html-anchor → no-html-image}/utils/get-jsx-element-by-name.d.ts +0 -0
@@ -13,6 +13,7 @@ declare const _default: {
13
13
  '@atlaskit/design-system/no-html-anchor': "warn";
14
14
  '@atlaskit/design-system/no-html-button': "warn";
15
15
  '@atlaskit/design-system/no-html-checkbox': "warn";
16
+ '@atlaskit/design-system/no-html-image': "warn";
16
17
  '@atlaskit/design-system/no-invalid-css-map': ["error", {
17
18
  allowedFunctionCalls: string[][];
18
19
  }];
@@ -13,6 +13,7 @@ declare const _default: {
13
13
  '@atlaskit/design-system/no-html-anchor': "warn";
14
14
  '@atlaskit/design-system/no-html-button': "warn";
15
15
  '@atlaskit/design-system/no-html-checkbox': "warn";
16
+ '@atlaskit/design-system/no-html-image': "warn";
16
17
  '@atlaskit/design-system/no-invalid-css-map': ["error", {
17
18
  allowedFunctionCalls: string[][];
18
19
  }];
@@ -19,6 +19,7 @@ export declare const rules: {
19
19
  'no-html-anchor': import("eslint").Rule.RuleModule;
20
20
  'no-html-button': import("eslint").Rule.RuleModule;
21
21
  'no-html-checkbox': import("eslint").Rule.RuleModule;
22
+ 'no-html-image': import("eslint").Rule.RuleModule;
22
23
  'no-invalid-css-map': import("eslint").Rule.RuleModule;
23
24
  'no-keyframes-tagged-template-expression': import("eslint").Rule.RuleModule;
24
25
  'no-legacy-icons': import("eslint").Rule.RuleModule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,2 @@
1
+ export { StyledComponent } from './styled-component';
2
+ export { JSXElement } from './jsx-element';
@@ -0,0 +1,8 @@
1
+ import type { Rule } from 'eslint';
2
+ interface MetaData {
3
+ context: Rule.RuleContext;
4
+ }
5
+ export declare const JSXElement: {
6
+ lint(node: Rule.Node, { context }: MetaData): void;
7
+ };
8
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { Rule } from 'eslint';
2
+ interface MetaData {
3
+ context: Rule.RuleContext;
4
+ }
5
+ export declare const StyledComponent: {
6
+ lint(node: Rule.Node, { context }: MetaData): void;
7
+ };
8
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type EslintNode } from 'eslint-codemod-utils';
2
+ /**
3
+ * Determines if the given JSX element is a supported element to lint with this rule.
4
+ */
5
+ export declare function isSupportedForLint(jsxNode: EslintNode, elementName?: string): jsxNode is Extract<EslintNode, {
6
+ type: 'JSXElement';
7
+ }>;
@@ -35,6 +35,7 @@ export declare const plugin: {
35
35
  'no-html-anchor': import("eslint").Rule.RuleModule;
36
36
  'no-html-button': import("eslint").Rule.RuleModule;
37
37
  'no-html-checkbox': import("eslint").Rule.RuleModule;
38
+ 'no-html-image': import("eslint").Rule.RuleModule;
38
39
  'no-invalid-css-map': import("eslint").Rule.RuleModule;
39
40
  'no-keyframes-tagged-template-expression': import("eslint").Rule.RuleModule;
40
41
  'no-legacy-icons': import("eslint").Rule.RuleModule;
@@ -89,6 +90,7 @@ export declare const plugin: {
89
90
  '@atlaskit/design-system/no-html-anchor': "warn";
90
91
  '@atlaskit/design-system/no-html-button': "warn";
91
92
  '@atlaskit/design-system/no-html-checkbox': "warn";
93
+ '@atlaskit/design-system/no-html-image': "warn";
92
94
  '@atlaskit/design-system/no-invalid-css-map': [
93
95
  "error",
94
96
  {
@@ -150,6 +152,7 @@ export declare const plugin: {
150
152
  '@atlaskit/design-system/no-html-anchor': "warn";
151
153
  '@atlaskit/design-system/no-html-button': "warn";
152
154
  '@atlaskit/design-system/no-html-checkbox': "warn";
155
+ '@atlaskit/design-system/no-html-image': "warn";
153
156
  '@atlaskit/design-system/no-invalid-css-map': [
154
157
  "error",
155
158
  {
@@ -204,6 +207,7 @@ export declare const plugin: {
204
207
  '@atlaskit/design-system/no-html-anchor': "warn";
205
208
  '@atlaskit/design-system/no-html-button': "warn";
206
209
  '@atlaskit/design-system/no-html-checkbox': "warn";
210
+ '@atlaskit/design-system/no-html-image': "warn";
207
211
  '@atlaskit/design-system/no-invalid-css-map': [
208
212
  "error",
209
213
  {
@@ -249,6 +253,7 @@ export declare const plugin: {
249
253
  '@atlaskit/design-system/no-html-anchor': "warn";
250
254
  '@atlaskit/design-system/no-html-button': "warn";
251
255
  '@atlaskit/design-system/no-html-checkbox': "warn";
256
+ '@atlaskit/design-system/no-html-image': "warn";
252
257
  '@atlaskit/design-system/no-invalid-css-map': [
253
258
  "error",
254
259
  {
@@ -300,6 +305,7 @@ declare const configs: {
300
305
  '@atlaskit/design-system/no-html-anchor': "warn";
301
306
  '@atlaskit/design-system/no-html-button': "warn";
302
307
  '@atlaskit/design-system/no-html-checkbox': "warn";
308
+ '@atlaskit/design-system/no-html-image': "warn";
303
309
  '@atlaskit/design-system/no-invalid-css-map': [
304
310
  "error",
305
311
  {
@@ -361,6 +367,7 @@ declare const configs: {
361
367
  '@atlaskit/design-system/no-html-anchor': "warn";
362
368
  '@atlaskit/design-system/no-html-button': "warn";
363
369
  '@atlaskit/design-system/no-html-checkbox': "warn";
370
+ '@atlaskit/design-system/no-html-image': "warn";
364
371
  '@atlaskit/design-system/no-invalid-css-map': [
365
372
  "error",
366
373
  {
@@ -415,6 +422,7 @@ declare const configs: {
415
422
  '@atlaskit/design-system/no-html-anchor': "warn";
416
423
  '@atlaskit/design-system/no-html-button': "warn";
417
424
  '@atlaskit/design-system/no-html-checkbox': "warn";
425
+ '@atlaskit/design-system/no-html-image': "warn";
418
426
  '@atlaskit/design-system/no-invalid-css-map': [
419
427
  "error",
420
428
  {
@@ -460,6 +468,7 @@ declare const configs: {
460
468
  '@atlaskit/design-system/no-html-anchor': "warn";
461
469
  '@atlaskit/design-system/no-html-button': "warn";
462
470
  '@atlaskit/design-system/no-html-checkbox': "warn";
471
+ '@atlaskit/design-system/no-html-image': "warn";
463
472
  '@atlaskit/design-system/no-invalid-css-map': [
464
473
  "error",
465
474
  {
@@ -18,6 +18,7 @@ declare const _default: {
18
18
  '@atlaskit/design-system/no-html-anchor': "warn";
19
19
  '@atlaskit/design-system/no-html-button': "warn";
20
20
  '@atlaskit/design-system/no-html-checkbox': "warn";
21
+ '@atlaskit/design-system/no-html-image': "warn";
21
22
  '@atlaskit/design-system/no-invalid-css-map': [
22
23
  "error",
23
24
  {
@@ -18,6 +18,7 @@ declare const _default: {
18
18
  '@atlaskit/design-system/no-html-anchor': "warn";
19
19
  '@atlaskit/design-system/no-html-button': "warn";
20
20
  '@atlaskit/design-system/no-html-checkbox': "warn";
21
+ '@atlaskit/design-system/no-html-image': "warn";
21
22
  '@atlaskit/design-system/no-invalid-css-map': [
22
23
  "error",
23
24
  {
@@ -13,6 +13,7 @@ declare const _default: {
13
13
  '@atlaskit/design-system/no-html-anchor': "warn";
14
14
  '@atlaskit/design-system/no-html-button': "warn";
15
15
  '@atlaskit/design-system/no-html-checkbox': "warn";
16
+ '@atlaskit/design-system/no-html-image': "warn";
16
17
  '@atlaskit/design-system/no-invalid-css-map': [
17
18
  "error",
18
19
  {
@@ -13,6 +13,7 @@ declare const _default: {
13
13
  '@atlaskit/design-system/no-html-anchor': "warn";
14
14
  '@atlaskit/design-system/no-html-button': "warn";
15
15
  '@atlaskit/design-system/no-html-checkbox': "warn";
16
+ '@atlaskit/design-system/no-html-image': "warn";
16
17
  '@atlaskit/design-system/no-invalid-css-map': [
17
18
  "error",
18
19
  {
@@ -19,6 +19,7 @@ export declare const rules: {
19
19
  'no-html-anchor': import("eslint").Rule.RuleModule;
20
20
  'no-html-button': import("eslint").Rule.RuleModule;
21
21
  'no-html-checkbox': import("eslint").Rule.RuleModule;
22
+ 'no-html-image': import("eslint").Rule.RuleModule;
22
23
  'no-invalid-css-map': import("eslint").Rule.RuleModule;
23
24
  'no-keyframes-tagged-template-expression': import("eslint").Rule.RuleModule;
24
25
  'no-legacy-icons': import("eslint").Rule.RuleModule;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -0,0 +1,2 @@
1
+ export { StyledComponent } from './styled-component';
2
+ export { JSXElement } from './jsx-element';
@@ -0,0 +1,8 @@
1
+ import type { Rule } from 'eslint';
2
+ interface MetaData {
3
+ context: Rule.RuleContext;
4
+ }
5
+ export declare const JSXElement: {
6
+ lint(node: Rule.Node, { context }: MetaData): void;
7
+ };
8
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { Rule } from 'eslint';
2
+ interface MetaData {
3
+ context: Rule.RuleContext;
4
+ }
5
+ export declare const StyledComponent: {
6
+ lint(node: Rule.Node, { context }: MetaData): void;
7
+ };
8
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type EslintNode } from 'eslint-codemod-utils';
2
+ /**
3
+ * Determines if the given JSX element is a supported element to lint with this rule.
4
+ */
5
+ export declare function isSupportedForLint(jsxNode: EslintNode, elementName?: string): jsxNode is Extract<EslintNode, {
6
+ type: 'JSXElement';
7
+ }>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
3
  "description": "The essential plugin for use with the Atlassian Design System.",
4
- "version": "13.6.0",
4
+ "version": "13.7.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
7
7
  "publishConfig": {
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getStyledComponentCall = void 0;
7
- var _eslintCodemodUtils = require("eslint-codemod-utils");
8
- /**
9
- * Returns a styled component
10
- */
11
-
12
- var getStyledComponentCall = exports.getStyledComponentCall = function getStyledComponentCall(node) {
13
- // halts unless we are dealing with a styled component
14
- if (!isStyledCallExpression(node)) {
15
- return;
16
- }
17
- // halts if the component is being exported directly
18
- if ((0, _eslintCodemodUtils.closestOfType)(node, 'ExportNamedDeclaration')) {
19
- return;
20
- }
21
- var styledComponentVariableRef = node.parent;
22
- // halts if the styled component is not assigned to a variable immediately
23
- if (!(0, _eslintCodemodUtils.isNodeOfType)(styledComponentVariableRef, 'VariableDeclarator')) {
24
- return;
25
- }
26
- return styledComponentVariableRef;
27
- };
28
-
29
- /**
30
- * Some verbose precondition checks but all it does is check
31
- * a call expression is of form `styled.a` or `styled2.a`
32
- */
33
- var isStyledCallExpression = function isStyledCallExpression(call) {
34
- if (!(0, _eslintCodemodUtils.isNodeOfType)(call, 'CallExpression')) {
35
- return false;
36
- }
37
- if (!(0, _eslintCodemodUtils.isNodeOfType)(call.callee, 'MemberExpression')) {
38
- return false;
39
- }
40
- if (!(0, _eslintCodemodUtils.isNodeOfType)(call.callee.object, 'Identifier') || !(0, _eslintCodemodUtils.isNodeOfType)(call.callee.property, 'Identifier')) {
41
- return false;
42
- }
43
- if (/^styled2?$/.test(call.callee.object.name)) {
44
- return true;
45
- }
46
- return false;
47
- };
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getStyledComponentCall = void 0;
7
- var _eslintCodemodUtils = require("eslint-codemod-utils");
8
- /**
9
- * Returns a styled component
10
- */
11
-
12
- var getStyledComponentCall = exports.getStyledComponentCall = function getStyledComponentCall(node) {
13
- // halts unless we are dealing with a styled component
14
- if (!isStyledCallExpression(node)) {
15
- return;
16
- }
17
- // halts if the component is being exported directly
18
- if ((0, _eslintCodemodUtils.closestOfType)(node, 'ExportNamedDeclaration')) {
19
- return;
20
- }
21
- var styledComponentVariableRef = node.parent;
22
- // halts if the styled component is not assigned to a variable immediately
23
- if (!(0, _eslintCodemodUtils.isNodeOfType)(styledComponentVariableRef, 'VariableDeclarator')) {
24
- return;
25
- }
26
- return styledComponentVariableRef;
27
- };
28
-
29
- /**
30
- * Some verbose precondition checks but all it does is check
31
- * a call expression is of form `styled.button` or `styled2.button`
32
- */
33
- var isStyledCallExpression = function isStyledCallExpression(call) {
34
- if (!(0, _eslintCodemodUtils.isNodeOfType)(call, 'CallExpression')) {
35
- return false;
36
- }
37
- if (!(0, _eslintCodemodUtils.isNodeOfType)(call.callee, 'MemberExpression')) {
38
- return false;
39
- }
40
- if (!(0, _eslintCodemodUtils.isNodeOfType)(call.callee.object, 'Identifier') || !(0, _eslintCodemodUtils.isNodeOfType)(call.callee.property, 'Identifier')) {
41
- return false;
42
- }
43
- if (/^styled2?$/.test(call.callee.object.name)) {
44
- return true;
45
- }
46
- return false;
47
- };
@@ -1,53 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.getJsxElementByName = void 0;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
- var _eslintCodemodUtils = require("eslint-codemod-utils");
10
- /**
11
- * Given a component name finds its JSX usage
12
- */
13
- var getJsxElementByName = exports.getJsxElementByName = function getJsxElementByName(componentName, scope) {
14
- var _variableDeclaration$;
15
- var variableDeclaration = scope.variables.find(function (v) {
16
- return v.name === componentName;
17
- });
18
- if (!variableDeclaration) {
19
- return;
20
- }
21
-
22
- // length here should be exactly 2 to indicate only two references:
23
- // one being the variable declaration itself
24
- // second being the JSX call site
25
- // we might consider handling multiple local JSX call sites in the future
26
- // but "this is good enough for now"™️
27
- if (variableDeclaration.references.length !== 2) {
28
- return;
29
- }
30
- var jsxUsage = (_variableDeclaration$ = variableDeclaration.references[1]) === null || _variableDeclaration$ === void 0 ? void 0 : _variableDeclaration$.identifier;
31
- var _variableDeclaration$2 = variableDeclaration.references.map(function (ref) {
32
- return ref === null || ref === void 0 ? void 0 : ref.identifier;
33
- }),
34
- _variableDeclaration$3 = (0, _slicedToArray2.default)(_variableDeclaration$2, 2),
35
- firstIdentifier = _variableDeclaration$3[0],
36
- secondIdentifier = _variableDeclaration$3[1];
37
- // Check if the first reference is a JSXOpeningElement and the second is not or vice versa
38
- if ((0, _eslintCodemodUtils.isNodeOfType)(firstIdentifier, 'JSXIdentifier') && !(0, _eslintCodemodUtils.isNodeOfType)(secondIdentifier, 'JSXIdentifier')) {
39
- jsxUsage = firstIdentifier;
40
- } else if ((0, _eslintCodemodUtils.isNodeOfType)(secondIdentifier, 'JSXIdentifier') && !(0, _eslintCodemodUtils.isNodeOfType)(firstIdentifier, 'JSXIdentifier')) {
41
- jsxUsage = secondIdentifier;
42
- } else {
43
- return;
44
- }
45
- if (!(0, _eslintCodemodUtils.isNodeOfType)(jsxUsage, 'JSXIdentifier')) {
46
- return;
47
- }
48
- var jsxOpeningElement = jsxUsage.parent;
49
- if (!(0, _eslintCodemodUtils.isNodeOfType)(jsxOpeningElement, 'JSXOpeningElement')) {
50
- return;
51
- }
52
- return jsxOpeningElement;
53
- };
@@ -1,42 +0,0 @@
1
- import { closestOfType, isNodeOfType } from 'eslint-codemod-utils';
2
-
3
- /**
4
- * Returns a styled component
5
- */
6
-
7
- export const getStyledComponentCall = node => {
8
- // halts unless we are dealing with a styled component
9
- if (!isStyledCallExpression(node)) {
10
- return;
11
- }
12
- // halts if the component is being exported directly
13
- if (closestOfType(node, 'ExportNamedDeclaration')) {
14
- return;
15
- }
16
- const styledComponentVariableRef = node.parent;
17
- // halts if the styled component is not assigned to a variable immediately
18
- if (!isNodeOfType(styledComponentVariableRef, 'VariableDeclarator')) {
19
- return;
20
- }
21
- return styledComponentVariableRef;
22
- };
23
-
24
- /**
25
- * Some verbose precondition checks but all it does is check
26
- * a call expression is of form `styled.a` or `styled2.a`
27
- */
28
- const isStyledCallExpression = call => {
29
- if (!isNodeOfType(call, 'CallExpression')) {
30
- return false;
31
- }
32
- if (!isNodeOfType(call.callee, 'MemberExpression')) {
33
- return false;
34
- }
35
- if (!isNodeOfType(call.callee.object, 'Identifier') || !isNodeOfType(call.callee.property, 'Identifier')) {
36
- return false;
37
- }
38
- if (/^styled2?$/.test(call.callee.object.name)) {
39
- return true;
40
- }
41
- return false;
42
- };
@@ -1,42 +0,0 @@
1
- import { closestOfType, isNodeOfType } from 'eslint-codemod-utils';
2
-
3
- /**
4
- * Returns a styled component
5
- */
6
-
7
- export const getStyledComponentCall = node => {
8
- // halts unless we are dealing with a styled component
9
- if (!isStyledCallExpression(node)) {
10
- return;
11
- }
12
- // halts if the component is being exported directly
13
- if (closestOfType(node, 'ExportNamedDeclaration')) {
14
- return;
15
- }
16
- const styledComponentVariableRef = node.parent;
17
- // halts if the styled component is not assigned to a variable immediately
18
- if (!isNodeOfType(styledComponentVariableRef, 'VariableDeclarator')) {
19
- return;
20
- }
21
- return styledComponentVariableRef;
22
- };
23
-
24
- /**
25
- * Some verbose precondition checks but all it does is check
26
- * a call expression is of form `styled.button` or `styled2.button`
27
- */
28
- const isStyledCallExpression = call => {
29
- if (!isNodeOfType(call, 'CallExpression')) {
30
- return false;
31
- }
32
- if (!isNodeOfType(call.callee, 'MemberExpression')) {
33
- return false;
34
- }
35
- if (!isNodeOfType(call.callee.object, 'Identifier') || !isNodeOfType(call.callee.property, 'Identifier')) {
36
- return false;
37
- }
38
- if (/^styled2?$/.test(call.callee.object.name)) {
39
- return true;
40
- }
41
- return false;
42
- };
@@ -1,39 +0,0 @@
1
- import { isNodeOfType } from 'eslint-codemod-utils';
2
-
3
- /**
4
- * Given a component name finds its JSX usage
5
- */
6
- export const getJsxElementByName = (componentName, scope) => {
7
- var _variableDeclaration$;
8
- const variableDeclaration = scope.variables.find(v => v.name === componentName);
9
- if (!variableDeclaration) {
10
- return;
11
- }
12
-
13
- // length here should be exactly 2 to indicate only two references:
14
- // one being the variable declaration itself
15
- // second being the JSX call site
16
- // we might consider handling multiple local JSX call sites in the future
17
- // but "this is good enough for now"™️
18
- if (variableDeclaration.references.length !== 2) {
19
- return;
20
- }
21
- let jsxUsage = (_variableDeclaration$ = variableDeclaration.references[1]) === null || _variableDeclaration$ === void 0 ? void 0 : _variableDeclaration$.identifier;
22
- const [firstIdentifier, secondIdentifier] = variableDeclaration.references.map(ref => ref === null || ref === void 0 ? void 0 : ref.identifier);
23
- // Check if the first reference is a JSXOpeningElement and the second is not or vice versa
24
- if (isNodeOfType(firstIdentifier, 'JSXIdentifier') && !isNodeOfType(secondIdentifier, 'JSXIdentifier')) {
25
- jsxUsage = firstIdentifier;
26
- } else if (isNodeOfType(secondIdentifier, 'JSXIdentifier') && !isNodeOfType(firstIdentifier, 'JSXIdentifier')) {
27
- jsxUsage = secondIdentifier;
28
- } else {
29
- return;
30
- }
31
- if (!isNodeOfType(jsxUsage, 'JSXIdentifier')) {
32
- return;
33
- }
34
- const jsxOpeningElement = jsxUsage.parent;
35
- if (!isNodeOfType(jsxOpeningElement, 'JSXOpeningElement')) {
36
- return;
37
- }
38
- return jsxOpeningElement;
39
- };
@@ -1,42 +0,0 @@
1
- import { closestOfType, isNodeOfType } from 'eslint-codemod-utils';
2
-
3
- /**
4
- * Returns a styled component
5
- */
6
-
7
- export var getStyledComponentCall = function getStyledComponentCall(node) {
8
- // halts unless we are dealing with a styled component
9
- if (!isStyledCallExpression(node)) {
10
- return;
11
- }
12
- // halts if the component is being exported directly
13
- if (closestOfType(node, 'ExportNamedDeclaration')) {
14
- return;
15
- }
16
- var styledComponentVariableRef = node.parent;
17
- // halts if the styled component is not assigned to a variable immediately
18
- if (!isNodeOfType(styledComponentVariableRef, 'VariableDeclarator')) {
19
- return;
20
- }
21
- return styledComponentVariableRef;
22
- };
23
-
24
- /**
25
- * Some verbose precondition checks but all it does is check
26
- * a call expression is of form `styled.a` or `styled2.a`
27
- */
28
- var isStyledCallExpression = function isStyledCallExpression(call) {
29
- if (!isNodeOfType(call, 'CallExpression')) {
30
- return false;
31
- }
32
- if (!isNodeOfType(call.callee, 'MemberExpression')) {
33
- return false;
34
- }
35
- if (!isNodeOfType(call.callee.object, 'Identifier') || !isNodeOfType(call.callee.property, 'Identifier')) {
36
- return false;
37
- }
38
- if (/^styled2?$/.test(call.callee.object.name)) {
39
- return true;
40
- }
41
- return false;
42
- };
@@ -1,42 +0,0 @@
1
- import { closestOfType, isNodeOfType } from 'eslint-codemod-utils';
2
-
3
- /**
4
- * Returns a styled component
5
- */
6
-
7
- export var getStyledComponentCall = function getStyledComponentCall(node) {
8
- // halts unless we are dealing with a styled component
9
- if (!isStyledCallExpression(node)) {
10
- return;
11
- }
12
- // halts if the component is being exported directly
13
- if (closestOfType(node, 'ExportNamedDeclaration')) {
14
- return;
15
- }
16
- var styledComponentVariableRef = node.parent;
17
- // halts if the styled component is not assigned to a variable immediately
18
- if (!isNodeOfType(styledComponentVariableRef, 'VariableDeclarator')) {
19
- return;
20
- }
21
- return styledComponentVariableRef;
22
- };
23
-
24
- /**
25
- * Some verbose precondition checks but all it does is check
26
- * a call expression is of form `styled.button` or `styled2.button`
27
- */
28
- var isStyledCallExpression = function isStyledCallExpression(call) {
29
- if (!isNodeOfType(call, 'CallExpression')) {
30
- return false;
31
- }
32
- if (!isNodeOfType(call.callee, 'MemberExpression')) {
33
- return false;
34
- }
35
- if (!isNodeOfType(call.callee.object, 'Identifier') || !isNodeOfType(call.callee.property, 'Identifier')) {
36
- return false;
37
- }
38
- if (/^styled2?$/.test(call.callee.object.name)) {
39
- return true;
40
- }
41
- return false;
42
- };
@@ -1,47 +0,0 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import { isNodeOfType } from 'eslint-codemod-utils';
3
-
4
- /**
5
- * Given a component name finds its JSX usage
6
- */
7
- export var getJsxElementByName = function getJsxElementByName(componentName, scope) {
8
- var _variableDeclaration$;
9
- var variableDeclaration = scope.variables.find(function (v) {
10
- return v.name === componentName;
11
- });
12
- if (!variableDeclaration) {
13
- return;
14
- }
15
-
16
- // length here should be exactly 2 to indicate only two references:
17
- // one being the variable declaration itself
18
- // second being the JSX call site
19
- // we might consider handling multiple local JSX call sites in the future
20
- // but "this is good enough for now"™️
21
- if (variableDeclaration.references.length !== 2) {
22
- return;
23
- }
24
- var jsxUsage = (_variableDeclaration$ = variableDeclaration.references[1]) === null || _variableDeclaration$ === void 0 ? void 0 : _variableDeclaration$.identifier;
25
- var _variableDeclaration$2 = variableDeclaration.references.map(function (ref) {
26
- return ref === null || ref === void 0 ? void 0 : ref.identifier;
27
- }),
28
- _variableDeclaration$3 = _slicedToArray(_variableDeclaration$2, 2),
29
- firstIdentifier = _variableDeclaration$3[0],
30
- secondIdentifier = _variableDeclaration$3[1];
31
- // Check if the first reference is a JSXOpeningElement and the second is not or vice versa
32
- if (isNodeOfType(firstIdentifier, 'JSXIdentifier') && !isNodeOfType(secondIdentifier, 'JSXIdentifier')) {
33
- jsxUsage = firstIdentifier;
34
- } else if (isNodeOfType(secondIdentifier, 'JSXIdentifier') && !isNodeOfType(firstIdentifier, 'JSXIdentifier')) {
35
- jsxUsage = secondIdentifier;
36
- } else {
37
- return;
38
- }
39
- if (!isNodeOfType(jsxUsage, 'JSXIdentifier')) {
40
- return;
41
- }
42
- var jsxOpeningElement = jsxUsage.parent;
43
- if (!isNodeOfType(jsxOpeningElement, 'JSXOpeningElement')) {
44
- return;
45
- }
46
- return jsxOpeningElement;
47
- };
@@ -1,6 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- import { type VariableDeclarator } from 'eslint-codemod-utils';
3
- /**
4
- * Returns a styled component
5
- */
6
- export declare const getStyledComponentCall: (node: Rule.Node) => (VariableDeclarator & Rule.NodeParentExtension) | undefined;
@@ -1,6 +0,0 @@
1
- import type { Rule, Scope } from 'eslint';
2
- import { type JSXOpeningElement } from 'eslint-codemod-utils';
3
- /**
4
- * Given a component name finds its JSX usage
5
- */
6
- export declare const getJsxElementByName: (componentName: string, scope: Scope.Scope) => (JSXOpeningElement & Rule.NodeParentExtension) | undefined;