@hero-design/snowflake-guard 1.4.10 → 1.4.12

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 (61) hide show
  1. package/package.json +2 -2
  2. package/lib/src/__tests__/parseMobileSource.spec.d.ts +0 -1
  3. package/lib/src/__tests__/parseMobileSource.spec.js +0 -417
  4. package/lib/src/__tests__/parseSource.spec.d.ts +0 -1
  5. package/lib/src/__tests__/parseSource.spec.js +0 -207
  6. package/lib/src/graphql/__tests__/fetchGrapql.spec.d.ts +0 -1
  7. package/lib/src/graphql/__tests__/fetchGrapql.spec.js +0 -33
  8. package/lib/src/graphql/__tests__/queryGenerators.spec.d.ts +0 -1
  9. package/lib/src/graphql/__tests__/queryGenerators.spec.js +0 -82
  10. package/lib/src/graphql/fetchGraphql.d.ts +0 -2
  11. package/lib/src/graphql/fetchGraphql.js +0 -23
  12. package/lib/src/graphql/queryGenerators.d.ts +0 -18
  13. package/lib/src/graphql/queryGenerators.js +0 -61
  14. package/lib/src/graphql/types.d.ts +0 -18
  15. package/lib/src/graphql/types.js +0 -2
  16. package/lib/src/index.d.ts +0 -3
  17. package/lib/src/index.js +0 -175
  18. package/lib/src/parseMobileSource.d.ts +0 -15
  19. package/lib/src/parseMobileSource.js +0 -135
  20. package/lib/src/parseSource.d.ts +0 -17
  21. package/lib/src/parseSource.js +0 -138
  22. package/lib/src/parsers/flow.d.ts +0 -3
  23. package/lib/src/parsers/flow.js +0 -47
  24. package/lib/src/parsers/typescript.d.ts +0 -3
  25. package/lib/src/parsers/typescript.js +0 -47
  26. package/lib/src/reports/__tests__/reportInlineStyle.spec.d.ts +0 -1
  27. package/lib/src/reports/__tests__/reportInlineStyle.spec.js +0 -143
  28. package/lib/src/reports/constants.d.ts +0 -233
  29. package/lib/src/reports/constants.js +0 -917
  30. package/lib/src/reports/mobile/__tests__/reportCustomStyleProperties.spec.d.ts +0 -1
  31. package/lib/src/reports/mobile/__tests__/reportCustomStyleProperties.spec.js +0 -144
  32. package/lib/src/reports/mobile/__tests__/reportInlineStyle.spec.d.ts +0 -1
  33. package/lib/src/reports/mobile/__tests__/reportInlineStyle.spec.js +0 -113
  34. package/lib/src/reports/mobile/__tests__/reportStyledComponents.spec.d.ts +0 -1
  35. package/lib/src/reports/mobile/__tests__/reportStyledComponents.spec.js +0 -54
  36. package/lib/src/reports/mobile/constants.d.ts +0 -106
  37. package/lib/src/reports/mobile/constants.js +0 -470
  38. package/lib/src/reports/mobile/reportCustomStyleProperties.d.ts +0 -24
  39. package/lib/src/reports/mobile/reportCustomStyleProperties.js +0 -193
  40. package/lib/src/reports/mobile/reportInlineStyle.d.ts +0 -20
  41. package/lib/src/reports/mobile/reportInlineStyle.js +0 -223
  42. package/lib/src/reports/mobile/reportStyledComponents.d.ts +0 -6
  43. package/lib/src/reports/mobile/reportStyledComponents.js +0 -105
  44. package/lib/src/reports/mobile/testUtils.d.ts +0 -1
  45. package/lib/src/reports/mobile/testUtils.js +0 -42
  46. package/lib/src/reports/mobile/types.d.ts +0 -3
  47. package/lib/src/reports/mobile/types.js +0 -2
  48. package/lib/src/reports/reportClassName.d.ts +0 -3
  49. package/lib/src/reports/reportClassName.js +0 -12
  50. package/lib/src/reports/reportCustomStyleProperties.d.ts +0 -25
  51. package/lib/src/reports/reportCustomStyleProperties.js +0 -185
  52. package/lib/src/reports/reportInlineStyle.d.ts +0 -23
  53. package/lib/src/reports/reportInlineStyle.js +0 -238
  54. package/lib/src/reports/reportStyledComponents.d.ts +0 -6
  55. package/lib/src/reports/reportStyledComponents.js +0 -105
  56. package/lib/src/reports/types.d.ts +0 -3
  57. package/lib/src/reports/types.js +0 -2
  58. package/lib/src/utils/__tests__/getDiffLocs.spec.d.ts +0 -1
  59. package/lib/src/utils/__tests__/getDiffLocs.spec.js +0 -43
  60. package/lib/src/utils/getDiffLocs.d.ts +0 -3
  61. package/lib/src/utils/getDiffLocs.js +0 -40
@@ -1,144 +0,0 @@
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
- barStyle: [],
35
- textStyle: [],
36
- containerStyle: [],
37
- violatingAttributes: [
38
- {
39
- attributeName: 'padding',
40
- attributeValue: '10',
41
- componentName: 'Card',
42
- inlineStyleProps: 'style',
43
- loc: 8,
44
- },
45
- ],
46
- });
47
- });
48
- it('should detect compound component with inline styles', () => {
49
- const source = `const App = () => (
50
- <Button.Icon style={{ padding: 10 }} />
51
- );
52
- `;
53
- const ast = (0, testUtils_1.parseTypeScript)(source);
54
- const result = (0, reportCustomStyleProperties_1.default)(ast, componentList, commentList);
55
- expect(result).toEqual({
56
- style: [2],
57
- barStyle: [],
58
- textStyle: [],
59
- containerStyle: [],
60
- violatingAttributes: [
61
- {
62
- attributeName: 'padding',
63
- attributeValue: '10',
64
- componentName: 'Button.Icon',
65
- inlineStyleProps: 'style',
66
- loc: 2,
67
- },
68
- ],
69
- });
70
- });
71
- it('should detect compound component using spread operator with inline styles', () => {
72
- const source = `const { Icon } = Button;
73
- const App = () => (
74
- <Icon style={{ padding: 10 }} />
75
- );
76
- `;
77
- const ast = (0, testUtils_1.parseTypeScript)(source);
78
- const result = (0, reportCustomStyleProperties_1.default)(ast, componentList, commentList);
79
- expect(result).toEqual({
80
- style: [3],
81
- barStyle: [],
82
- textStyle: [],
83
- containerStyle: [],
84
- violatingAttributes: [
85
- {
86
- attributeName: 'padding',
87
- attributeValue: '10',
88
- componentName: 'Button.Icon',
89
- inlineStyleProps: 'style',
90
- loc: 3,
91
- },
92
- ],
93
- });
94
- });
95
- it('should not detect non-custom style properties', () => {
96
- const source = `
97
- const App = () => (
98
- <Card><Content/></Card>
99
- );
100
- `;
101
- const ast = (0, testUtils_1.parseTypeScript)(source);
102
- const result = (0, reportCustomStyleProperties_1.default)(ast, componentList, commentList);
103
- expect(result).toEqual({
104
- style: [],
105
- barStyle: [],
106
- textStyle: [],
107
- containerStyle: [],
108
- violatingAttributes: [],
109
- });
110
- });
111
- it('should ignore approved inline styles', () => {
112
- const mockedCommentList = {
113
- styleCmts: [
114
- {
115
- loc: 10,
116
- comment: '@snowflake-guard/approved-inline-style attributes: padding',
117
- },
118
- ],
119
- };
120
- const source = `
121
- const styles = {
122
- button: {
123
- padding: 10,
124
- },
125
- };
126
-
127
- const App = () => (
128
- <>
129
- {/* @snowflake-guard/approved-inline-style attributes: padding */}
130
- <Button style={styles.button} />
131
- </>
132
- );
133
- `;
134
- const ast = (0, testUtils_1.parseTypeScript)(source);
135
- const result = (0, reportCustomStyleProperties_1.default)(ast, componentList, mockedCommentList);
136
- expect(result).toEqual({
137
- style: [],
138
- barStyle: [],
139
- textStyle: [],
140
- containerStyle: [],
141
- violatingAttributes: [],
142
- });
143
- });
144
- });
@@ -1,113 +0,0 @@
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 () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- const recast = __importStar(require("recast"));
40
- const reportInlineStyle_1 = __importDefault(require("../reportInlineStyle"));
41
- const constants_1 = require("../constants");
42
- const tsParser = __importStar(require("../../../parsers/typescript"));
43
- describe('reportInlineStyle', () => {
44
- it('should return line numbers and violating attributes for inline styles that violate the ruleset', () => {
45
- const code = `
46
- const MyComponent = () => (
47
- <Card style={{
48
- color: 'red',
49
- backgroundColor: 'blue'
50
- }}
51
- />
52
- );
53
- `;
54
- // Step 1: Parse the code to generate the AST
55
- const ast = recast.parse(code, { parser: tsParser });
56
- const attributes = [];
57
- // Step 2: Traverse the AST to extract relevant JSXAttributes (style)
58
- recast.visit(ast, {
59
- visitJSXAttribute(path) {
60
- const { node } = path;
61
- attributes.push(node);
62
- this.traverse(path);
63
- },
64
- });
65
- const componentName = 'Card';
66
- // Mock the RULESET_MAP for this test
67
- constants_1.MOBILE_RULESET_MAP.Card = ['color', 'backgroundColor'];
68
- // Step 3: Run the function with the dynamically extracted attributes
69
- const result = (0, reportInlineStyle_1.default)(ast, attributes, componentName);
70
- expect(result.locs.style).toEqual(3);
71
- expect(result.violatingAttributes).toEqual([
72
- {
73
- attributeName: 'color',
74
- attributeValue: "'red'",
75
- componentName: 'Card',
76
- inlineStyleProps: 'style',
77
- loc: 3,
78
- },
79
- {
80
- attributeName: 'backgroundColor',
81
- attributeValue: "'blue'",
82
- componentName: 'Card',
83
- inlineStyleProps: 'style',
84
- loc: 3,
85
- },
86
- ]);
87
- });
88
- it('should return empty arrays when no violations are found', () => {
89
- const code = `
90
- const MyComponent = () => (
91
- <Card style={{ margin: 10 }} />
92
- );
93
- `;
94
- // Step 1: Parse the code to generate the AST
95
- const ast = recast.parse(code, { parser: tsParser });
96
- const attributes = [];
97
- // Step 2: Traverse the AST to extract relevant JSXAttributes (style)
98
- recast.visit(ast, {
99
- visitJSXAttribute(path) {
100
- const { node } = path;
101
- attributes.push(node);
102
- this.traverse(path);
103
- },
104
- });
105
- const componentName = 'Card';
106
- // Mock the RULESET_MAP and SX_RULESET_MAP for this test
107
- constants_1.MOBILE_RULESET_MAP.Card = ['color'];
108
- const result = (0, reportInlineStyle_1.default)(ast, attributes, componentName);
109
- expect(result.locs.style).toEqual(undefined);
110
- expect(result.violatingAttributes).toEqual([]);
111
- expect(result.violatingAttributes).toEqual([]);
112
- });
113
- });
@@ -1,54 +0,0 @@
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 reportStyledComponents_1 = __importDefault(require("../reportStyledComponents"));
7
- const testUtils_1 = require("../testUtils");
8
- const componentList = {
9
- Button: 'Button',
10
- Alert: 'Alert',
11
- };
12
- const styledAliasName = 'styled';
13
- describe('reportStyledComponents', () => {
14
- it('should detect styled components with default component', () => {
15
- const source = `
16
- const StyledCard = styled(Button)\`
17
- padding: 10px;
18
- \`;
19
- `;
20
- const ast = (0, testUtils_1.parseTypeScript)(source);
21
- const locs = (0, reportStyledComponents_1.default)(ast, componentList, styledAliasName);
22
- expect(locs).toEqual([2]);
23
- });
24
- it('should detect styled components with compound component', () => {
25
- const source = `
26
- const StyledCardIcon = styled(Button.Icon)\`
27
- padding: 10px;
28
- \`;
29
- `;
30
- const ast = (0, testUtils_1.parseTypeScript)(source);
31
- const locs = (0, reportStyledComponents_1.default)(ast, componentList, styledAliasName);
32
- expect(locs).toEqual([2]);
33
- });
34
- it('should detect styled components with spread operator', () => {
35
- const source = `
36
- const { Icon } = Button;
37
- const StyledIcon = styled(Icon)\`
38
- color: red;
39
- \`;
40
- <StyledIcon />;
41
- `;
42
- const ast = (0, testUtils_1.parseTypeScript)(source);
43
- const locs = (0, reportStyledComponents_1.default)(ast, componentList, styledAliasName);
44
- expect(locs).toEqual([3]);
45
- });
46
- it('should not detect non-styled components', () => {
47
- const source = `
48
- const NotStyled = Button;
49
- `;
50
- const ast = (0, testUtils_1.parseTypeScript)(source);
51
- const locs = (0, reportStyledComponents_1.default)(ast, componentList, styledAliasName);
52
- expect(locs).toEqual([]);
53
- });
54
- });
@@ -1,106 +0,0 @@
1
- declare const HD_MOBILE_COMPONENTS: readonly ["Accordion", "Alert", "Attachment", "Avatar", "Badge", "BottomNavigation", "BottomSheet", "Box", "Button", "Calendar", "Carousel", "Card", "Chart", "Chip", "Collapse", "Checkbox", "ContentNavigator", "DatePicker", "Divider", "Drawer", "Empty", "Error", "FAB", "FormGroup", "HeroDesignProvider", "MapPin", "Icon", "Image", "List", "PinInput", "Progress", "Slider", "Spinner", "Swipeable", "Radio", "SectionHeading", "Select", "Skeleton", "Success", "Switch", "Tabs", "Tag", "TextInput", "TimePicker", "Toast", "Toolbar", "Typography", "Rate", "RefreshControl", "RichTextEditor", "PageControl", "Portal", "ScrollViewWithFAB", "SectionListWithFAB", "FlatListWithFAB", "Search", "FloatingIsland", "FilterTrigger", "SegmentedControl"];
2
- declare const MOBILE_RULESET_MAP: {
3
- Accordion: string[];
4
- Alert: (string | string[])[];
5
- Attachment: string[];
6
- Avatar: string[];
7
- 'Avatar.Stack': string[];
8
- Badge: string[];
9
- 'Badge.Status': string[];
10
- BottomNavigation: string[];
11
- BottomSheet: string[];
12
- 'BottomSheet.ScrollView': string[];
13
- Box: string[];
14
- Button: string[];
15
- 'Button.Icon': string[];
16
- 'Button.Utility': string[];
17
- Calendar: string[];
18
- Card: string[];
19
- 'Card.Data': string[];
20
- Carousel: string[];
21
- 'Carousel.Card': string[];
22
- Checkbox: string[];
23
- Chip: string[];
24
- 'Chart.Column': string[];
25
- 'Chart.Line': string[];
26
- 'Chart.SelectAction': string[];
27
- Collapse: string[];
28
- ContentNavigator: string[];
29
- DatePicker: string[];
30
- Divider: string[];
31
- Drawer: string[];
32
- 'Drawer.Dragable': string[];
33
- Empty: string[];
34
- Error: string[];
35
- FAB: string[];
36
- 'FAB.ActionGroup': string[];
37
- 'FAB.Pair': string[];
38
- FloatingIsland: string[];
39
- FilterTrigger: string[];
40
- Icon: string[];
41
- Illustration: string[];
42
- Image: string[];
43
- 'List.BasicItem': string[];
44
- 'List.Item': string[];
45
- MapPin: string[];
46
- PageControl: string[];
47
- PinInput: string[];
48
- Portal: string[];
49
- 'Progress.Bar': string[];
50
- 'Progress.Circle': string[];
51
- 'Progress.Step': string[];
52
- 'Radio.Group': string[];
53
- Rate: string[];
54
- RefreshControl: string[];
55
- RichTextEditor: string[];
56
- 'RichTextEditor.MentionList': string[];
57
- 'RichTextEditor.Toolbar': string[];
58
- ScrollViewWithFAB: string[];
59
- FlatListWithFAB: string[];
60
- SectionListWithFAB: string[];
61
- 'Search.OneLine': string[];
62
- 'Search.TwoLine': string[];
63
- 'Search.SuffixIcon': string[];
64
- SectionHeading: string[];
65
- Select: string[];
66
- 'Select.Multi': string[];
67
- Skeleton: string[];
68
- Slider: string[];
69
- Spinner: string[];
70
- Success: string[];
71
- Swipeable: string[];
72
- 'Swipeable.Action': string[];
73
- 'Swipeable.Content': string[];
74
- Switch: string[];
75
- 'Switch.Selector': string[];
76
- Tabs: string[];
77
- 'Tabs.Scroll': string[];
78
- Tag: string[];
79
- TextInput: string[];
80
- FormGroup: string[];
81
- SegmentedControl: string[];
82
- TimePicker: string[];
83
- 'Toast.Container': string[];
84
- 'Toast.Provider': string[];
85
- 'Toolbar.Group': string[];
86
- 'Toolbar.Item': string[];
87
- 'Toolbar.Message': string[];
88
- 'Typography.Title': string[];
89
- 'Typography.Body': string[];
90
- 'Typography.Caption': string[];
91
- 'Typography.Label': string[];
92
- };
93
- declare const BAR_STYLE_RULESET_MAP: {
94
- Tabs: string[];
95
- 'Tabs.Scroll': string[];
96
- };
97
- declare const CONTAINER_STYLE_RULESET_MAP: {
98
- Tabs: string[];
99
- 'Tabs.Scroll': string[];
100
- };
101
- declare const TEXT_STYLE_RULESET_MAP: {
102
- 'Toolbar.Message': string[];
103
- TextInput: string[];
104
- 'Search.OneLine': string[];
105
- };
106
- export { HD_MOBILE_COMPONENTS, MOBILE_RULESET_MAP, BAR_STYLE_RULESET_MAP, CONTAINER_STYLE_RULESET_MAP, TEXT_STYLE_RULESET_MAP, };