@hero-design/snowflake-guard 1.2.4 → 1.3.0-alpha.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.
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const reportCustomStyleProperties_1 = __importDefault(require("../reportCustomStyleProperties"));
7
+ const testUtils_1 = require("../testUtils");
8
+ const componentList = {
9
+ Card: 'Card',
10
+ Button: 'Button',
11
+ };
12
+ const commentList = {
13
+ styleCmts: [],
14
+ };
15
+ describe('reportCustomStyleProperties', () => {
16
+ beforeEach(() => {
17
+ jest.clearAllMocks();
18
+ });
19
+ it('should detect component with inline styles', () => {
20
+ const source = `const styles = {
21
+ card: {
22
+ padding: 10,
23
+ },
24
+ };
25
+
26
+ const App = () => (
27
+ <Card style={styles.card}><Content/></Card>
28
+ );
29
+ `;
30
+ const ast = (0, testUtils_1.parseTypeScript)(source);
31
+ const result = (0, reportCustomStyleProperties_1.default)(ast, componentList, commentList);
32
+ expect(result).toEqual({
33
+ style: [8],
34
+ violatingAttributes: [
35
+ {
36
+ attributeName: 'padding',
37
+ attributeValue: '10',
38
+ componentName: 'Card',
39
+ inlineStyleProps: 'style',
40
+ loc: 8,
41
+ },
42
+ ],
43
+ });
44
+ });
45
+ it('should detect compound component with inline styles', () => {
46
+ const source = `const App = () => (
47
+ <Button.Icon style={{ padding: 10 }} />
48
+ );
49
+ `;
50
+ const ast = (0, testUtils_1.parseTypeScript)(source);
51
+ const result = (0, reportCustomStyleProperties_1.default)(ast, componentList, commentList);
52
+ expect(result).toEqual({
53
+ style: [2],
54
+ violatingAttributes: [
55
+ {
56
+ attributeName: 'padding',
57
+ attributeValue: '10',
58
+ componentName: 'Button.Icon',
59
+ inlineStyleProps: 'style',
60
+ loc: 2,
61
+ },
62
+ ],
63
+ });
64
+ });
65
+ it('should detect compound component using spread operator with inline styles', () => {
66
+ const source = `const { Icon } = Button;
67
+ const App = () => (
68
+ <Icon style={{ padding: 10 }} />
69
+ );
70
+ `;
71
+ const ast = (0, testUtils_1.parseTypeScript)(source);
72
+ const result = (0, reportCustomStyleProperties_1.default)(ast, componentList, commentList);
73
+ expect(result).toEqual({
74
+ style: [3],
75
+ violatingAttributes: [
76
+ {
77
+ attributeName: 'padding',
78
+ attributeValue: '10',
79
+ componentName: 'Button.Icon',
80
+ inlineStyleProps: 'style',
81
+ loc: 3,
82
+ },
83
+ ],
84
+ });
85
+ });
86
+ it('should not detect non-custom style properties', () => {
87
+ const source = `
88
+ const App = () => (
89
+ <Card><Content/></Card>
90
+ );
91
+ `;
92
+ const ast = (0, testUtils_1.parseTypeScript)(source);
93
+ const result = (0, reportCustomStyleProperties_1.default)(ast, componentList, commentList);
94
+ expect(result).toEqual({ style: [], violatingAttributes: [] });
95
+ });
96
+ it('should ignore approved inline styles', () => {
97
+ const mockedCommentList = {
98
+ styleCmts: [
99
+ {
100
+ loc: 10,
101
+ comment: '@snowflake-guard/approved-inline-style attributes: padding',
102
+ },
103
+ ],
104
+ };
105
+ const source = `
106
+ const styles = {
107
+ button: {
108
+ padding: 10,
109
+ },
110
+ };
111
+
112
+ const App = () => (
113
+ <>
114
+ {/* @snowflake-guard/approved-inline-style attributes: padding */}
115
+ <Button style={styles.button} />
116
+ </>
117
+ );
118
+ `;
119
+ const ast = (0, testUtils_1.parseTypeScript)(source);
120
+ const result = (0, reportCustomStyleProperties_1.default)(ast, componentList, mockedCommentList);
121
+ expect(result).toEqual({ style: [], violatingAttributes: [] });
122
+ });
123
+ });
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const recast = __importStar(require("recast"));
30
+ const reportInlineStyle_1 = __importDefault(require("../reportInlineStyle"));
31
+ const constants_1 = require("../constants");
32
+ const tsParser = __importStar(require("../../../parsers/typescript"));
33
+ describe('reportInlineStyle', () => {
34
+ it('should return line numbers and violating attributes for inline styles that violate the ruleset', () => {
35
+ const code = `
36
+ const MyComponent = () => (
37
+ <Card style={{
38
+ color: 'red',
39
+ backgroundColor: 'blue'
40
+ }}
41
+ />
42
+ );
43
+ `;
44
+ // Step 1: Parse the code to generate the AST
45
+ const ast = recast.parse(code, { parser: tsParser });
46
+ const attributes = [];
47
+ // Step 2: Traverse the AST to extract relevant JSXAttributes (style)
48
+ recast.visit(ast, {
49
+ visitJSXAttribute(path) {
50
+ const { node } = path;
51
+ attributes.push(node);
52
+ this.traverse(path);
53
+ },
54
+ });
55
+ const componentName = 'Card';
56
+ // Mock the RULESET_MAP for this test
57
+ constants_1.MOBILE_RULESET_MAP.Card = ['color', 'backgroundColor'];
58
+ // Step 3: Run the function with the dynamically extracted attributes
59
+ const result = (0, reportInlineStyle_1.default)(ast, attributes, componentName);
60
+ expect(result.locs.style).toEqual(3);
61
+ expect(result.violatingAttributes).toEqual([
62
+ {
63
+ attributeName: 'color',
64
+ attributeValue: "'red'",
65
+ componentName: 'Card',
66
+ inlineStyleProps: 'style',
67
+ loc: 3,
68
+ },
69
+ {
70
+ attributeName: 'backgroundColor',
71
+ attributeValue: "'blue'",
72
+ componentName: 'Card',
73
+ inlineStyleProps: 'style',
74
+ loc: 3,
75
+ },
76
+ ]);
77
+ });
78
+ it('should return empty arrays when no violations are found', () => {
79
+ const code = `
80
+ const MyComponent = () => (
81
+ <Card style={{ margin: 10 }} />
82
+ );
83
+ `;
84
+ // Step 1: Parse the code to generate the AST
85
+ const ast = recast.parse(code, { parser: tsParser });
86
+ const attributes = [];
87
+ // Step 2: Traverse the AST to extract relevant JSXAttributes (style)
88
+ recast.visit(ast, {
89
+ visitJSXAttribute(path) {
90
+ const { node } = path;
91
+ attributes.push(node);
92
+ this.traverse(path);
93
+ },
94
+ });
95
+ const componentName = 'Card';
96
+ // Mock the RULESET_MAP and SX_RULESET_MAP for this test
97
+ constants_1.MOBILE_RULESET_MAP.Card = ['color'];
98
+ const result = (0, reportInlineStyle_1.default)(ast, attributes, componentName);
99
+ expect(result.locs.style).toEqual(undefined);
100
+ expect(result.violatingAttributes).toEqual([]);
101
+ expect(result.violatingAttributes).toEqual([]);
102
+ });
103
+ });
@@ -82,4 +82,17 @@ declare const MOBILE_RULESET_MAP: {
82
82
  'Typography.Caption': string[];
83
83
  'Typography.Label': string[];
84
84
  };
85
- export { HD_MOBILE_COMPONENTS, MOBILE_RULESET_MAP };
85
+ declare const BAR_STYLE_RULESET_MAP: {
86
+ Tabs: string[];
87
+ 'Tabs.Scroll': string[];
88
+ };
89
+ declare const CONTAINER_STYLE_RULESET_MAP: {
90
+ Tabs: string[];
91
+ 'Tabs.Scroll': string[];
92
+ };
93
+ declare const TEXT_STYLE_RULESET_MAP: {
94
+ 'Toolbar.Message': string[];
95
+ TextInput: string[];
96
+ 'Search.OneLine': string[];
97
+ };
98
+ export { HD_MOBILE_COMPONENTS, MOBILE_RULESET_MAP, BAR_STYLE_RULESET_MAP, CONTAINER_STYLE_RULESET_MAP, TEXT_STYLE_RULESET_MAP, };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MOBILE_RULESET_MAP = exports.HD_MOBILE_COMPONENTS = void 0;
3
+ exports.TEXT_STYLE_RULESET_MAP = exports.CONTAINER_STYLE_RULESET_MAP = exports.BAR_STYLE_RULESET_MAP = exports.MOBILE_RULESET_MAP = exports.HD_MOBILE_COMPONENTS = void 0;
4
4
  const PADDING_ATTRS = [
5
5
  'padding',
6
6
  'paddingBottom',
@@ -347,42 +347,99 @@ const MOBILE_RULESET_MAP = {
347
347
  ...HEIGHT_ATTRS,
348
348
  ],
349
349
  'Toast.Container': [
350
- ...PADDING_ATTRS,
351
- ...BORDER_ATTRS,
352
- ...SHADOW_ATTRS,
353
- ...TEXT_ATTRS,
350
+ ...COMMON_PROHIBITED_ATTRS,
351
+ ...WIDTH_ATTRS,
354
352
  ...HEIGHT_ATTRS,
353
+ ...MARGIN_ATTRS,
355
354
  ],
356
355
  'Toast.Provider': [
356
+ ...COMMON_PROHIBITED_ATTRS,
357
+ ...WIDTH_ATTRS,
358
+ ...HEIGHT_ATTRS,
359
+ ...MARGIN_ATTRS,
360
+ ],
361
+ 'Toolbar.Group': [
362
+ ...COMMON_PROHIBITED_ATTRS,
363
+ ...WIDTH_ATTRS,
364
+ ...HEIGHT_ATTRS,
365
+ ...MARGIN_ATTRS,
366
+ ],
367
+ 'Toolbar.Item': [
368
+ ...COMMON_PROHIBITED_ATTRS,
369
+ ...WIDTH_ATTRS,
370
+ ...HEIGHT_ATTRS,
371
+ ...MARGIN_ATTRS,
372
+ ],
373
+ 'Toolbar.Message': [
374
+ ...COMMON_PROHIBITED_ATTRS,
375
+ ...WIDTH_ATTRS,
376
+ ...HEIGHT_ATTRS,
377
+ ...MARGIN_ATTRS,
378
+ ],
379
+ 'Typography.Body': [...COMMON_PROHIBITED_ATTRS, ...HEIGHT_ATTRS],
380
+ 'Typography.Caption': [...COMMON_PROHIBITED_ATTRS, ...HEIGHT_ATTRS],
381
+ 'Typography.Label': [...COMMON_PROHIBITED_ATTRS, ...HEIGHT_ATTRS],
382
+ };
383
+ exports.MOBILE_RULESET_MAP = MOBILE_RULESET_MAP;
384
+ const BAR_STYLE_RULESET_MAP = {
385
+ Tabs: [
357
386
  ...PADDING_ATTRS,
358
387
  ...BORDER_ATTRS,
359
- ...SHADOW_ATTRS,
360
388
  ...TEXT_ATTRS,
389
+ ...SHADOW_ATTRS,
390
+ ...WIDTH_ATTRS,
361
391
  ...HEIGHT_ATTRS,
392
+ ...MARGIN_ATTRS,
362
393
  ],
363
- 'Toolbar.Group': [
394
+ 'Tabs.Scroll': [
364
395
  ...PADDING_ATTRS,
365
396
  ...BORDER_ATTRS,
366
- ...SHADOW_ATTRS,
367
397
  ...TEXT_ATTRS,
398
+ ...SHADOW_ATTRS,
399
+ ...WIDTH_ATTRS,
368
400
  ...HEIGHT_ATTRS,
401
+ ...MARGIN_ATTRS,
369
402
  ],
370
- 'Toolbar.Item': [
371
- ...PADDING_ATTRS,
403
+ };
404
+ exports.BAR_STYLE_RULESET_MAP = BAR_STYLE_RULESET_MAP;
405
+ const CONTAINER_STYLE_RULESET_MAP = {
406
+ Tabs: [
372
407
  ...BORDER_ATTRS,
408
+ ...TEXT_ATTRS,
373
409
  ...SHADOW_ATTRS,
410
+ ...WIDTH_ATTRS,
411
+ ...HEIGHT_ATTRS,
412
+ ...MARGIN_ATTRS,
413
+ ],
414
+ 'Tabs.Scroll': [
415
+ ...BORDER_ATTRS,
374
416
  ...TEXT_ATTRS,
417
+ ...SHADOW_ATTRS,
418
+ ...WIDTH_ATTRS,
375
419
  ...HEIGHT_ATTRS,
420
+ ...MARGIN_ATTRS,
376
421
  ],
422
+ };
423
+ exports.CONTAINER_STYLE_RULESET_MAP = CONTAINER_STYLE_RULESET_MAP;
424
+ const TEXT_STYLE_RULESET_MAP = {
377
425
  'Toolbar.Message': [
426
+ ...COMMON_PROHIBITED_ATTRS,
427
+ ...WIDTH_ATTRS,
428
+ ...HEIGHT_ATTRS,
429
+ ...MARGIN_ATTRS,
430
+ ],
431
+ TextInput: [
378
432
  ...PADDING_ATTRS,
379
433
  ...BORDER_ATTRS,
380
434
  ...SHADOW_ATTRS,
381
435
  ...TEXT_ATTRS,
382
436
  ...HEIGHT_ATTRS,
383
437
  ],
384
- 'Typography.Body': [...COMMON_PROHIBITED_ATTRS, ...HEIGHT_ATTRS],
385
- 'Typography.Caption': [...COMMON_PROHIBITED_ATTRS, ...HEIGHT_ATTRS],
386
- 'Typography.Label': [...COMMON_PROHIBITED_ATTRS, ...HEIGHT_ATTRS],
438
+ 'Search.OneLine': [
439
+ ...COMMON_PROHIBITED_ATTRS,
440
+ ...WIDTH_ATTRS,
441
+ ...HEIGHT_ATTRS,
442
+ ...MARGIN_ATTRS,
443
+ ],
387
444
  };
388
- exports.MOBILE_RULESET_MAP = MOBILE_RULESET_MAP;
445
+ exports.TEXT_STYLE_RULESET_MAP = TEXT_STYLE_RULESET_MAP;
@@ -0,0 +1,41 @@
1
+ import * as recast from 'recast';
2
+ import { InlineStyleProps, ViolatingAttribute } from './reportInlineStyle';
3
+ import type { CompoundMobileComponentName, MobileComponentName } from './types';
4
+ export declare const getNonApprovedInlineLocs: (reportedLocs: {
5
+ style?: number;
6
+ barStyle?: number;
7
+ containerStyle?: number;
8
+ textStyle?: number;
9
+ }, violatingAttributes: ViolatingAttribute[], approvedCmts: {
10
+ loc: number;
11
+ comment: string;
12
+ }[], elementLoc: number) => {
13
+ reportedLocs: {
14
+ style?: number;
15
+ barStyle?: number;
16
+ containerStyle?: number;
17
+ textStyle?: number;
18
+ };
19
+ noneApprovedAttributes: ViolatingAttribute[];
20
+ };
21
+ declare const reportCustomProperties: (ast: recast.types.ASTNode, componentList: {
22
+ [k: string]: MobileComponentName;
23
+ }, commentList: {
24
+ styleCmts: {
25
+ loc: number;
26
+ comment: string;
27
+ }[];
28
+ }) => {
29
+ style: number[];
30
+ barStyle: number[];
31
+ containerStyle: number[];
32
+ textStyle: number[];
33
+ violatingAttributes: {
34
+ attributeName: string;
35
+ attributeValue: string | null;
36
+ inlineStyleProps: InlineStyleProps;
37
+ componentName: CompoundMobileComponentName;
38
+ loc: number | undefined;
39
+ }[];
40
+ };
41
+ export default reportCustomProperties;
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.getNonApprovedInlineLocs = void 0;
30
+ const recast = __importStar(require("recast"));
31
+ const reportInlineStyle_1 = __importDefault(require("./reportInlineStyle"));
32
+ const mapViolatingAttributesAndAdditionalProps = (violatingAttributes) => {
33
+ return violatingAttributes.map((violatingAttribute) => (Object.assign({}, violatingAttribute)));
34
+ };
35
+ const getNonApprovedInlineLocs = (reportedLocs, violatingAttributes, approvedCmts, elementLoc) => {
36
+ var _a, _b;
37
+ const approvedCmt = approvedCmts.find((cmt) => cmt.loc === elementLoc - 1);
38
+ if (approvedCmt) {
39
+ const approvedCmtAttrNames = (_b = (_a = approvedCmt.comment
40
+ .toLowerCase()
41
+ .replace(/\s+/g, '')
42
+ .split('attributes:')[1]) === null || _a === void 0 ? void 0 : _a.split(',')) !== null && _b !== void 0 ? _b : [];
43
+ const noneApprovedStyleAttributes = violatingAttributes.filter((attr) => attr.loc === reportedLocs.style &&
44
+ !approvedCmtAttrNames.includes(attr.attributeName.toLowerCase()));
45
+ const nonApprovedBarStyleAttributes = violatingAttributes.filter((attr) => attr.loc === reportedLocs.barStyle &&
46
+ !approvedCmtAttrNames.includes(attr.attributeName.toLowerCase()));
47
+ const nonApprovedContainerStyleAttributes = violatingAttributes.filter((attr) => attr.loc === reportedLocs.containerStyle &&
48
+ !approvedCmtAttrNames.includes(attr.attributeName.toLowerCase()));
49
+ const nonApprovedTextStyleAttributes = violatingAttributes.filter((attr) => attr.loc === reportedLocs.textStyle &&
50
+ !approvedCmtAttrNames.includes(attr.attributeName.toLowerCase()));
51
+ if (noneApprovedStyleAttributes.length > 0) {
52
+ return {
53
+ reportedLocs,
54
+ noneApprovedAttributes: [
55
+ ...noneApprovedStyleAttributes,
56
+ ...nonApprovedBarStyleAttributes,
57
+ ...nonApprovedContainerStyleAttributes,
58
+ ...nonApprovedTextStyleAttributes,
59
+ ],
60
+ };
61
+ }
62
+ return { reportedLocs: {}, noneApprovedAttributes: [] };
63
+ }
64
+ return { reportedLocs, noneApprovedAttributes: violatingAttributes };
65
+ };
66
+ exports.getNonApprovedInlineLocs = getNonApprovedInlineLocs;
67
+ const reportCustomProperties = (ast, componentList, commentList) => {
68
+ const report = {
69
+ style: [],
70
+ barStyle: [],
71
+ containerStyle: [],
72
+ textStyle: [],
73
+ violatingAttributes: [],
74
+ };
75
+ const localComponentList = Object.keys(componentList);
76
+ recast.visit(ast, {
77
+ visitJSXOpeningElement(path) {
78
+ this.traverse(path);
79
+ // Case 1: Custom default component, e.g. <Button />
80
+ if (path.value.name.type === 'JSXIdentifier' &&
81
+ localComponentList.includes(path.value.name.name)) {
82
+ const attributes = path.value
83
+ .attributes;
84
+ const { locs: styleObjectLocs, violatingAttributes } = (0, reportInlineStyle_1.default)(ast, attributes, componentList[path.value.name.name]);
85
+ const { reportedLocs, noneApprovedAttributes } = (0, exports.getNonApprovedInlineLocs)(styleObjectLocs, violatingAttributes, commentList.styleCmts, path.value.loc.start.line);
86
+ if (reportedLocs.style) {
87
+ report.style.push(reportedLocs.style);
88
+ }
89
+ if (reportedLocs.barStyle) {
90
+ report.style.push(reportedLocs.barStyle);
91
+ }
92
+ if (reportedLocs.containerStyle) {
93
+ report.style.push(reportedLocs.containerStyle);
94
+ }
95
+ if (reportedLocs.textStyle) {
96
+ report.style.push(reportedLocs.textStyle);
97
+ }
98
+ report.violatingAttributes = [
99
+ ...report.violatingAttributes,
100
+ ...mapViolatingAttributesAndAdditionalProps(noneApprovedAttributes),
101
+ ];
102
+ }
103
+ // Case 2: Custom compound component, e.g. <Button.Icon />
104
+ if (path.value.name.type === 'JSXMemberExpression' &&
105
+ localComponentList.includes(path.value.name.object.name)) {
106
+ const compoundComponentName = [
107
+ componentList[path.value.name.object.name],
108
+ path.value.name.property.name,
109
+ ].join('.');
110
+ const attributes = path.value
111
+ .attributes;
112
+ const { locs: styleObjectLocs, violatingAttributes } = (0, reportInlineStyle_1.default)(ast, attributes, compoundComponentName);
113
+ const { reportedLocs, noneApprovedAttributes } = (0, exports.getNonApprovedInlineLocs)(styleObjectLocs, violatingAttributes, commentList.styleCmts, path.value.loc.start.line);
114
+ if (reportedLocs.style) {
115
+ report.style.push(reportedLocs.style);
116
+ }
117
+ if (reportedLocs.barStyle) {
118
+ report.style.push(reportedLocs.barStyle);
119
+ }
120
+ if (reportedLocs.containerStyle) {
121
+ report.style.push(reportedLocs.containerStyle);
122
+ }
123
+ if (reportedLocs.textStyle) {
124
+ report.style.push(reportedLocs.textStyle);
125
+ }
126
+ report.violatingAttributes = [
127
+ ...report.violatingAttributes,
128
+ ...mapViolatingAttributesAndAdditionalProps(noneApprovedAttributes),
129
+ ];
130
+ }
131
+ },
132
+ // Case 3: Custom compound component with spead operator. e.g. const { Icon } = Button, then <Button />
133
+ visitVariableDeclaration(path) {
134
+ this.traverse(path);
135
+ const declaration = path.value
136
+ .declarations[0];
137
+ if (declaration.init &&
138
+ declaration.init.type === 'Identifier' &&
139
+ localComponentList.includes(declaration.init.name)) {
140
+ const componentName = declaration.init.name;
141
+ const { id } = declaration;
142
+ if (id.type === 'ObjectPattern') {
143
+ const compoundComponentNames = id.properties
144
+ .map((prop) => prop.type === 'ObjectProperty' && prop.key.type === 'Identifier'
145
+ ? prop.key.name
146
+ : null)
147
+ .filter((name) => name !== null);
148
+ recast.visit(ast, {
149
+ visitJSXOpeningElement(openPath) {
150
+ this.traverse(openPath);
151
+ if (openPath.value.name.type === 'JSXIdentifier' &&
152
+ compoundComponentNames.includes(openPath.value.name.name)) {
153
+ const compoundComponentName = [
154
+ componentList[componentName],
155
+ openPath.value.name.name,
156
+ ].join('.');
157
+ const { attributes } = openPath.value;
158
+ const { locs: styleObjectLocs, violatingAttributes } = (0, reportInlineStyle_1.default)(ast, attributes, compoundComponentName);
159
+ const { reportedLocs, noneApprovedAttributes } = (0, exports.getNonApprovedInlineLocs)(styleObjectLocs, violatingAttributes, commentList.styleCmts, openPath.value.loc.start.line);
160
+ if (reportedLocs.style) {
161
+ report.style.push(reportedLocs.style);
162
+ }
163
+ if (reportedLocs.barStyle) {
164
+ report.style.push(reportedLocs.barStyle);
165
+ }
166
+ if (reportedLocs.containerStyle) {
167
+ report.style.push(reportedLocs.containerStyle);
168
+ }
169
+ if (reportedLocs.textStyle) {
170
+ report.style.push(reportedLocs.textStyle);
171
+ }
172
+ report.violatingAttributes = [
173
+ ...report.violatingAttributes,
174
+ ...mapViolatingAttributesAndAdditionalProps(noneApprovedAttributes),
175
+ ];
176
+ }
177
+ },
178
+ });
179
+ }
180
+ }
181
+ },
182
+ });
183
+ return report;
184
+ };
185
+ exports.default = reportCustomProperties;
@@ -0,0 +1,21 @@
1
+ import * as recast from 'recast';
2
+ import type { CompoundMobileComponentName } from './types';
3
+ export type InlineStyleProps = 'style' | 'barStyle' | 'containerStyle' | 'textStyle';
4
+ export declare const INLINE_STYLE_PROPERTIES: string[];
5
+ export type ViolatingAttribute = {
6
+ attributeName: string;
7
+ attributeValue: string | null;
8
+ inlineStyleProps: InlineStyleProps;
9
+ componentName: CompoundMobileComponentName;
10
+ loc: number | undefined;
11
+ };
12
+ declare const reportInlineStyle: (ast: recast.types.ASTNode, attributes: recast.types.namedTypes.JSXAttribute[], componentName: CompoundMobileComponentName) => {
13
+ locs: {
14
+ style?: number;
15
+ barStyle?: number;
16
+ containerStyle?: number;
17
+ textStyle?: number;
18
+ };
19
+ violatingAttributes: ViolatingAttribute[];
20
+ };
21
+ export default reportInlineStyle;