@hero-design/snowflake-guard 1.2.4-alpha.4 → 1.2.4

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/README.md CHANGED
@@ -10,8 +10,6 @@
10
10
  cp .env.example .env
11
11
  ```
12
12
 
13
- For React Native projects, include your repo name in the `MOBILE_REPO_NAMES` env.
14
-
15
13
  2. Set up [internal-tool-integrations service](https://github.com/Thinkei/internal-tool-integrations) for the bot to store report.
16
14
 
17
15
  - Replace `DB_HOST` with the host of the internal-tool-integrations service.
package/lib/src/index.js CHANGED
@@ -11,14 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
- const parseMobileSource_1 = __importDefault(require("./parseMobileSource"));
15
14
  const parseSource_1 = __importDefault(require("./parseSource"));
16
15
  const constants_1 = require("./reports/constants");
17
16
  const fetchGraphql_1 = __importDefault(require("./graphql/fetchGraphql"));
18
17
  const queryGenerators_1 = require("./graphql/queryGenerators");
19
18
  const getDiffLocs_1 = require("./utils/getDiffLocs");
20
19
  const TSX_REGEX = /\.tsx$/;
21
- const TSX_AND_JSX_REGEX = /\.(tsx|jsx|js)$/;
22
20
  const TEST_REGEX = /__tests__/;
23
21
  const SNOWFLAKE_COMMENTS = {
24
22
  style: 'Snowflake detected! A component is customized using inline styles. Make sure to not use [prohibited CSS properties](https://docs.google.com/spreadsheets/d/1Dj8vqLdFaf-CSaSVoYqyYZIkGqF6OoyP7K4G1_9L62U/edit?usp=sharing).',
@@ -26,7 +24,6 @@ const SNOWFLAKE_COMMENTS = {
26
24
  'styled-component': 'Please do not use styled-component to customize this component, use sx prop or inline style instead.',
27
25
  className: `Please make sure that this className is not used as a CSS classname for component customization purposes, use sx prop or inline style instead. In case this is none-css classname, please flag it with this comment \`${constants_1.APPROVED_CLASSNAME_COMMENT}\`.`,
28
26
  };
29
- const MOBILE_REPO_NAMES = JSON.parse(process.env.MOBILE_REPO_NAMES || '[]');
30
27
  const checkIfDetectedSnowflakesInDiff = (diffLocs, locToComment) => {
31
28
  const locIdx = diffLocs.findIndex(([start, end]) => {
32
29
  return locToComment >= start && locToComment <= end;
@@ -45,19 +42,16 @@ module.exports = (app) => {
45
42
  const prBranch = context.payload.pull_request.head.ref;
46
43
  // List all changed files
47
44
  const prFiles = yield context.octokit.pulls.listFiles(Object.assign(Object.assign({}, repoInfo), { pull_number: prNumber }));
48
- const isMobile = MOBILE_REPO_NAMES.includes(context.payload.repository.name);
49
- const parseSource = isMobile ? parseMobileSource_1.default : parseSource_1.default;
50
- const SOURCE_REGEX = isMobile ? TSX_AND_JSX_REGEX : TSX_REGEX;
51
- const sourceFiles = prFiles.data.filter((file) => SOURCE_REGEX.test(file.filename) &&
45
+ const tsxFiles = prFiles.data.filter((file) => TSX_REGEX.test(file.filename) &&
52
46
  !TEST_REGEX.test(file.filename) &&
53
47
  file.status !== 'removed');
54
48
  // Saving file patches to get diff locations
55
- const prFilePatches = sourceFiles.reduce((acc, file) => {
49
+ const prFilePatches = tsxFiles.reduce((acc, file) => {
56
50
  acc[file.filename] = file.patch || '';
57
51
  return acc;
58
52
  }, {});
59
53
  // Get file contents
60
- const prFileContentPromises = sourceFiles.map((file) => context.octokit.repos.getContent(Object.assign(Object.assign({}, repoInfo), { path: file.filename, ref: prBranch })));
54
+ const prFileContentPromises = tsxFiles.map((file) => context.octokit.repos.getContent(Object.assign(Object.assign({}, repoInfo), { path: file.filename, ref: prBranch })));
61
55
  const prFileContents = yield Promise.all(prFileContentPromises);
62
56
  const snowflakeComments = [];
63
57
  const approvedSnowflakeLocs = [];
@@ -71,7 +65,7 @@ module.exports = (app) => {
71
65
  // @ts-ignore
72
66
  file.data.content, 'base64').toString();
73
67
  // Parse file content to check for snowflakes
74
- const snowflakeReport = parseSource(stringContent);
68
+ const snowflakeReport = (0, parseSource_1.default)(stringContent);
75
69
  snowflakeReport.styleLocs.forEach((loc) => {
76
70
  if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
77
71
  snowflakeComments.push({
@@ -81,6 +75,15 @@ module.exports = (app) => {
81
75
  });
82
76
  }
83
77
  });
78
+ snowflakeReport.sxLocs.forEach((loc) => {
79
+ if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
80
+ snowflakeComments.push({
81
+ path: filePath,
82
+ body: SNOWFLAKE_COMMENTS['sx'],
83
+ line: loc,
84
+ });
85
+ }
86
+ });
84
87
  snowflakeReport.styledComponentLocs.forEach((loc) => {
85
88
  if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
86
89
  snowflakeComments.push({
@@ -90,31 +93,20 @@ module.exports = (app) => {
90
93
  });
91
94
  }
92
95
  });
96
+ snowflakeReport.classNameLocs.forEach((loc) => {
97
+ if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
98
+ snowflakeComments.push({
99
+ path: filePath,
100
+ body: SNOWFLAKE_COMMENTS['className'],
101
+ line: loc,
102
+ });
103
+ }
104
+ });
93
105
  snowflakeReport.approvedLocs.forEach((loc) => {
94
106
  if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
95
107
  approvedSnowflakeLocs.push(loc);
96
108
  }
97
109
  });
98
- if (!isMobile) {
99
- snowflakeReport.sxLocs.forEach((loc) => {
100
- if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
101
- snowflakeComments.push({
102
- path: filePath,
103
- body: SNOWFLAKE_COMMENTS['sx'],
104
- line: loc,
105
- });
106
- }
107
- });
108
- snowflakeReport.classNameLocs.forEach((loc) => {
109
- if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
110
- snowflakeComments.push({
111
- path: filePath,
112
- body: SNOWFLAKE_COMMENTS['className'],
113
- line: loc,
114
- });
115
- }
116
- });
117
- }
118
110
  }));
119
111
  // Saving report
120
112
  const snowflakeCount = snowflakeComments.length;
@@ -82,179 +82,4 @@ declare const MOBILE_RULESET_MAP: {
82
82
  'Typography.Caption': string[];
83
83
  'Typography.Label': string[];
84
84
  };
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': {
95
- [x: number]: string;
96
- length: number;
97
- toString(): string;
98
- toLocaleString(): string;
99
- pop(): string | undefined;
100
- push(...items: string[]): number;
101
- concat(...items: ConcatArray<string>[]): string[];
102
- concat(...items: (string | ConcatArray<string>)[]): string[];
103
- join(separator?: string | undefined): string;
104
- reverse(): string[];
105
- shift(): string | undefined;
106
- slice(start?: number | undefined, end?: number | undefined): string[];
107
- sort(compareFn?: ((a: string, b: string) => number) | undefined): string[];
108
- splice(start: number, deleteCount?: number | undefined): string[];
109
- splice(start: number, deleteCount: number, ...items: string[]): string[];
110
- unshift(...items: string[]): number;
111
- indexOf(searchElement: string, fromIndex?: number | undefined): number;
112
- lastIndexOf(searchElement: string, fromIndex?: number | undefined): number;
113
- every<S extends string>(predicate: (value: string, index: number, array: string[]) => value is S, thisArg?: any): this is S[];
114
- every(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
115
- some(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
116
- forEach(callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any): void;
117
- map<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): U[];
118
- filter<S_1 extends string>(predicate: (value: string, index: number, array: string[]) => value is S_1, thisArg?: any): S_1[];
119
- filter(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[];
120
- reduce(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
121
- reduce(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
122
- reduce<U_1>(callbackfn: (previousValue: U_1, currentValue: string, currentIndex: number, array: string[]) => U_1, initialValue: U_1): U_1;
123
- reduceRight(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
124
- reduceRight(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
125
- reduceRight<U_2>(callbackfn: (previousValue: U_2, currentValue: string, currentIndex: number, array: string[]) => U_2, initialValue: U_2): U_2;
126
- find<S_2 extends string>(predicate: (this: void, value: string, index: number, obj: string[]) => value is S_2, thisArg?: any): S_2 | undefined;
127
- find(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): string | undefined;
128
- findIndex(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): number;
129
- fill(value: string, start?: number | undefined, end?: number | undefined): string[];
130
- copyWithin(target: number, start: number, end?: number | undefined): string[];
131
- entries(): IterableIterator<[number, string]>;
132
- keys(): IterableIterator<number>;
133
- values(): IterableIterator<string>;
134
- includes(searchElement: string, fromIndex?: number | undefined): boolean;
135
- flatMap<U_3, This = undefined>(callback: (this: This, value: string, index: number, array: string[]) => U_3 | readonly U_3[], thisArg?: This | undefined): U_3[];
136
- flat<A, D extends number = 1>(this: A, depth?: D | undefined): FlatArray<A, D>[];
137
- [Symbol.iterator](): IterableIterator<string>;
138
- [Symbol.unscopables](): {
139
- copyWithin: boolean;
140
- entries: boolean;
141
- fill: boolean;
142
- find: boolean;
143
- findIndex: boolean;
144
- keys: boolean;
145
- values: boolean;
146
- };
147
- at(index: number): string | undefined;
148
- };
149
- TextInput: {
150
- [x: number]: string;
151
- length: number;
152
- toString(): string;
153
- toLocaleString(): string;
154
- pop(): string | undefined;
155
- push(...items: string[]): number;
156
- concat(...items: ConcatArray<string>[]): string[];
157
- concat(...items: (string | ConcatArray<string>)[]): string[];
158
- join(separator?: string | undefined): string;
159
- reverse(): string[];
160
- shift(): string | undefined;
161
- slice(start?: number | undefined, end?: number | undefined): string[];
162
- sort(compareFn?: ((a: string, b: string) => number) | undefined): string[];
163
- splice(start: number, deleteCount?: number | undefined): string[];
164
- splice(start: number, deleteCount: number, ...items: string[]): string[];
165
- unshift(...items: string[]): number;
166
- indexOf(searchElement: string, fromIndex?: number | undefined): number;
167
- lastIndexOf(searchElement: string, fromIndex?: number | undefined): number;
168
- every<S extends string>(predicate: (value: string, index: number, array: string[]) => value is S, thisArg?: any): this is S[];
169
- every(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
170
- some(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
171
- forEach(callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any): void;
172
- map<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): U[];
173
- filter<S_1 extends string>(predicate: (value: string, index: number, array: string[]) => value is S_1, thisArg?: any): S_1[];
174
- filter(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[];
175
- reduce(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
176
- reduce(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
177
- reduce<U_1>(callbackfn: (previousValue: U_1, currentValue: string, currentIndex: number, array: string[]) => U_1, initialValue: U_1): U_1;
178
- reduceRight(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
179
- reduceRight(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
180
- reduceRight<U_2>(callbackfn: (previousValue: U_2, currentValue: string, currentIndex: number, array: string[]) => U_2, initialValue: U_2): U_2;
181
- find<S_2 extends string>(predicate: (this: void, value: string, index: number, obj: string[]) => value is S_2, thisArg?: any): S_2 | undefined;
182
- find(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): string | undefined;
183
- findIndex(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): number;
184
- fill(value: string, start?: number | undefined, end?: number | undefined): string[];
185
- copyWithin(target: number, start: number, end?: number | undefined): string[];
186
- entries(): IterableIterator<[number, string]>;
187
- keys(): IterableIterator<number>;
188
- values(): IterableIterator<string>;
189
- includes(searchElement: string, fromIndex?: number | undefined): boolean;
190
- flatMap<U_3, This = undefined>(callback: (this: This, value: string, index: number, array: string[]) => U_3 | readonly U_3[], thisArg?: This | undefined): U_3[];
191
- flat<A, D extends number = 1>(this: A, depth?: D | undefined): FlatArray<A, D>[];
192
- [Symbol.iterator](): IterableIterator<string>;
193
- [Symbol.unscopables](): {
194
- copyWithin: boolean;
195
- entries: boolean;
196
- fill: boolean;
197
- find: boolean;
198
- findIndex: boolean;
199
- keys: boolean;
200
- values: boolean;
201
- };
202
- at(index: number): string | undefined;
203
- };
204
- 'Search.OneLine': {
205
- [x: number]: string;
206
- length: number;
207
- toString(): string;
208
- toLocaleString(): string;
209
- pop(): string | undefined;
210
- push(...items: string[]): number;
211
- concat(...items: ConcatArray<string>[]): string[];
212
- concat(...items: (string | ConcatArray<string>)[]): string[];
213
- join(separator?: string | undefined): string;
214
- reverse(): string[];
215
- shift(): string | undefined;
216
- slice(start?: number | undefined, end?: number | undefined): string[];
217
- sort(compareFn?: ((a: string, b: string) => number) | undefined): string[];
218
- splice(start: number, deleteCount?: number | undefined): string[];
219
- splice(start: number, deleteCount: number, ...items: string[]): string[];
220
- unshift(...items: string[]): number;
221
- indexOf(searchElement: string, fromIndex?: number | undefined): number;
222
- lastIndexOf(searchElement: string, fromIndex?: number | undefined): number;
223
- every<S extends string>(predicate: (value: string, index: number, array: string[]) => value is S, thisArg?: any): this is S[];
224
- every(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
225
- some(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): boolean;
226
- forEach(callbackfn: (value: string, index: number, array: string[]) => void, thisArg?: any): void;
227
- map<U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any): U[];
228
- filter<S_1 extends string>(predicate: (value: string, index: number, array: string[]) => value is S_1, thisArg?: any): S_1[];
229
- filter(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[];
230
- reduce(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
231
- reduce(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
232
- reduce<U_1>(callbackfn: (previousValue: U_1, currentValue: string, currentIndex: number, array: string[]) => U_1, initialValue: U_1): U_1;
233
- reduceRight(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string): string;
234
- reduceRight(callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: string[]) => string, initialValue: string): string;
235
- reduceRight<U_2>(callbackfn: (previousValue: U_2, currentValue: string, currentIndex: number, array: string[]) => U_2, initialValue: U_2): U_2;
236
- find<S_2 extends string>(predicate: (this: void, value: string, index: number, obj: string[]) => value is S_2, thisArg?: any): S_2 | undefined;
237
- find(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): string | undefined;
238
- findIndex(predicate: (value: string, index: number, obj: string[]) => unknown, thisArg?: any): number;
239
- fill(value: string, start?: number | undefined, end?: number | undefined): string[];
240
- copyWithin(target: number, start: number, end?: number | undefined): string[];
241
- entries(): IterableIterator<[number, string]>;
242
- keys(): IterableIterator<number>;
243
- values(): IterableIterator<string>;
244
- includes(searchElement: string, fromIndex?: number | undefined): boolean;
245
- flatMap<U_3, This = undefined>(callback: (this: This, value: string, index: number, array: string[]) => U_3 | readonly U_3[], thisArg?: This | undefined): U_3[];
246
- flat<A, D extends number = 1>(this: A, depth?: D | undefined): FlatArray<A, D>[];
247
- [Symbol.iterator](): IterableIterator<string>;
248
- [Symbol.unscopables](): {
249
- copyWithin: boolean;
250
- entries: boolean;
251
- fill: boolean;
252
- find: boolean;
253
- findIndex: boolean;
254
- keys: boolean;
255
- values: boolean;
256
- };
257
- at(index: number): string | undefined;
258
- };
259
- };
260
- export { HD_MOBILE_COMPONENTS, MOBILE_RULESET_MAP, BAR_STYLE_RULESET_MAP, CONTAINER_STYLE_RULESET_MAP, TEXT_STYLE_RULESET_MAP, };
85
+ export { HD_MOBILE_COMPONENTS, MOBILE_RULESET_MAP };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
3
+ exports.MOBILE_RULESET_MAP = exports.HD_MOBILE_COMPONENTS = void 0;
4
4
  const PADDING_ATTRS = [
5
5
  'padding',
6
6
  'paddingBottom',
@@ -347,83 +347,42 @@ const MOBILE_RULESET_MAP = {
347
347
  ...HEIGHT_ATTRS,
348
348
  ],
349
349
  'Toast.Container': [
350
- ...COMMON_PROHIBITED_ATTRS,
351
- ...WIDTH_ATTRS,
350
+ ...PADDING_ATTRS,
351
+ ...BORDER_ATTRS,
352
+ ...SHADOW_ATTRS,
353
+ ...TEXT_ATTRS,
352
354
  ...HEIGHT_ATTRS,
353
- ...MARGIN_ATTRS,
354
355
  ],
355
356
  '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: [
386
357
  ...PADDING_ATTRS,
387
358
  ...BORDER_ATTRS,
388
- ...TEXT_ATTRS,
389
359
  ...SHADOW_ATTRS,
390
- ...WIDTH_ATTRS,
360
+ ...TEXT_ATTRS,
391
361
  ...HEIGHT_ATTRS,
392
- ...MARGIN_ATTRS,
393
362
  ],
394
- 'Tabs.Scroll': [
363
+ 'Toolbar.Group': [
395
364
  ...PADDING_ATTRS,
396
365
  ...BORDER_ATTRS,
397
- ...TEXT_ATTRS,
398
366
  ...SHADOW_ATTRS,
399
- ...WIDTH_ATTRS,
367
+ ...TEXT_ATTRS,
400
368
  ...HEIGHT_ATTRS,
401
- ...MARGIN_ATTRS,
402
369
  ],
403
- };
404
- exports.BAR_STYLE_RULESET_MAP = BAR_STYLE_RULESET_MAP;
405
- const CONTAINER_STYLE_RULESET_MAP = {
406
- Tabs: [
370
+ 'Toolbar.Item': [
371
+ ...PADDING_ATTRS,
407
372
  ...BORDER_ATTRS,
408
- ...TEXT_ATTRS,
409
373
  ...SHADOW_ATTRS,
410
- ...WIDTH_ATTRS,
374
+ ...TEXT_ATTRS,
411
375
  ...HEIGHT_ATTRS,
412
- ...MARGIN_ATTRS,
413
376
  ],
414
- 'Tabs.Scroll': [
377
+ 'Toolbar.Message': [
378
+ ...PADDING_ATTRS,
415
379
  ...BORDER_ATTRS,
416
- ...TEXT_ATTRS,
417
380
  ...SHADOW_ATTRS,
418
- ...WIDTH_ATTRS,
381
+ ...TEXT_ATTRS,
419
382
  ...HEIGHT_ATTRS,
420
- ...MARGIN_ATTRS,
421
383
  ],
384
+ 'Typography.Body': [...COMMON_PROHIBITED_ATTRS, ...HEIGHT_ATTRS],
385
+ 'Typography.Caption': [...COMMON_PROHIBITED_ATTRS, ...HEIGHT_ATTRS],
386
+ 'Typography.Label': [...COMMON_PROHIBITED_ATTRS, ...HEIGHT_ATTRS],
422
387
  };
423
- exports.CONTAINER_STYLE_RULESET_MAP = CONTAINER_STYLE_RULESET_MAP;
424
- const TEXT_STYLE_RULESET_MAP = {
425
- 'Toolbar.Message': Object.assign(Object.assign(Object.assign(Object.assign({}, COMMON_PROHIBITED_ATTRS), WIDTH_ATTRS), HEIGHT_ATTRS), MARGIN_ATTRS),
426
- TextInput: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, PADDING_ATTRS), BORDER_ATTRS), SHADOW_ATTRS), TEXT_ATTRS), HEIGHT_ATTRS),
427
- 'Search.OneLine': Object.assign(Object.assign(Object.assign(Object.assign({}, COMMON_PROHIBITED_ATTRS), WIDTH_ATTRS), HEIGHT_ATTRS), MARGIN_ATTRS),
428
- };
429
- exports.TEXT_STYLE_RULESET_MAP = TEXT_STYLE_RULESET_MAP;
388
+ exports.MOBILE_RULESET_MAP = MOBILE_RULESET_MAP;
@@ -1,6 +1,6 @@
1
1
  import * as recast from 'recast';
2
2
  import type { MobileComponentName } from './types';
3
3
  declare const reportStyledComponents: (ast: recast.types.ASTNode, componentList: {
4
- [k: string]: "Accordion" | "Alert" | "Attachment" | "Avatar" | "Badge" | "BottomNavigation" | "BottomSheet" | "Box" | "Button" | "Calendar" | "Carousel" | "Card" | "Chip" | "Collapse" | "Checkbox" | "ContentNavigator" | "DatePicker" | "Divider" | "Drawer" | "Empty" | "Error" | "FAB" | "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";
4
+ [k: string]: "Alert" | "Badge" | "Button" | "Card" | "Carousel" | "Checkbox" | "Chip" | "Collapse" | "DatePicker" | "Divider" | "Empty" | "Icon" | "Portal" | "Progress" | "Radio" | "Rate" | "Select" | "Slider" | "Spinner" | "Switch" | "Tabs" | "Tag" | "TimePicker" | "Typography" | "Error" | "Image" | "Accordion" | "Attachment" | "Avatar" | "BottomNavigation" | "BottomSheet" | "Box" | "Calendar" | "ContentNavigator" | "Drawer" | "FAB" | "HeroDesignProvider" | "MapPin" | "List" | "PinInput" | "Swipeable" | "SectionHeading" | "Skeleton" | "Success" | "TextInput" | "Toast" | "Toolbar" | "RefreshControl" | "RichTextEditor" | "PageControl" | "ScrollViewWithFAB" | "SectionListWithFAB" | "FlatListWithFAB" | "Search" | "FloatingIsland";
5
5
  }, styledAliasName: string) => number[];
6
6
  export default reportStyledComponents;
@@ -2,7 +2,7 @@ import * as recast from 'recast';
2
2
  import { AdditionalProp, InlineStyleProps } from './reportInlineStyle';
3
3
  import type { ComponentName, CompoundComponentName } from './types';
4
4
  declare const reportCustomProperties: (ast: recast.types.ASTNode, componentList: {
5
- [k: string]: "Alert" | "Badge" | "Button" | "Carousel" | "Card" | "Chip" | "Collapse" | "Checkbox" | "DatePicker" | "Divider" | "Empty" | "Icon" | "Progress" | "Slider" | "Spinner" | "Radio" | "Select" | "Switch" | "Tabs" | "Tag" | "TimePicker" | "Typography" | "Rate" | "Portal" | "Banner" | "Breadcrumb" | "Chart" | "Comment" | "ContextPanel" | "Dropdown" | "File" | "Filters" | "Form" | "Grid" | "InPageNavigation" | "Input" | "MediaQuery" | "Menu" | "Modal" | "Notification" | "PageHeader" | "Pagination" | "Portlet" | "Result" | "SelectButton" | "SideBar" | "Statistic" | "Steps" | "Table" | "TagInput" | "Timeline" | "Tooltip" | "Widget";
5
+ [k: string]: "Alert" | "Badge" | "Banner" | "Breadcrumb" | "Button" | "Card" | "Carousel" | "Chart" | "Checkbox" | "Chip" | "Collapse" | "Comment" | "ContextPanel" | "DatePicker" | "Divider" | "Dropdown" | "Empty" | "File" | "Filters" | "Form" | "Grid" | "Icon" | "InPageNavigation" | "Input" | "MediaQuery" | "Menu" | "Modal" | "Notification" | "PageHeader" | "Pagination" | "Portal" | "Portlet" | "Progress" | "Radio" | "Rate" | "Result" | "Select" | "SelectButton" | "SideBar" | "Slider" | "Spinner" | "Statistic" | "Steps" | "Switch" | "Table" | "Tabs" | "Tag" | "TagInput" | "TimePicker" | "Timeline" | "Tooltip" | "Typography" | "Widget";
6
6
  }, commentList: {
7
7
  classNameCmts: number[];
8
8
  styleCmts: {
@@ -1,6 +1,6 @@
1
1
  import * as recast from 'recast';
2
2
  import type { ComponentName } from './types';
3
3
  declare const reportStyledComponents: (ast: recast.types.ASTNode, componentList: {
4
- [k: string]: "Alert" | "Badge" | "Button" | "Carousel" | "Card" | "Chip" | "Collapse" | "Checkbox" | "DatePicker" | "Divider" | "Empty" | "Icon" | "Progress" | "Slider" | "Spinner" | "Radio" | "Select" | "Switch" | "Tabs" | "Tag" | "TimePicker" | "Typography" | "Rate" | "Portal" | "Banner" | "Breadcrumb" | "Chart" | "Comment" | "ContextPanel" | "Dropdown" | "File" | "Filters" | "Form" | "Grid" | "InPageNavigation" | "Input" | "MediaQuery" | "Menu" | "Modal" | "Notification" | "PageHeader" | "Pagination" | "Portlet" | "Result" | "SelectButton" | "SideBar" | "Statistic" | "Steps" | "Table" | "TagInput" | "Timeline" | "Tooltip" | "Widget";
4
+ [k: string]: "Alert" | "Badge" | "Banner" | "Breadcrumb" | "Button" | "Card" | "Carousel" | "Chart" | "Checkbox" | "Chip" | "Collapse" | "Comment" | "ContextPanel" | "DatePicker" | "Divider" | "Dropdown" | "Empty" | "File" | "Filters" | "Form" | "Grid" | "Icon" | "InPageNavigation" | "Input" | "MediaQuery" | "Menu" | "Modal" | "Notification" | "PageHeader" | "Pagination" | "Portal" | "Portlet" | "Progress" | "Radio" | "Rate" | "Result" | "Select" | "SelectButton" | "SideBar" | "Slider" | "Spinner" | "Statistic" | "Steps" | "Switch" | "Table" | "Tabs" | "Tag" | "TagInput" | "TimePicker" | "Timeline" | "Tooltip" | "Typography" | "Widget";
5
5
  }, styledAliasName: string) => number[];
6
6
  export default reportStyledComponents;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hero-design/snowflake-guard",
3
- "version": "1.2.4-alpha.4",
3
+ "version": "1.2.4",
4
4
  "description": "A hero-design bot detecting snowflake usage",
5
5
  "author": "Hau Dao",
6
6
  "license": "ISC",
@@ -1,15 +0,0 @@
1
- import { InlineStyleProps } from './reports/mobile/reportInlineStyle';
2
- import type { CompoundMobileComponentName } from './reports/mobile/types';
3
- declare const parseMobileSource: (source: string) => {
4
- styleLocs: number[];
5
- styledComponentLocs: number[];
6
- approvedLocs: number[];
7
- violatingAttributes: {
8
- attributeName: string;
9
- attributeValue: string | null;
10
- inlineStyleProps: InlineStyleProps;
11
- componentName: CompoundMobileComponentName;
12
- loc: number | undefined;
13
- }[];
14
- };
15
- export default parseMobileSource;
@@ -1,118 +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 (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 flowParser = __importStar(require("./parsers/flow"));
31
- const tsParser = __importStar(require("./parsers/typescript"));
32
- const constants_1 = require("./reports/mobile/constants");
33
- const constants_2 = require("./reports/constants");
34
- const reportCustomStyleProperties_1 = __importDefault(require("./reports/mobile/reportCustomStyleProperties"));
35
- const reportStyledComponents_1 = __importDefault(require("./reports/mobile/reportStyledComponents"));
36
- const parseMobileSource = (source) => {
37
- let hasHeroDesignImport = false;
38
- let hasStyledComponentsImport = false;
39
- const componentList = {};
40
- let styledAliasName = 'styled';
41
- let styledComponentLocs = [];
42
- let styleLocs = [];
43
- let violatingAttributes = [];
44
- const approvedInlineStyleCmts = [];
45
- const approvedStyledComponentLocs = [];
46
- const ast = recast.parse(source, {
47
- parser: source.includes('@flow') ? flowParser : tsParser,
48
- });
49
- recast.visit(ast, {
50
- visitImportDeclaration(path) {
51
- this.traverse(path);
52
- const importedFrom = path.value.source.value;
53
- // Check if file imports components from '@hero-design/rn'
54
- if (importedFrom === '@hero-design/rn') {
55
- recast.visit(path.node, {
56
- visitImportSpecifier(importPath) {
57
- this.traverse(importPath);
58
- if (constants_1.HD_MOBILE_COMPONENTS.includes(importPath.value.imported.name)) {
59
- componentList[importPath.value.local.name] =
60
- importPath.value.imported.name;
61
- hasHeroDesignImport = true;
62
- }
63
- },
64
- });
65
- }
66
- // Check if file imports from '@emotion/native'
67
- if (importedFrom === '@emotion/native') {
68
- recast.visit(path.node, {
69
- visitImportDefaultSpecifier(importPath) {
70
- this.traverse(importPath);
71
- styledAliasName = importPath.value.local.name;
72
- hasStyledComponentsImport = true;
73
- },
74
- });
75
- }
76
- },
77
- visitComment(path) {
78
- this.traverse(path);
79
- const comment = path.value.value;
80
- if (comment
81
- .toLowerCase()
82
- .includes(constants_2.APPROVED_INLINE_STYLE_COMMENT.toLowerCase())) {
83
- approvedInlineStyleCmts.push({
84
- loc: path.value.loc.start.line,
85
- comment,
86
- });
87
- }
88
- if (comment
89
- .toLowerCase()
90
- .includes(constants_2.APPROVED_STYLED_COMPONENTS_COMMENT.toLowerCase())) {
91
- approvedStyledComponentLocs.push(path.value.loc.start.line);
92
- }
93
- },
94
- });
95
- const isNotApprovedStyledComponentSnowflakes = (loc) => !approvedStyledComponentLocs.includes(loc - 1);
96
- if (hasHeroDesignImport) {
97
- // Case 1: Using style object to customise components
98
- const customPropLocs = (0, reportCustomStyleProperties_1.default)(ast, componentList, {
99
- styleCmts: approvedInlineStyleCmts,
100
- });
101
- styleLocs = customPropLocs.style;
102
- // Case 2: Using styled-components to customise components
103
- if (hasStyledComponentsImport) {
104
- styledComponentLocs = (0, reportStyledComponents_1.default)(ast, componentList, styledAliasName).filter(isNotApprovedStyledComponentSnowflakes);
105
- }
106
- violatingAttributes = customPropLocs.violatingAttributes;
107
- }
108
- return {
109
- styleLocs,
110
- styledComponentLocs,
111
- approvedLocs: [
112
- ...approvedInlineStyleCmts.map((cmt) => cmt.loc),
113
- ...approvedStyledComponentLocs,
114
- ],
115
- violatingAttributes,
116
- };
117
- };
118
- exports.default = parseMobileSource;
@@ -1,3 +0,0 @@
1
- import * as babelParser from '@babel/parser';
2
- import { Overrides } from 'recast/parsers/_babel_options';
3
- export declare const parse: (source: string, options?: Overrides) => babelParser.ParseResult<import("@babel/types").File>;
@@ -1,37 +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 (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.parse = void 0;
30
- const babelParser = __importStar(require("@babel/parser"));
31
- const _babel_options_1 = __importDefault(require("recast/parsers/_babel_options"));
32
- const parse = (source, options) => {
33
- const babelOptions = (0, _babel_options_1.default)(options);
34
- babelOptions.plugins.push('jsx', 'flow');
35
- return babelParser.parse(source, babelOptions);
36
- };
37
- exports.parse = parse;