@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
package/lib/src/parseSource.js
DELETED
|
@@ -1,138 +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 tsParser = __importStar(require("./parsers/typescript"));
|
|
41
|
-
const reportCustomStyleProperties_1 = __importDefault(require("./reports/reportCustomStyleProperties"));
|
|
42
|
-
const reportStyledComponents_1 = __importDefault(require("./reports/reportStyledComponents"));
|
|
43
|
-
const constants_1 = require("./reports/constants");
|
|
44
|
-
const parseSource = (source) => {
|
|
45
|
-
let hasHeroDesignImport = false;
|
|
46
|
-
let hasStyledComponentsImport = false;
|
|
47
|
-
const componentList = {};
|
|
48
|
-
let styledAliasName = 'styled';
|
|
49
|
-
let styledComponentLocs = [];
|
|
50
|
-
let classNameLocs = [];
|
|
51
|
-
let styleLocs = [];
|
|
52
|
-
let sxLocs = [];
|
|
53
|
-
let violatingAttributes = [];
|
|
54
|
-
const approvedInlineStyleCmts = [];
|
|
55
|
-
const approvedClassnameLocs = [];
|
|
56
|
-
const approvedStyledComponentLocs = [];
|
|
57
|
-
const ast = recast.parse(source, { parser: tsParser });
|
|
58
|
-
recast.visit(ast, {
|
|
59
|
-
visitImportDeclaration(path) {
|
|
60
|
-
this.traverse(path);
|
|
61
|
-
const importedFrom = path.value.source.value;
|
|
62
|
-
// Check if file imports components from '@hero-design/react'
|
|
63
|
-
if (importedFrom === '@hero-design/react') {
|
|
64
|
-
recast.visit(path.node, {
|
|
65
|
-
visitImportSpecifier(importPath) {
|
|
66
|
-
this.traverse(importPath);
|
|
67
|
-
if (constants_1.HD_COMPONENTS.includes(importPath.value.imported.name)) {
|
|
68
|
-
componentList[importPath.value.local.name] =
|
|
69
|
-
importPath.value.imported.name;
|
|
70
|
-
hasHeroDesignImport = true;
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
// Check if file imports from 'styled-components'
|
|
76
|
-
if (importedFrom === 'styled-components') {
|
|
77
|
-
recast.visit(path.node, {
|
|
78
|
-
visitImportDefaultSpecifier(importPath) {
|
|
79
|
-
this.traverse(importPath);
|
|
80
|
-
styledAliasName = importPath.value.local.name;
|
|
81
|
-
hasStyledComponentsImport = true;
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
visitComment(path) {
|
|
87
|
-
this.traverse(path);
|
|
88
|
-
const comment = path.value.value;
|
|
89
|
-
if (comment
|
|
90
|
-
.toLowerCase()
|
|
91
|
-
.includes(constants_1.APPROVED_INLINE_STYLE_COMMENT.toLowerCase())) {
|
|
92
|
-
approvedInlineStyleCmts.push({
|
|
93
|
-
loc: path.value.loc.start.line,
|
|
94
|
-
comment,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
if (comment.toLowerCase().includes(constants_1.APPROVED_CLASSNAME_COMMENT.toLowerCase())) {
|
|
98
|
-
approvedClassnameLocs.push(path.value.loc.start.line);
|
|
99
|
-
}
|
|
100
|
-
if (comment
|
|
101
|
-
.toLowerCase()
|
|
102
|
-
.includes(constants_1.APPROVED_STYLED_COMPONENTS_COMMENT.toLowerCase())) {
|
|
103
|
-
approvedStyledComponentLocs.push(path.value.loc.start.line);
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
const isNotApprovedStyledComponentSnowflakes = (loc) => !approvedStyledComponentLocs.includes(loc - 1);
|
|
108
|
-
if (hasHeroDesignImport) {
|
|
109
|
-
// Case 1: Using className to customise components
|
|
110
|
-
// Case 2: Using style object to customise components
|
|
111
|
-
// Case 3: Using sx object to customise components
|
|
112
|
-
const customPropLocs = (0, reportCustomStyleProperties_1.default)(ast, componentList, {
|
|
113
|
-
classNameCmts: approvedClassnameLocs,
|
|
114
|
-
styleCmts: approvedInlineStyleCmts,
|
|
115
|
-
});
|
|
116
|
-
classNameLocs = customPropLocs.className;
|
|
117
|
-
styleLocs = customPropLocs.style;
|
|
118
|
-
sxLocs = customPropLocs.sx;
|
|
119
|
-
// Case 4: Using styled-components to customise components
|
|
120
|
-
if (hasStyledComponentsImport) {
|
|
121
|
-
styledComponentLocs = (0, reportStyledComponents_1.default)(ast, componentList, styledAliasName).filter(isNotApprovedStyledComponentSnowflakes);
|
|
122
|
-
}
|
|
123
|
-
violatingAttributes = customPropLocs.violatingAttributes;
|
|
124
|
-
}
|
|
125
|
-
return {
|
|
126
|
-
classNameLocs,
|
|
127
|
-
styleLocs,
|
|
128
|
-
sxLocs,
|
|
129
|
-
styledComponentLocs,
|
|
130
|
-
approvedLocs: [
|
|
131
|
-
...approvedInlineStyleCmts.map((cmt) => cmt.loc),
|
|
132
|
-
...approvedClassnameLocs,
|
|
133
|
-
...approvedStyledComponentLocs,
|
|
134
|
-
],
|
|
135
|
-
violatingAttributes,
|
|
136
|
-
};
|
|
137
|
-
};
|
|
138
|
-
exports.default = parseSource;
|
package/lib/src/parsers/flow.js
DELETED
|
@@ -1,47 +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
|
-
exports.parse = void 0;
|
|
40
|
-
const babelParser = __importStar(require("@babel/parser"));
|
|
41
|
-
const _babel_options_1 = __importDefault(require("recast/parsers/_babel_options"));
|
|
42
|
-
const parse = (source, options) => {
|
|
43
|
-
const babelOptions = (0, _babel_options_1.default)(options);
|
|
44
|
-
babelOptions.plugins.push('jsx', 'flow');
|
|
45
|
-
return babelParser.parse(source, babelOptions);
|
|
46
|
-
};
|
|
47
|
-
exports.parse = parse;
|
|
@@ -1,47 +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
|
-
exports.parse = void 0;
|
|
40
|
-
const babelParser = __importStar(require("@babel/parser"));
|
|
41
|
-
const _babel_options_1 = __importDefault(require("recast/parsers/_babel_options"));
|
|
42
|
-
const parse = (source, options) => {
|
|
43
|
-
const babelOptions = (0, _babel_options_1.default)(options);
|
|
44
|
-
babelOptions.plugins.push('jsx', 'typescript');
|
|
45
|
-
return babelParser.parse(source, babelOptions);
|
|
46
|
-
};
|
|
47
|
-
exports.parse = parse;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,143 +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
|
-
sx={{
|
|
52
|
-
padding: 10,
|
|
53
|
-
backgroundColor: 'blue'
|
|
54
|
-
}}
|
|
55
|
-
variant="primary"
|
|
56
|
-
intent="success"
|
|
57
|
-
/>
|
|
58
|
-
);
|
|
59
|
-
`;
|
|
60
|
-
// Step 1: Parse the code to generate the AST
|
|
61
|
-
const ast = recast.parse(code, { parser: tsParser });
|
|
62
|
-
const attributes = [];
|
|
63
|
-
// Step 2: Traverse the AST to extract relevant JSXAttributes (style and sx)
|
|
64
|
-
recast.visit(ast, {
|
|
65
|
-
visitJSXAttribute(path) {
|
|
66
|
-
const { node } = path;
|
|
67
|
-
attributes.push(node);
|
|
68
|
-
this.traverse(path);
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
const componentName = 'Card';
|
|
72
|
-
// Mock the RULESET_MAP and SX_RULESET_MAP for this test
|
|
73
|
-
constants_1.RULESET_MAP.Card = ['color', 'backgroundColor'];
|
|
74
|
-
constants_1.SX_RULESET_MAP.Card = ['padding', 'backgroundColor'];
|
|
75
|
-
// Step 3: Run the function with the dynamically extracted attributes
|
|
76
|
-
const result = (0, reportInlineStyle_1.default)(ast, attributes, componentName);
|
|
77
|
-
expect(result.additionalProps).toMatchObject([
|
|
78
|
-
{
|
|
79
|
-
propValue: '"primary"',
|
|
80
|
-
propName: 'variant',
|
|
81
|
-
},
|
|
82
|
-
]);
|
|
83
|
-
expect(result.locs.style).toEqual(3);
|
|
84
|
-
expect(result.locs.sx).toEqual(7);
|
|
85
|
-
expect(result.violatingAttributes).toEqual([
|
|
86
|
-
{
|
|
87
|
-
attributeName: 'color',
|
|
88
|
-
attributeValue: "'red'",
|
|
89
|
-
componentName: 'Card',
|
|
90
|
-
inlineStyleProps: 'style',
|
|
91
|
-
loc: 3,
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
attributeName: 'backgroundColor',
|
|
95
|
-
attributeValue: "'blue'",
|
|
96
|
-
componentName: 'Card',
|
|
97
|
-
inlineStyleProps: 'style',
|
|
98
|
-
loc: 3,
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
attributeName: 'padding',
|
|
102
|
-
attributeValue: '10',
|
|
103
|
-
componentName: 'Card',
|
|
104
|
-
inlineStyleProps: 'sx',
|
|
105
|
-
loc: 7,
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
attributeName: 'backgroundColor',
|
|
109
|
-
attributeValue: "'blue'",
|
|
110
|
-
componentName: 'Card',
|
|
111
|
-
inlineStyleProps: 'sx',
|
|
112
|
-
loc: 7,
|
|
113
|
-
},
|
|
114
|
-
]);
|
|
115
|
-
});
|
|
116
|
-
it('should return empty arrays when no violations are found', () => {
|
|
117
|
-
const code = `
|
|
118
|
-
const MyComponent = () => (
|
|
119
|
-
<Card style={{ margin: '10px' }} sx={{ margin: 5 }} />
|
|
120
|
-
);
|
|
121
|
-
`;
|
|
122
|
-
// Step 1: Parse the code to generate the AST
|
|
123
|
-
const ast = recast.parse(code, { parser: tsParser });
|
|
124
|
-
const attributes = [];
|
|
125
|
-
// Step 2: Traverse the AST to extract relevant JSXAttributes (style and sx)
|
|
126
|
-
recast.visit(ast, {
|
|
127
|
-
visitJSXAttribute(path) {
|
|
128
|
-
const { node } = path;
|
|
129
|
-
attributes.push(node);
|
|
130
|
-
this.traverse(path);
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
const componentName = 'Card';
|
|
134
|
-
// Mock the RULESET_MAP and SX_RULESET_MAP for this test
|
|
135
|
-
constants_1.RULESET_MAP.Card = ['color'];
|
|
136
|
-
constants_1.SX_RULESET_MAP.Card = ['padding'];
|
|
137
|
-
const result = (0, reportInlineStyle_1.default)(ast, attributes, componentName);
|
|
138
|
-
expect(result.locs.style).toEqual(undefined);
|
|
139
|
-
expect(result.locs.sx).toEqual(undefined);
|
|
140
|
-
expect(result.violatingAttributes).toEqual([]);
|
|
141
|
-
expect(result.violatingAttributes).toEqual([]);
|
|
142
|
-
});
|
|
143
|
-
});
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
declare const RULESET_MAP: {
|
|
2
|
-
Alert: string[];
|
|
3
|
-
Badge: string[];
|
|
4
|
-
'Badge.Count': string[];
|
|
5
|
-
'Badge.Status': string[];
|
|
6
|
-
Banner: string[];
|
|
7
|
-
Breadcrumb: string[];
|
|
8
|
-
Button: string[];
|
|
9
|
-
'Button.Link': string[];
|
|
10
|
-
'Button.Icon': string[];
|
|
11
|
-
Card: string[];
|
|
12
|
-
'Card.Header': string[];
|
|
13
|
-
'Card.Content': string[];
|
|
14
|
-
Carousel: string[];
|
|
15
|
-
'Chart.Bar': string[];
|
|
16
|
-
'Chart.HorizontalBar': string[];
|
|
17
|
-
'Chart.Column': string[];
|
|
18
|
-
'Chart.Line': string[];
|
|
19
|
-
'Chart.Pie': string[];
|
|
20
|
-
'Chart.MultiplePie': string[];
|
|
21
|
-
Checkbox: string[];
|
|
22
|
-
'Checkbox.Group': string[];
|
|
23
|
-
'Checkbox.Button': string[];
|
|
24
|
-
'Checkbox.ButtonGroup': string[];
|
|
25
|
-
Chip: string[];
|
|
26
|
-
Collapse: string[];
|
|
27
|
-
Comment: string[];
|
|
28
|
-
'Comment.Editor': string[];
|
|
29
|
-
ContextPanel: string[];
|
|
30
|
-
'ContextPanel.Header': string[];
|
|
31
|
-
'ContextPanel.Body': string[];
|
|
32
|
-
'ContextPanel.Footer': string[];
|
|
33
|
-
'ContextPanel.CloseButton': string[];
|
|
34
|
-
DatePicker: string[];
|
|
35
|
-
'DatePicker.Range': string[];
|
|
36
|
-
'DatePicker.Month': string[];
|
|
37
|
-
'DatePicker.MonthRange': string[];
|
|
38
|
-
'DatePicker.Week': string[];
|
|
39
|
-
'DatePicker.Fortnightly': string[];
|
|
40
|
-
'DatePicker.SingleMonth': string[];
|
|
41
|
-
'DatePicker.SingleYear': string[];
|
|
42
|
-
'DatePicker.FixedRange': string[];
|
|
43
|
-
Divider: string[];
|
|
44
|
-
Dropdown: string[];
|
|
45
|
-
Empty: string[];
|
|
46
|
-
'File.DragAndDrop': string[];
|
|
47
|
-
'File.UploadButton': string[];
|
|
48
|
-
'File.UploadIconButton': string[];
|
|
49
|
-
Filters: string[];
|
|
50
|
-
'Filters.Label': string[];
|
|
51
|
-
'Filters.Filter': string[];
|
|
52
|
-
'Filters.Group': string[];
|
|
53
|
-
'Filters.Group.Filter': string[];
|
|
54
|
-
'Form.Field': string[];
|
|
55
|
-
Grid: string[];
|
|
56
|
-
'Grid.Row': string[];
|
|
57
|
-
'Grid.Col': string[];
|
|
58
|
-
Icon: string[];
|
|
59
|
-
InPageNavigation: string[];
|
|
60
|
-
Input: string[];
|
|
61
|
-
'Input.TextArea': string[];
|
|
62
|
-
MediaQuery: string[];
|
|
63
|
-
Menu: string[];
|
|
64
|
-
'Menu.Item': string[];
|
|
65
|
-
Modal: string[];
|
|
66
|
-
'Modal.PopUp': string[];
|
|
67
|
-
'Modal.Header': string[];
|
|
68
|
-
'Modal.Body': string[];
|
|
69
|
-
'Modal.Footer': string[];
|
|
70
|
-
'Modal.CloseButton': string[];
|
|
71
|
-
Notification: string[];
|
|
72
|
-
PageHeader: string[];
|
|
73
|
-
Pagination: string[];
|
|
74
|
-
Pane: string[];
|
|
75
|
-
'Pane.Header': string[];
|
|
76
|
-
'Pane.Body': string[];
|
|
77
|
-
'Pane.Footer': string[];
|
|
78
|
-
'Pane.CloseButton': string[];
|
|
79
|
-
Portlet: string[];
|
|
80
|
-
Progress: string[];
|
|
81
|
-
'Progress.Circle': string[];
|
|
82
|
-
Radio: string[];
|
|
83
|
-
'Radio.Group': string[];
|
|
84
|
-
'Radio.Button': string[];
|
|
85
|
-
'Radio.ButtonGroup': string[];
|
|
86
|
-
Rate: string[];
|
|
87
|
-
Result: string[];
|
|
88
|
-
Select: string[];
|
|
89
|
-
'Select.Multi': string[];
|
|
90
|
-
SelectButton: string[];
|
|
91
|
-
'SelectButton.Group': string[];
|
|
92
|
-
SideBar: string[];
|
|
93
|
-
'SideBar.Panel': string[];
|
|
94
|
-
Slider: string[];
|
|
95
|
-
Spinner: string[];
|
|
96
|
-
Statistic: string[];
|
|
97
|
-
Steps: string[];
|
|
98
|
-
Switch: string[];
|
|
99
|
-
Table: string[];
|
|
100
|
-
'Table.ActionButtons': string[];
|
|
101
|
-
'Table.BulkActions': string[];
|
|
102
|
-
'Table.RowAction': string[];
|
|
103
|
-
'Table.Filters': string[];
|
|
104
|
-
'Table.Filter': string[];
|
|
105
|
-
Tabs: string[];
|
|
106
|
-
'Tabs.Sub': string[];
|
|
107
|
-
Tag: string[];
|
|
108
|
-
TimePicker: string[];
|
|
109
|
-
Timeline: string[];
|
|
110
|
-
Tooltip: string[];
|
|
111
|
-
'Typography.Title': string[];
|
|
112
|
-
'Typography.Text': string[];
|
|
113
|
-
Widget: string[];
|
|
114
|
-
};
|
|
115
|
-
declare const SX_RULESET_MAP: {
|
|
116
|
-
Alert: string[];
|
|
117
|
-
Badge: string[];
|
|
118
|
-
'Badge.Count': string[];
|
|
119
|
-
'Badge.Status': string[];
|
|
120
|
-
Banner: string[];
|
|
121
|
-
Breadcrumb: string[];
|
|
122
|
-
Button: string[];
|
|
123
|
-
'Button.Link': string[];
|
|
124
|
-
'Button.Icon': string[];
|
|
125
|
-
Card: string[];
|
|
126
|
-
'Card.Header': string[];
|
|
127
|
-
'Card.Content': string[];
|
|
128
|
-
Carousel: string[];
|
|
129
|
-
'Chart.Bar': string[];
|
|
130
|
-
'Chart.HorizontalBar': string[];
|
|
131
|
-
'Chart.Column': string[];
|
|
132
|
-
'Chart.Line': string[];
|
|
133
|
-
'Chart.Pie': string[];
|
|
134
|
-
'Chart.MultiplePie': string[];
|
|
135
|
-
Checkbox: string[];
|
|
136
|
-
'Checkbox.Group': string[];
|
|
137
|
-
'Checkbox.Button': string[];
|
|
138
|
-
'Checkbox.ButtonGroup': string[];
|
|
139
|
-
Chip: string[];
|
|
140
|
-
Collapse: string[];
|
|
141
|
-
Comment: string[];
|
|
142
|
-
'Comment.Editor': string[];
|
|
143
|
-
ContextPanel: string[];
|
|
144
|
-
'ContextPanel.Header': string[];
|
|
145
|
-
'ContextPanel.Body': string[];
|
|
146
|
-
'ContextPanel.Footer': string[];
|
|
147
|
-
'ContextPanel.CloseButton': string[];
|
|
148
|
-
DatePicker: string[];
|
|
149
|
-
'DatePicker.Range': string[];
|
|
150
|
-
'DatePicker.Month': string[];
|
|
151
|
-
'DatePicker.MonthRange': string[];
|
|
152
|
-
'DatePicker.Week': string[];
|
|
153
|
-
'DatePicker.Fortnightly': string[];
|
|
154
|
-
'DatePicker.SingleMonth': string[];
|
|
155
|
-
'DatePicker.SingleYear': string[];
|
|
156
|
-
'DatePicker.FixedRange': string[];
|
|
157
|
-
Divider: string[];
|
|
158
|
-
Dropdown: string[];
|
|
159
|
-
Empty: string[];
|
|
160
|
-
'File.DragAndDrop': string[];
|
|
161
|
-
'File.UploadButton': string[];
|
|
162
|
-
'File.UploadIconButton': string[];
|
|
163
|
-
Filters: string[];
|
|
164
|
-
'Filters.Label': string[];
|
|
165
|
-
'Filters.Filter': string[];
|
|
166
|
-
'Filters.Group': string[];
|
|
167
|
-
'Filters.Group.Filter': string[];
|
|
168
|
-
'Form.Field': string[];
|
|
169
|
-
Grid: string[];
|
|
170
|
-
'Grid.Row': string[];
|
|
171
|
-
'Grid.Col': string[];
|
|
172
|
-
Icon: string[];
|
|
173
|
-
InPageNavigation: string[];
|
|
174
|
-
Input: string[];
|
|
175
|
-
'Input.TextArea': string[];
|
|
176
|
-
MediaQuery: string[];
|
|
177
|
-
Menu: string[];
|
|
178
|
-
'Menu.Item': string[];
|
|
179
|
-
Modal: string[];
|
|
180
|
-
'Modal.PopUp': string[];
|
|
181
|
-
'Modal.Header': string[];
|
|
182
|
-
'Modal.Body': string[];
|
|
183
|
-
'Modal.Footer': string[];
|
|
184
|
-
'Modal.CloseButton': string[];
|
|
185
|
-
Notification: string[];
|
|
186
|
-
PageHeader: string[];
|
|
187
|
-
Pagination: string[];
|
|
188
|
-
Pane: string[];
|
|
189
|
-
'Pane.Header': string[];
|
|
190
|
-
'Pane.Body': string[];
|
|
191
|
-
'Pane.Footer': string[];
|
|
192
|
-
'Pane.CloseButton': string[];
|
|
193
|
-
Portlet: string[];
|
|
194
|
-
Progress: string[];
|
|
195
|
-
'Progress.Circle': string[];
|
|
196
|
-
Radio: string[];
|
|
197
|
-
'Radio.Group': string[];
|
|
198
|
-
'Radio.Button': string[];
|
|
199
|
-
'Radio.ButtonGroup': string[];
|
|
200
|
-
Rate: string[];
|
|
201
|
-
Result: string[];
|
|
202
|
-
Select: string[];
|
|
203
|
-
'Select.Multi': string[];
|
|
204
|
-
SelectButton: string[];
|
|
205
|
-
'SelectButton.Group': string[];
|
|
206
|
-
SideBar: string[];
|
|
207
|
-
'SideBar.Panel': string[];
|
|
208
|
-
Slider: string[];
|
|
209
|
-
Spinner: string[];
|
|
210
|
-
Statistic: string[];
|
|
211
|
-
Steps: string[];
|
|
212
|
-
Switch: string[];
|
|
213
|
-
Table: string[];
|
|
214
|
-
'Table.ActionButtons': string[];
|
|
215
|
-
'Table.BulkActions': string[];
|
|
216
|
-
'Table.RowAction': string[];
|
|
217
|
-
'Table.Filters': string[];
|
|
218
|
-
'Table.Filter': string[];
|
|
219
|
-
Tabs: string[];
|
|
220
|
-
'Tabs.Sub': string[];
|
|
221
|
-
Tag: string[];
|
|
222
|
-
TimePicker: string[];
|
|
223
|
-
Timeline: string[];
|
|
224
|
-
Tooltip: string[];
|
|
225
|
-
'Typography.Title': string[];
|
|
226
|
-
'Typography.Text': string[];
|
|
227
|
-
Widget: string[];
|
|
228
|
-
};
|
|
229
|
-
declare const HD_COMPONENTS: readonly ["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", "Pane", "Portal", "Portlet", "Progress", "Radio", "Rate", "Result", "Select", "SelectButton", "SideBar", "Slider", "Spinner", "Statistic", "Steps", "Switch", "Table", "Tabs", "Tag", "TagInput", "TimePicker", "Timeline", "Tooltip", "Typography", "Widget"];
|
|
230
|
-
declare const APPROVED_INLINE_STYLE_COMMENT = "@snowflake-guard/approved-inline-style";
|
|
231
|
-
declare const APPROVED_CLASSNAME_COMMENT = "@snowflake-guard/approved-classname";
|
|
232
|
-
declare const APPROVED_STYLED_COMPONENTS_COMMENT = "@snowflake-guard/approved-styled-components";
|
|
233
|
-
export { HD_COMPONENTS, RULESET_MAP, SX_RULESET_MAP, APPROVED_INLINE_STYLE_COMMENT, APPROVED_CLASSNAME_COMMENT, APPROVED_STYLED_COMPONENTS_COMMENT, };
|