@hero-design/eslint-plugin 7.27.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.
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @fileoverview Disallow deprecated component props
3
+ * @author Thong Quach
4
+ */
5
+ 'use strict';
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const rule = require('../../../lib/rules/no-deprecated-component-prop'),
12
+ RuleTester = require('eslint').RuleTester;
13
+
14
+ //------------------------------------------------------------------------------
15
+ // Tests
16
+ //------------------------------------------------------------------------------
17
+
18
+ const config = {
19
+ options: [
20
+ {
21
+ package: '@hero-design/rn',
22
+ components: [
23
+ { name: 'Card', props: ['variant'] },
24
+ { name: 'Box', props: ['padding', 'margin'] },
25
+ { name: 'Select', props: ['onDimiss', 'numberOfLines'] },
26
+ { name: 'Select.Multi', props: ['onDimiss', 'numberOfLines'] },
27
+ ],
28
+ },
29
+ ],
30
+ parserOptions: {
31
+ sourceType: 'module',
32
+ ecmaVersion: 6,
33
+ ecmaFeatures: { jsx: true },
34
+ },
35
+ };
36
+
37
+ const ruleTester = new RuleTester();
38
+ ruleTester.run('no-deprecated-component-prop', rule, {
39
+ valid: [
40
+ {
41
+ code: '<Box padding="large" {...props} />',
42
+ },
43
+ {
44
+ code: 'import HD from "@hero-design/rn"; <Card intent="primary" {...props} />',
45
+ },
46
+ {
47
+ code: 'import { Card, Box } from "@hero-design/rn"; <Card intent="primary" />',
48
+ },
49
+ {
50
+ code: 'import { Card, Box } from "ant-design"; <Card variant="card" />',
51
+ },
52
+ {
53
+ code: 'import { Card as HDCard, Box } from "@hero-design/rn"; <Card variant="basic" />',
54
+ },
55
+ {
56
+ code: 'import { Select } from "@hero-design/rn"; <Select.Multi onClose={() => {}} />',
57
+ },
58
+ {
59
+ code: 'import * as HD from "@hero-design/rn"; <Card variant="basic" />',
60
+ },
61
+ {
62
+ code: 'import * as HD from "@hero-design/rn"; <HD.Select.Multi onClose={() => {}} />',
63
+ },
64
+ ].map((test) => ({
65
+ ...test,
66
+ ...config,
67
+ })),
68
+
69
+ invalid: [
70
+ {
71
+ code: 'import { Card, Box } from "@hero-design/rn"; <Card variant="basic" />',
72
+ errors: [{ messageId: 'deprecatedProp' }],
73
+ },
74
+ {
75
+ code: 'import { Card as HDCard, Box } from "@hero-design/rn"; <HDCard variant="basic" />',
76
+ errors: [{ messageId: 'deprecatedProp' }],
77
+ },
78
+ {
79
+ code: 'import { Card as HDCard, Box as HDBox } from "@hero-design/rn"; <HDBox padding="large" margin="small"/>',
80
+ errors: [
81
+ { messageId: 'deprecatedProp' },
82
+ { messageId: 'deprecatedProp' },
83
+ ],
84
+ },
85
+ {
86
+ code: 'import { Select } from "@hero-design/rn"; <Select onDimiss={() => {}} />',
87
+ errors: [{ messageId: 'deprecatedProp' }],
88
+ },
89
+ {
90
+ code: 'import { Select } from "@hero-design/rn"; <><Select onDimiss={() => {}} numberOfLines={2} /><Select.Multi onDimiss={() => {}} numberOfLines={2} /></>',
91
+ errors: [
92
+ { messageId: 'deprecatedProp' },
93
+ { messageId: 'deprecatedProp' },
94
+ { messageId: 'deprecatedProp' },
95
+ { messageId: 'deprecatedProp' },
96
+ ],
97
+ },
98
+ {
99
+ code: 'import * as HD from "@hero-design/rn"; <HD.Card variant="basic" />',
100
+ errors: [{ messageId: 'deprecatedProp' }],
101
+ },
102
+ {
103
+ code: 'import * as HD from "@hero-design/rn"; <HD.Select.Multi onDimiss={() => {}} />',
104
+ errors: [{ messageId: 'deprecatedProp' }],
105
+ },
106
+ ].map((test) => ({
107
+ ...test,
108
+ ...config,
109
+ })),
110
+ });
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @fileoverview Disallow deprecated theme keys
3
+ * @author Thong Quach
4
+ */
5
+ 'use strict';
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const rule = require('../../../lib/rules/no-deprecated-theme-key'),
12
+ RuleTester = require('eslint').RuleTester;
13
+
14
+ //------------------------------------------------------------------------------
15
+ // Tests
16
+ //------------------------------------------------------------------------------
17
+
18
+ const config = {
19
+ options: [
20
+ {
21
+ keys: [
22
+ { old: 'deprecatedKey', new: 'newKey' },
23
+ { old: 'colors.globalPrimary', new: 'colors.onDefaultGlobalSurface' },
24
+ { old: 'colors.globalPrimaryLight', new: 'colors.globalPrimaryLight' },
25
+ {
26
+ old: 'colors.globalPrimaryBackground',
27
+ new: 'colors.defaultGlobalSurface',
28
+ },
29
+ ],
30
+ },
31
+ ],
32
+ parserOptions: {
33
+ sourceType: 'module',
34
+ ecmaVersion: 6,
35
+ ecmaFeatures: { jsx: true },
36
+ },
37
+ };
38
+
39
+ const ruleTester = new RuleTester();
40
+ ruleTester.run('no-deprecated-theme-key', rule, {
41
+ valid: [
42
+ {
43
+ code: '<Card style={{ backgroundColor: theme.colors.onDefaultGlobalSurface }} />',
44
+ },
45
+ {
46
+ code: '<Card style={{ backgroundColor: theme.randomKey }} />',
47
+ },
48
+ {
49
+ code: '<Card style={{ backgroundColor: seen ? theme.colors.onDefaultGlobalSurface : theme.colors.defaultGlobalSurface }} />',
50
+ },
51
+ ].map((test) => ({ ...test, ...config })),
52
+ invalid: [
53
+ {
54
+ code: 'const value = theme.deprecatedKey',
55
+ output: 'const value = theme.newKey',
56
+ errors: [{ messageId: 'deprecatedThemeKey' }],
57
+ },
58
+ {
59
+ code: '<Card style={{ backgroundColor: theme.colors.globalPrimary }} />',
60
+ output:
61
+ '<Card style={{ backgroundColor: theme.colors.onDefaultGlobalSurface }} />',
62
+ errors: [{ messageId: 'deprecatedThemeKey' }],
63
+ },
64
+ {
65
+ code: '<Card style={{ backgroundColor: theme.colors.globalPrimaryLight }} />',
66
+ output:
67
+ '<Card style={{ backgroundColor: theme.colors.globalPrimaryLight }} />',
68
+ errors: [{ messageId: 'deprecatedThemeKey' }],
69
+ },
70
+ {
71
+ code: '<Card style={{ backgroundColor: seen ? theme.colors.onDefaultGlobalSurface : theme.colors.globalPrimaryBackground }} />',
72
+ output:
73
+ '<Card style={{ backgroundColor: seen ? theme.colors.onDefaultGlobalSurface : theme.colors.defaultGlobalSurface }} />',
74
+ errors: [{ messageId: 'deprecatedThemeKey' }],
75
+ },
76
+ ].map((test) => ({ ...test, ...config })),
77
+ });
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @fileoverview Disallow not recommended imports
3
+ * @author Thong Quach
4
+ */
5
+ 'use strict';
6
+
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
11
+ const rule = require('../../../lib/rules/not-recommended-import'),
12
+ RuleTester = require('eslint').RuleTester;
13
+
14
+ const config = {
15
+ options: [
16
+ {
17
+ package: '@hero-design/rn',
18
+ imports: [
19
+ {
20
+ name: 'swagSystemPalette',
21
+ message: 'Please use colors from useTheme hook instead.',
22
+ },
23
+ ],
24
+ },
25
+ {
26
+ package: '@hero-design/colors',
27
+ imports: [
28
+ {
29
+ name: 'default',
30
+ message: 'Please use colors from useTheme hook instead.',
31
+ },
32
+ {
33
+ name: 'mixColor',
34
+ message: 'Please use colors from useTheme hook instead.',
35
+ },
36
+ {
37
+ name: 'colorScales',
38
+ message: 'Please use colors from useTheme hook instead.',
39
+ },
40
+ {
41
+ name: 'swagPalette',
42
+ message: 'Please use colors from useTheme hook instead.',
43
+ },
44
+ ],
45
+ },
46
+ ],
47
+ parserOptions: { sourceType: 'module', ecmaVersion: 6 },
48
+ };
49
+
50
+ const ruleTester = new RuleTester();
51
+ ruleTester.run('not-recommended-import', rule, {
52
+ valid: [
53
+ {
54
+ code: "import { mobileVisualisationPalette } from '@hero-design/colors';",
55
+ },
56
+ ].map((test) => ({ ...test, ...config })),
57
+
58
+ invalid: [
59
+ {
60
+ code: "import palette from '@hero-design/colors';",
61
+ errors: [{ messageId: 'notRecommendedImport' }],
62
+ },
63
+ {
64
+ code: "import { swagPalette, colorScales } from '@hero-design/colors';",
65
+ errors: [
66
+ { messageId: 'notRecommendedImport' },
67
+ { messageId: 'notRecommendedImport' },
68
+ ],
69
+ },
70
+ {
71
+ code: "import palette, { swagPalette } from '@hero-design/colors';",
72
+ errors: [
73
+ { messageId: 'notRecommendedImport' },
74
+ { messageId: 'notRecommendedImport' },
75
+ ],
76
+ },
77
+ {
78
+ code: "import { Box, Drawer, swagSystemPalette } from '@hero-design/rn';",
79
+ errors: [{ messageId: 'notRecommendedImport' }],
80
+ },
81
+ ].map((test) => ({ ...test, ...config })),
82
+ });