@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.
- package/package.json +2 -2
- package/lib/src/__tests__/parseMobileSource.spec.d.ts +0 -1
- package/lib/src/__tests__/parseMobileSource.spec.js +0 -417
- package/lib/src/__tests__/parseSource.spec.d.ts +0 -1
- package/lib/src/__tests__/parseSource.spec.js +0 -207
- package/lib/src/graphql/__tests__/fetchGrapql.spec.d.ts +0 -1
- package/lib/src/graphql/__tests__/fetchGrapql.spec.js +0 -33
- package/lib/src/graphql/__tests__/queryGenerators.spec.d.ts +0 -1
- package/lib/src/graphql/__tests__/queryGenerators.spec.js +0 -82
- package/lib/src/graphql/fetchGraphql.d.ts +0 -2
- package/lib/src/graphql/fetchGraphql.js +0 -23
- package/lib/src/graphql/queryGenerators.d.ts +0 -18
- package/lib/src/graphql/queryGenerators.js +0 -61
- package/lib/src/graphql/types.d.ts +0 -18
- package/lib/src/graphql/types.js +0 -2
- package/lib/src/index.d.ts +0 -3
- package/lib/src/index.js +0 -175
- package/lib/src/parseMobileSource.d.ts +0 -15
- package/lib/src/parseMobileSource.js +0 -135
- package/lib/src/parseSource.d.ts +0 -17
- package/lib/src/parseSource.js +0 -138
- package/lib/src/parsers/flow.d.ts +0 -3
- package/lib/src/parsers/flow.js +0 -47
- package/lib/src/parsers/typescript.d.ts +0 -3
- package/lib/src/parsers/typescript.js +0 -47
- package/lib/src/reports/__tests__/reportInlineStyle.spec.d.ts +0 -1
- package/lib/src/reports/__tests__/reportInlineStyle.spec.js +0 -143
- package/lib/src/reports/constants.d.ts +0 -233
- package/lib/src/reports/constants.js +0 -917
- package/lib/src/reports/mobile/__tests__/reportCustomStyleProperties.spec.d.ts +0 -1
- package/lib/src/reports/mobile/__tests__/reportCustomStyleProperties.spec.js +0 -144
- package/lib/src/reports/mobile/__tests__/reportInlineStyle.spec.d.ts +0 -1
- package/lib/src/reports/mobile/__tests__/reportInlineStyle.spec.js +0 -113
- package/lib/src/reports/mobile/__tests__/reportStyledComponents.spec.d.ts +0 -1
- package/lib/src/reports/mobile/__tests__/reportStyledComponents.spec.js +0 -54
- package/lib/src/reports/mobile/constants.d.ts +0 -106
- package/lib/src/reports/mobile/constants.js +0 -470
- package/lib/src/reports/mobile/reportCustomStyleProperties.d.ts +0 -24
- package/lib/src/reports/mobile/reportCustomStyleProperties.js +0 -193
- package/lib/src/reports/mobile/reportInlineStyle.d.ts +0 -20
- package/lib/src/reports/mobile/reportInlineStyle.js +0 -223
- package/lib/src/reports/mobile/reportStyledComponents.d.ts +0 -6
- package/lib/src/reports/mobile/reportStyledComponents.js +0 -105
- package/lib/src/reports/mobile/testUtils.d.ts +0 -1
- package/lib/src/reports/mobile/testUtils.js +0 -42
- package/lib/src/reports/mobile/types.d.ts +0 -3
- package/lib/src/reports/mobile/types.js +0 -2
- package/lib/src/reports/reportClassName.d.ts +0 -3
- package/lib/src/reports/reportClassName.js +0 -12
- package/lib/src/reports/reportCustomStyleProperties.d.ts +0 -25
- package/lib/src/reports/reportCustomStyleProperties.js +0 -185
- package/lib/src/reports/reportInlineStyle.d.ts +0 -23
- package/lib/src/reports/reportInlineStyle.js +0 -238
- package/lib/src/reports/reportStyledComponents.d.ts +0 -6
- package/lib/src/reports/reportStyledComponents.js +0 -105
- package/lib/src/reports/types.d.ts +0 -3
- package/lib/src/reports/types.js +0 -2
- package/lib/src/utils/__tests__/getDiffLocs.spec.d.ts +0 -1
- package/lib/src/utils/__tests__/getDiffLocs.spec.js +0 -43
- package/lib/src/utils/getDiffLocs.d.ts +0 -3
- package/lib/src/utils/getDiffLocs.js +0 -40
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as recast from 'recast';
|
|
2
|
-
import type { CompoundMobileComponentName } from './types';
|
|
3
|
-
export type InlineStyleProps = 'style' | 'barStyle' | 'containerStyle' | 'textStyle';
|
|
4
|
-
export type ViolatingAttribute = {
|
|
5
|
-
attributeName: string;
|
|
6
|
-
attributeValue: string | null;
|
|
7
|
-
inlineStyleProps: InlineStyleProps;
|
|
8
|
-
componentName: CompoundMobileComponentName;
|
|
9
|
-
loc: number | undefined;
|
|
10
|
-
};
|
|
11
|
-
declare const reportInlineStyle: (ast: recast.types.ASTNode, attributes: recast.types.namedTypes.JSXAttribute[], componentName: CompoundMobileComponentName) => {
|
|
12
|
-
locs: {
|
|
13
|
-
style?: number;
|
|
14
|
-
barStyle?: number;
|
|
15
|
-
containerStyle?: number;
|
|
16
|
-
textStyle?: number;
|
|
17
|
-
};
|
|
18
|
-
violatingAttributes: ViolatingAttribute[];
|
|
19
|
-
};
|
|
20
|
-
export default reportInlineStyle;
|
|
@@ -1,223 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const recast = __importStar(require("recast"));
|
|
37
|
-
const constants_1 = require("./constants");
|
|
38
|
-
const BLACKLIST_PROPERTIES = {
|
|
39
|
-
style: constants_1.MOBILE_RULESET_MAP,
|
|
40
|
-
barStyle: constants_1.BAR_STYLE_RULESET_MAP,
|
|
41
|
-
containerStyle: constants_1.CONTAINER_STYLE_RULESET_MAP,
|
|
42
|
-
textStyle: constants_1.TEXT_STYLE_RULESET_MAP,
|
|
43
|
-
};
|
|
44
|
-
const INLINE_STYLE_PROPERTIES = [
|
|
45
|
-
'style',
|
|
46
|
-
'barStyle',
|
|
47
|
-
'containerStyle',
|
|
48
|
-
'textStyle',
|
|
49
|
-
];
|
|
50
|
-
const addViolatingAttribute = (prop, styleObjName, componentName, loc, violatingAttributes) => {
|
|
51
|
-
if (prop.key.type !== 'Identifier') {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
violatingAttributes.push({
|
|
55
|
-
attributeName: prop.key.name,
|
|
56
|
-
attributeValue: recast.print(prop.value).code,
|
|
57
|
-
inlineStyleProps: styleObjName,
|
|
58
|
-
componentName,
|
|
59
|
-
loc,
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
const reportInlineStyle = (ast, attributes, componentName) => {
|
|
63
|
-
const locs = {};
|
|
64
|
-
const violatingAttributes = [];
|
|
65
|
-
let hasCustomStyle = false;
|
|
66
|
-
let styleObjName;
|
|
67
|
-
attributes.forEach((attr) => {
|
|
68
|
-
var _a;
|
|
69
|
-
if (attr.type !== 'JSXAttribute') {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (typeof attr.name.name !== 'string') {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (((_a = attr.value) === null || _a === void 0 ? void 0 : _a.type) !== 'JSXExpressionContainer') {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
if (INLINE_STYLE_PROPERTIES.includes(attr.name.name)) {
|
|
79
|
-
styleObjName = attr.name.name;
|
|
80
|
-
const PROHIBITED_PROPERTIES = BLACKLIST_PROPERTIES[styleObjName][componentName] || [];
|
|
81
|
-
const { expression } = attr.value;
|
|
82
|
-
if (expression.type === 'ObjectExpression') {
|
|
83
|
-
expression.properties.forEach((prop) => {
|
|
84
|
-
var _a;
|
|
85
|
-
// Case 1: Use direct object, e.g. <Button style={{ backgroundColor: 'red' }} />
|
|
86
|
-
if (prop.type === 'ObjectProperty' &&
|
|
87
|
-
prop.key.type === 'Identifier' &&
|
|
88
|
-
PROHIBITED_PROPERTIES.includes(prop.key.name)) {
|
|
89
|
-
hasCustomStyle = true;
|
|
90
|
-
addViolatingAttribute(prop, styleObjName, componentName, (_a = attr.loc) === null || _a === void 0 ? void 0 : _a.start.line, violatingAttributes);
|
|
91
|
-
}
|
|
92
|
-
// Case 2: Use spread operator, e.g. <Button style={{ ...customStyle }} />
|
|
93
|
-
if (prop.type === 'SpreadElement' &&
|
|
94
|
-
prop.argument.type === 'Identifier') {
|
|
95
|
-
const variableName = prop.argument.name;
|
|
96
|
-
recast.visit(ast, {
|
|
97
|
-
visitVariableDeclaration(path) {
|
|
98
|
-
var _a;
|
|
99
|
-
this.traverse(path);
|
|
100
|
-
const declaration = path.value
|
|
101
|
-
.declarations[0];
|
|
102
|
-
if (declaration.id.type === 'Identifier' &&
|
|
103
|
-
declaration.id.name === variableName &&
|
|
104
|
-
((_a = declaration.init) === null || _a === void 0 ? void 0 : _a.type) === 'ObjectExpression') {
|
|
105
|
-
declaration.init.properties.forEach((deProp) => {
|
|
106
|
-
var _a;
|
|
107
|
-
if (deProp.type === 'ObjectProperty' &&
|
|
108
|
-
deProp.key.type === 'Identifier' &&
|
|
109
|
-
PROHIBITED_PROPERTIES.includes(deProp.key.name)) {
|
|
110
|
-
hasCustomStyle = true;
|
|
111
|
-
addViolatingAttribute(deProp, styleObjName, componentName, (_a = attr.loc) === null || _a === void 0 ? void 0 : _a.start.line, violatingAttributes);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
// Case 3: Use spread operator with variable's property, e.g. <Button style={{ ...customStyle.button }} />
|
|
119
|
-
if (prop.type === 'SpreadElement' &&
|
|
120
|
-
prop.argument.type === 'MemberExpression' &&
|
|
121
|
-
prop.argument.object.type === 'Identifier' &&
|
|
122
|
-
prop.argument.property.type === 'Identifier') {
|
|
123
|
-
const variableName = prop.argument.object.name;
|
|
124
|
-
const propName = prop.argument.property.name;
|
|
125
|
-
recast.visit(ast, {
|
|
126
|
-
visitVariableDeclaration(path) {
|
|
127
|
-
var _a;
|
|
128
|
-
this.traverse(path);
|
|
129
|
-
const declaration = path.value
|
|
130
|
-
.declarations[0];
|
|
131
|
-
if (declaration.id.type === 'Identifier' &&
|
|
132
|
-
declaration.id.name === variableName &&
|
|
133
|
-
((_a = declaration.init) === null || _a === void 0 ? void 0 : _a.type) === 'ObjectExpression') {
|
|
134
|
-
declaration.init.properties.forEach((deProp) => {
|
|
135
|
-
if (deProp.type === 'ObjectProperty' &&
|
|
136
|
-
deProp.key.type === 'Identifier' &&
|
|
137
|
-
deProp.key.name === propName &&
|
|
138
|
-
deProp.value.type === 'ObjectExpression') {
|
|
139
|
-
deProp.value.properties.forEach((p) => {
|
|
140
|
-
var _a;
|
|
141
|
-
if (p.type === 'ObjectProperty' &&
|
|
142
|
-
p.key.type === 'Identifier' &&
|
|
143
|
-
PROHIBITED_PROPERTIES.includes(p.key.name)) {
|
|
144
|
-
hasCustomStyle = true;
|
|
145
|
-
addViolatingAttribute(p, styleObjName, componentName, (_a = attr.loc) === null || _a === void 0 ? void 0 : _a.start.line, violatingAttributes);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
// Case 4: Use variable, e.g. <Button style={customStyle} />
|
|
157
|
-
if (expression.type === 'Identifier') {
|
|
158
|
-
const variableName = expression.name;
|
|
159
|
-
recast.visit(ast, {
|
|
160
|
-
visitVariableDeclaration(path) {
|
|
161
|
-
var _a;
|
|
162
|
-
this.traverse(path);
|
|
163
|
-
const declaration = path.value
|
|
164
|
-
.declarations[0];
|
|
165
|
-
if (declaration.id.type === 'Identifier' &&
|
|
166
|
-
declaration.id.name === variableName &&
|
|
167
|
-
((_a = declaration.init) === null || _a === void 0 ? void 0 : _a.type) === 'ObjectExpression') {
|
|
168
|
-
declaration.init.properties.forEach((prop) => {
|
|
169
|
-
var _a;
|
|
170
|
-
if (prop.type === 'ObjectProperty' &&
|
|
171
|
-
prop.key.type === 'Identifier' &&
|
|
172
|
-
PROHIBITED_PROPERTIES.includes(prop.key.name)) {
|
|
173
|
-
hasCustomStyle = true;
|
|
174
|
-
addViolatingAttribute(prop, styleObjName, componentName, (_a = attr.loc) === null || _a === void 0 ? void 0 : _a.start.line, violatingAttributes);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
// Case 5: Use variable's property, e.g. <Button style={customStyle.button} />
|
|
182
|
-
if (expression.type === 'MemberExpression' &&
|
|
183
|
-
expression.object.type === 'Identifier' &&
|
|
184
|
-
expression.property.type === 'Identifier') {
|
|
185
|
-
const objectName = expression.object.name;
|
|
186
|
-
const propName = expression.property.name;
|
|
187
|
-
recast.visit(ast, {
|
|
188
|
-
visitVariableDeclaration(path) {
|
|
189
|
-
var _a;
|
|
190
|
-
this.traverse(path);
|
|
191
|
-
const declaration = path.value
|
|
192
|
-
.declarations[0];
|
|
193
|
-
if (declaration.id.type === 'Identifier' &&
|
|
194
|
-
declaration.id.name === objectName &&
|
|
195
|
-
((_a = declaration.init) === null || _a === void 0 ? void 0 : _a.type) === 'ObjectExpression') {
|
|
196
|
-
declaration.init.properties.forEach((prop) => {
|
|
197
|
-
if (prop.type === 'ObjectProperty' &&
|
|
198
|
-
prop.key.type === 'Identifier' &&
|
|
199
|
-
prop.key.name === propName &&
|
|
200
|
-
prop.value.type === 'ObjectExpression') {
|
|
201
|
-
prop.value.properties.forEach((p) => {
|
|
202
|
-
var _a;
|
|
203
|
-
if (p.type === 'ObjectProperty' &&
|
|
204
|
-
p.key.type === 'Identifier' &&
|
|
205
|
-
PROHIBITED_PROPERTIES.includes(p.key.name)) {
|
|
206
|
-
hasCustomStyle = true;
|
|
207
|
-
addViolatingAttribute(p, styleObjName, componentName, (_a = attr.loc) === null || _a === void 0 ? void 0 : _a.start.line, violatingAttributes);
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
},
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
if (hasCustomStyle && attr.loc) {
|
|
217
|
-
locs[styleObjName] = attr.loc.start.line;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
return { locs, violatingAttributes };
|
|
222
|
-
};
|
|
223
|
-
exports.default = reportInlineStyle;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import * as recast from 'recast';
|
|
2
|
-
import type { MobileComponentName } from './types';
|
|
3
|
-
declare const reportStyledComponents: (ast: recast.types.ASTNode, componentList: {
|
|
4
|
-
[k: string]: MobileComponentName;
|
|
5
|
-
}, styledAliasName: string) => number[];
|
|
6
|
-
export default reportStyledComponents;
|
|
@@ -1,105 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const recast = __importStar(require("recast"));
|
|
37
|
-
const reportStyledComponents = (ast, componentList, styledAliasName) => {
|
|
38
|
-
const locs = [];
|
|
39
|
-
const localComponentList = Object.keys(componentList);
|
|
40
|
-
recast.visit(ast, {
|
|
41
|
-
visitVariableDeclaration(path) {
|
|
42
|
-
this.traverse(path);
|
|
43
|
-
const declaration = path.value
|
|
44
|
-
.declarations[0];
|
|
45
|
-
if (declaration.init &&
|
|
46
|
-
declaration.init.type === 'TaggedTemplateExpression') {
|
|
47
|
-
const { tag } = declaration.init;
|
|
48
|
-
if (tag.type === 'CallExpression' &&
|
|
49
|
-
tag.callee.type === 'Identifier' &&
|
|
50
|
-
tag.callee.name === styledAliasName) {
|
|
51
|
-
const arg = tag.arguments[0];
|
|
52
|
-
// Case 1: Custom default component, e.g. styled(Button)
|
|
53
|
-
if (arg.type === 'Identifier' &&
|
|
54
|
-
localComponentList.includes(arg.name) &&
|
|
55
|
-
tag.loc) {
|
|
56
|
-
locs.push(tag.loc.start.line);
|
|
57
|
-
}
|
|
58
|
-
// Case 2: Custom compound component, e.g. styled(Button.Icon)
|
|
59
|
-
if (arg.type === 'MemberExpression' &&
|
|
60
|
-
arg.object.type === 'Identifier' &&
|
|
61
|
-
localComponentList.includes(arg.object.name) &&
|
|
62
|
-
tag.loc) {
|
|
63
|
-
locs.push(tag.loc.start.line);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// Case 3: Custom compound component with spead operator. e.g. const { Icon } = Button, then styled(Icon)
|
|
68
|
-
if (declaration.init &&
|
|
69
|
-
declaration.init.type === 'Identifier' &&
|
|
70
|
-
localComponentList.includes(declaration.init.name)) {
|
|
71
|
-
const { id } = declaration;
|
|
72
|
-
if (id.type === 'ObjectPattern') {
|
|
73
|
-
const compoundComponentNames = id.properties
|
|
74
|
-
.map((prop) => prop.type === 'ObjectProperty' && prop.key.type === 'Identifier'
|
|
75
|
-
? prop.key.name
|
|
76
|
-
: null)
|
|
77
|
-
.filter((name) => name !== null);
|
|
78
|
-
recast.visit(ast, {
|
|
79
|
-
visitVariableDeclaration(spreadPath) {
|
|
80
|
-
this.traverse(spreadPath);
|
|
81
|
-
const spreadDeclaration = spreadPath.value
|
|
82
|
-
.declarations[0];
|
|
83
|
-
if (spreadDeclaration.init &&
|
|
84
|
-
spreadDeclaration.init.type === 'TaggedTemplateExpression') {
|
|
85
|
-
const { tag } = spreadDeclaration.init;
|
|
86
|
-
if (tag.type === 'CallExpression' &&
|
|
87
|
-
tag.callee.type === 'Identifier' &&
|
|
88
|
-
tag.callee.name === styledAliasName) {
|
|
89
|
-
const arg = tag.arguments[0];
|
|
90
|
-
if (arg.type === 'Identifier' &&
|
|
91
|
-
compoundComponentNames.includes(arg.name) &&
|
|
92
|
-
tag.loc) {
|
|
93
|
-
locs.push(tag.loc.start.line);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
return locs;
|
|
104
|
-
};
|
|
105
|
-
exports.default = reportStyledComponents;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const parseTypeScript: (source: string) => any;
|
|
@@ -1,42 +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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.parseTypeScript = void 0;
|
|
37
|
-
const recast = __importStar(require("recast"));
|
|
38
|
-
const tsParser = __importStar(require("../../parsers/typescript"));
|
|
39
|
-
const parseTypeScript = (source) => {
|
|
40
|
-
return recast.parse(source, { parser: tsParser });
|
|
41
|
-
};
|
|
42
|
-
exports.parseTypeScript = parseTypeScript;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const reportClassName = (attributes) => {
|
|
4
|
-
const classNameAttr = attributes.find((attr) => attr.type === 'JSXAttribute' &&
|
|
5
|
-
attr.name.type === 'JSXIdentifier' &&
|
|
6
|
-
attr.name.name === 'className');
|
|
7
|
-
if (classNameAttr && classNameAttr.loc) {
|
|
8
|
-
return classNameAttr.loc.start.line;
|
|
9
|
-
}
|
|
10
|
-
return undefined;
|
|
11
|
-
};
|
|
12
|
-
exports.default = reportClassName;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as recast from 'recast';
|
|
2
|
-
import type { AdditionalProp, InlineStyleProps } from './reportInlineStyle';
|
|
3
|
-
import type { ComponentName, CompoundComponentName } from './types';
|
|
4
|
-
declare const reportCustomProperties: (ast: recast.types.ASTNode, componentList: {
|
|
5
|
-
[k: string]: ComponentName;
|
|
6
|
-
}, commentList: {
|
|
7
|
-
classNameCmts: number[];
|
|
8
|
-
styleCmts: {
|
|
9
|
-
loc: number;
|
|
10
|
-
comment: string;
|
|
11
|
-
}[];
|
|
12
|
-
}) => {
|
|
13
|
-
className: number[];
|
|
14
|
-
style: number[];
|
|
15
|
-
sx: number[];
|
|
16
|
-
violatingAttributes: {
|
|
17
|
-
attributeName: string;
|
|
18
|
-
attributeValue: string | null;
|
|
19
|
-
inlineStyleProps: InlineStyleProps;
|
|
20
|
-
componentName: CompoundComponentName;
|
|
21
|
-
loc: number | undefined;
|
|
22
|
-
additionalProps?: AdditionalProp[];
|
|
23
|
-
}[];
|
|
24
|
-
};
|
|
25
|
-
export default reportCustomProperties;
|
|
@@ -1,185 +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 reportClassName_1 = __importDefault(require("./reportClassName"));
|
|
41
|
-
const reportInlineStyle_1 = __importDefault(require("./reportInlineStyle"));
|
|
42
|
-
const mapViolatingAttributesAndAdditionalProps = (violatingAttributes, additionalProps) => {
|
|
43
|
-
return violatingAttributes.map((violatingAttribute) => (Object.assign(Object.assign({}, violatingAttribute), (additionalProps && additionalProps.length ? { additionalProps } : {}))));
|
|
44
|
-
};
|
|
45
|
-
const getNonApprovedInlineLocs = (reportedLocs, violatingAttributes, approvedCmts, elementLoc) => {
|
|
46
|
-
var _a, _b;
|
|
47
|
-
const approvedCmt = approvedCmts.find((cmt) => cmt.loc === elementLoc - 1);
|
|
48
|
-
if (approvedCmt) {
|
|
49
|
-
const approvedCmtAttrNames = (_b = (_a = approvedCmt.comment
|
|
50
|
-
.toLowerCase()
|
|
51
|
-
.replace(/\s+/g, '')
|
|
52
|
-
.split('attributes:')[1]) === null || _a === void 0 ? void 0 : _a.split(',')) !== null && _b !== void 0 ? _b : [];
|
|
53
|
-
const noneApprovedStyleAttributes = violatingAttributes.filter((attr) => attr.loc === reportedLocs.style &&
|
|
54
|
-
!approvedCmtAttrNames.includes(attr.attributeName.toLowerCase()));
|
|
55
|
-
const noneApprovedSxAttributes = violatingAttributes.filter((attr) => attr.loc === reportedLocs.sx &&
|
|
56
|
-
!approvedCmtAttrNames.includes(attr.attributeName.toLowerCase()));
|
|
57
|
-
if (noneApprovedStyleAttributes.length > 0 ||
|
|
58
|
-
noneApprovedSxAttributes.length > 0) {
|
|
59
|
-
return {
|
|
60
|
-
reportedLocs,
|
|
61
|
-
noneApprovedAttributes: [
|
|
62
|
-
...noneApprovedStyleAttributes,
|
|
63
|
-
...noneApprovedSxAttributes,
|
|
64
|
-
],
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
return { reportedLocs: {}, noneApprovedAttributes: [] };
|
|
68
|
-
}
|
|
69
|
-
return { reportedLocs, noneApprovedAttributes: violatingAttributes };
|
|
70
|
-
};
|
|
71
|
-
const reportCustomProperties = (ast, componentList, commentList) => {
|
|
72
|
-
const report = {
|
|
73
|
-
className: [],
|
|
74
|
-
style: [],
|
|
75
|
-
sx: [],
|
|
76
|
-
violatingAttributes: [],
|
|
77
|
-
};
|
|
78
|
-
const localComponentList = Object.keys(componentList);
|
|
79
|
-
recast.visit(ast, {
|
|
80
|
-
visitJSXOpeningElement(path) {
|
|
81
|
-
this.traverse(path);
|
|
82
|
-
// Case 1: Custom default component, e.g. <Card />
|
|
83
|
-
if (path.value.name.type === 'JSXIdentifier' &&
|
|
84
|
-
localComponentList.includes(path.value.name.name)) {
|
|
85
|
-
const attributes = path.value
|
|
86
|
-
.attributes;
|
|
87
|
-
const classNameLoc = (0, reportClassName_1.default)(attributes);
|
|
88
|
-
if (classNameLoc &&
|
|
89
|
-
!commentList.classNameCmts.includes(path.value.loc.start.line - 1)) {
|
|
90
|
-
report.className.push(classNameLoc);
|
|
91
|
-
}
|
|
92
|
-
const { locs: styleObjectLocs, violatingAttributes, additionalProps, } = (0, reportInlineStyle_1.default)(ast, attributes, componentList[path.value.name.name]);
|
|
93
|
-
const { reportedLocs, noneApprovedAttributes } = getNonApprovedInlineLocs(styleObjectLocs, violatingAttributes, commentList.styleCmts, path.value.loc.start.line);
|
|
94
|
-
if (reportedLocs.style) {
|
|
95
|
-
report.style.push(reportedLocs.style);
|
|
96
|
-
}
|
|
97
|
-
if (reportedLocs.sx) {
|
|
98
|
-
report.sx.push(reportedLocs.sx);
|
|
99
|
-
}
|
|
100
|
-
report.violatingAttributes = [
|
|
101
|
-
...report.violatingAttributes,
|
|
102
|
-
...mapViolatingAttributesAndAdditionalProps(noneApprovedAttributes, additionalProps),
|
|
103
|
-
];
|
|
104
|
-
}
|
|
105
|
-
// Case 2: Custom compound component, e.g. <Card.Header />
|
|
106
|
-
if (path.value.name.type === 'JSXMemberExpression' &&
|
|
107
|
-
localComponentList.includes(path.value.name.object.name)) {
|
|
108
|
-
const compoundComponentName = [
|
|
109
|
-
componentList[path.value.name.object.name],
|
|
110
|
-
path.value.name.property.name,
|
|
111
|
-
].join('.');
|
|
112
|
-
const attributes = path.value
|
|
113
|
-
.attributes;
|
|
114
|
-
const classNameLoc = (0, reportClassName_1.default)(attributes);
|
|
115
|
-
if (classNameLoc &&
|
|
116
|
-
!commentList.classNameCmts.includes(path.value.loc.start.line - 1)) {
|
|
117
|
-
report.className.push(classNameLoc);
|
|
118
|
-
}
|
|
119
|
-
const { locs: styleObjectLocs, violatingAttributes, additionalProps, } = (0, reportInlineStyle_1.default)(ast, attributes, compoundComponentName);
|
|
120
|
-
const { reportedLocs, noneApprovedAttributes } = getNonApprovedInlineLocs(styleObjectLocs, violatingAttributes, commentList.styleCmts, path.value.loc.start.line);
|
|
121
|
-
if (reportedLocs.style) {
|
|
122
|
-
report.style.push(reportedLocs.style);
|
|
123
|
-
}
|
|
124
|
-
if (reportedLocs.sx) {
|
|
125
|
-
report.sx.push(reportedLocs.sx);
|
|
126
|
-
}
|
|
127
|
-
report.violatingAttributes = [
|
|
128
|
-
...report.violatingAttributes,
|
|
129
|
-
...mapViolatingAttributesAndAdditionalProps(noneApprovedAttributes, additionalProps),
|
|
130
|
-
];
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
// Case 3: Custom compound component with spead operator. e.g. const { Header } = Card, then <Header />
|
|
134
|
-
visitVariableDeclaration(path) {
|
|
135
|
-
this.traverse(path);
|
|
136
|
-
const declaration = path.value
|
|
137
|
-
.declarations[0];
|
|
138
|
-
if (declaration.init &&
|
|
139
|
-
declaration.init.type === 'Identifier' &&
|
|
140
|
-
localComponentList.includes(declaration.init.name)) {
|
|
141
|
-
const componentName = declaration.init.name;
|
|
142
|
-
const { id } = declaration;
|
|
143
|
-
if (id.type === 'ObjectPattern') {
|
|
144
|
-
const compoundComponentNames = id.properties
|
|
145
|
-
.map((prop) => prop.type === 'ObjectProperty' && prop.key.type === 'Identifier'
|
|
146
|
-
? prop.key.name
|
|
147
|
-
: null)
|
|
148
|
-
.filter((name) => name !== null);
|
|
149
|
-
recast.visit(ast, {
|
|
150
|
-
visitJSXOpeningElement(openPath) {
|
|
151
|
-
this.traverse(openPath);
|
|
152
|
-
if (openPath.value.name.type === 'JSXIdentifier' &&
|
|
153
|
-
compoundComponentNames.includes(openPath.value.name.name)) {
|
|
154
|
-
const compoundComponentName = [
|
|
155
|
-
componentList[componentName],
|
|
156
|
-
openPath.value.name.name,
|
|
157
|
-
].join('.');
|
|
158
|
-
const { attributes } = openPath.value;
|
|
159
|
-
const classNameLoc = (0, reportClassName_1.default)(attributes);
|
|
160
|
-
if (classNameLoc &&
|
|
161
|
-
!commentList.classNameCmts.includes(openPath.value.loc.start.line - 1)) {
|
|
162
|
-
report.className.push(classNameLoc);
|
|
163
|
-
}
|
|
164
|
-
const { locs: styleObjectLocs, violatingAttributes, additionalProps, } = (0, reportInlineStyle_1.default)(ast, attributes, compoundComponentName);
|
|
165
|
-
const { reportedLocs, noneApprovedAttributes } = getNonApprovedInlineLocs(styleObjectLocs, violatingAttributes, commentList.styleCmts, openPath.value.loc.start.line);
|
|
166
|
-
if (reportedLocs.style) {
|
|
167
|
-
report.style.push(reportedLocs.style);
|
|
168
|
-
}
|
|
169
|
-
if (reportedLocs.sx) {
|
|
170
|
-
report.sx.push(reportedLocs.sx);
|
|
171
|
-
}
|
|
172
|
-
report.violatingAttributes = [
|
|
173
|
-
...report.violatingAttributes,
|
|
174
|
-
...mapViolatingAttributesAndAdditionalProps(noneApprovedAttributes, additionalProps),
|
|
175
|
-
];
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
return report;
|
|
184
|
-
};
|
|
185
|
-
exports.default = reportCustomProperties;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as recast from 'recast';
|
|
2
|
-
import type { CompoundComponentName } from './types';
|
|
3
|
-
export type InlineStyleProps = 'style' | 'sx';
|
|
4
|
-
export type ViolatingAttribute = {
|
|
5
|
-
attributeName: string;
|
|
6
|
-
attributeValue: string | null;
|
|
7
|
-
inlineStyleProps: InlineStyleProps;
|
|
8
|
-
componentName: CompoundComponentName;
|
|
9
|
-
loc: number | undefined;
|
|
10
|
-
};
|
|
11
|
-
export type AdditionalProp = {
|
|
12
|
-
propName: string;
|
|
13
|
-
propValue: string | null;
|
|
14
|
-
};
|
|
15
|
-
declare const reportInlineStyle: (ast: recast.types.ASTNode, attributes: recast.types.namedTypes.JSXAttribute[], componentName: CompoundComponentName) => {
|
|
16
|
-
locs: {
|
|
17
|
-
style?: number;
|
|
18
|
-
sx?: number;
|
|
19
|
-
};
|
|
20
|
-
violatingAttributes: ViolatingAttribute[];
|
|
21
|
-
additionalProps: AdditionalProp[];
|
|
22
|
-
};
|
|
23
|
-
export default reportInlineStyle;
|