@hero-design/snowflake-guard 1.4.9 → 1.4.11
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 +1 -1
- 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,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const queryGenerators_1 = require("../queryGenerators");
|
|
4
|
-
const replaceWhiteSpace = (str) => str.replace(/\s/g, '');
|
|
5
|
-
describe('generateFetchReportQuery', () => {
|
|
6
|
-
it('returns correct query', () => {
|
|
7
|
-
const query = (0, queryGenerators_1.generateFetchReportQuery)({
|
|
8
|
-
repoName: 'repoName',
|
|
9
|
-
prNumber: 123,
|
|
10
|
-
});
|
|
11
|
-
expect(replaceWhiteSpace(query)).toBe(replaceWhiteSpace(`
|
|
12
|
-
query {
|
|
13
|
-
fetchHdSnowflakeGuardReport(repoName: "repoName", prNumber: 123) {
|
|
14
|
-
id
|
|
15
|
-
originalCount
|
|
16
|
-
latestCount
|
|
17
|
-
approvedCount
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
`));
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
describe('generateCreateReportQuery', () => {
|
|
24
|
-
it('returns correct query', () => {
|
|
25
|
-
const query = (0, queryGenerators_1.generateCreateReportQuery)({
|
|
26
|
-
repoName: 'repoName',
|
|
27
|
-
prNumber: 123,
|
|
28
|
-
owner: 'owner',
|
|
29
|
-
originalCount: 3,
|
|
30
|
-
latestCount: 1,
|
|
31
|
-
approvedCount: 2,
|
|
32
|
-
});
|
|
33
|
-
expect(replaceWhiteSpace(query)).toBe(replaceWhiteSpace(`
|
|
34
|
-
mutation {
|
|
35
|
-
createHdSnowflakeGuardReport(
|
|
36
|
-
input: {
|
|
37
|
-
params: {
|
|
38
|
-
repoName: "repoName"
|
|
39
|
-
prNumber: 123
|
|
40
|
-
owner: "owner"
|
|
41
|
-
originalCount: 3
|
|
42
|
-
latestCount: 1
|
|
43
|
-
approvedCount: 2
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
) {
|
|
47
|
-
hdSnowflakeGuardReport {
|
|
48
|
-
id
|
|
49
|
-
repoName
|
|
50
|
-
prNumber
|
|
51
|
-
originalCount
|
|
52
|
-
latestCount
|
|
53
|
-
approvedCount
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
`));
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
describe('generateUpdateReportQuery', () => {
|
|
61
|
-
it('returns correct query', () => {
|
|
62
|
-
const query = (0, queryGenerators_1.generateUpdateReportQuery)({
|
|
63
|
-
id: 'id',
|
|
64
|
-
latestCount: 1,
|
|
65
|
-
approvedCount: 2,
|
|
66
|
-
});
|
|
67
|
-
expect(replaceWhiteSpace(query)).toBe(replaceWhiteSpace(`
|
|
68
|
-
mutation {
|
|
69
|
-
updateHdSnowflakeGuardReport(
|
|
70
|
-
input: { id: "id", latestCount: 1, approvedCount: 2 }
|
|
71
|
-
) {
|
|
72
|
-
hdSnowflakeGuardReport {
|
|
73
|
-
id
|
|
74
|
-
latestCount
|
|
75
|
-
originalCount
|
|
76
|
-
approvedCount
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
`));
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const fetchGraphql = (query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
-
const host = process.env.DB_HOST || 'http://localhost:3000';
|
|
14
|
-
return fetch(`${host}/graphql`, {
|
|
15
|
-
method: 'POST',
|
|
16
|
-
headers: {
|
|
17
|
-
'Content-Type': 'application/json',
|
|
18
|
-
'Snowflake-Guard-Auth': process.env.SNOWFLAKE_GUARD_SECRET || '',
|
|
19
|
-
},
|
|
20
|
-
body: JSON.stringify({ query }),
|
|
21
|
-
}).then((response) => response.json());
|
|
22
|
-
});
|
|
23
|
-
exports.default = fetchGraphql;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
declare const generateFetchReportQuery: ({ repoName, prNumber, }: {
|
|
2
|
-
repoName: string;
|
|
3
|
-
prNumber: number;
|
|
4
|
-
}) => string;
|
|
5
|
-
declare const generateCreateReportQuery: ({ repoName, prNumber, owner, originalCount, latestCount, approvedCount, }: {
|
|
6
|
-
repoName: string;
|
|
7
|
-
prNumber: number;
|
|
8
|
-
owner: string;
|
|
9
|
-
originalCount: number;
|
|
10
|
-
latestCount: number;
|
|
11
|
-
approvedCount: number;
|
|
12
|
-
}) => string;
|
|
13
|
-
declare const generateUpdateReportQuery: ({ id, latestCount, approvedCount, }: {
|
|
14
|
-
id: string;
|
|
15
|
-
latestCount: number;
|
|
16
|
-
approvedCount: number;
|
|
17
|
-
}) => string;
|
|
18
|
-
export { generateFetchReportQuery, generateCreateReportQuery, generateUpdateReportQuery, };
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateUpdateReportQuery = exports.generateCreateReportQuery = exports.generateFetchReportQuery = void 0;
|
|
4
|
-
const generateFetchReportQuery = ({ repoName, prNumber, }) => {
|
|
5
|
-
return `
|
|
6
|
-
query {
|
|
7
|
-
fetchHdSnowflakeGuardReport(repoName: "${repoName}", prNumber: ${prNumber}) {
|
|
8
|
-
id
|
|
9
|
-
originalCount
|
|
10
|
-
latestCount
|
|
11
|
-
approvedCount
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
`;
|
|
15
|
-
};
|
|
16
|
-
exports.generateFetchReportQuery = generateFetchReportQuery;
|
|
17
|
-
const generateCreateReportQuery = ({ repoName, prNumber, owner, originalCount, latestCount, approvedCount, }) => {
|
|
18
|
-
return `
|
|
19
|
-
mutation {
|
|
20
|
-
createHdSnowflakeGuardReport(
|
|
21
|
-
input: {
|
|
22
|
-
params: {
|
|
23
|
-
repoName: "${repoName}"
|
|
24
|
-
prNumber: ${prNumber}
|
|
25
|
-
owner: "${owner}"
|
|
26
|
-
originalCount: ${originalCount}
|
|
27
|
-
latestCount: ${latestCount}
|
|
28
|
-
approvedCount: ${approvedCount}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
) {
|
|
32
|
-
hdSnowflakeGuardReport {
|
|
33
|
-
id
|
|
34
|
-
repoName
|
|
35
|
-
prNumber
|
|
36
|
-
originalCount
|
|
37
|
-
latestCount
|
|
38
|
-
approvedCount
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
`;
|
|
43
|
-
};
|
|
44
|
-
exports.generateCreateReportQuery = generateCreateReportQuery;
|
|
45
|
-
const generateUpdateReportQuery = ({ id, latestCount, approvedCount, }) => {
|
|
46
|
-
return `
|
|
47
|
-
mutation {
|
|
48
|
-
updateHdSnowflakeGuardReport(
|
|
49
|
-
input: { id: "${id}", latestCount: ${latestCount}, approvedCount: ${approvedCount} }
|
|
50
|
-
) {
|
|
51
|
-
hdSnowflakeGuardReport {
|
|
52
|
-
id
|
|
53
|
-
latestCount
|
|
54
|
-
originalCount
|
|
55
|
-
approvedCount
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
`;
|
|
60
|
-
};
|
|
61
|
-
exports.generateUpdateReportQuery = generateUpdateReportQuery;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
type Report = {
|
|
2
|
-
id: string;
|
|
3
|
-
repoName: string;
|
|
4
|
-
prNumber: number;
|
|
5
|
-
owner: string;
|
|
6
|
-
originalCount: number;
|
|
7
|
-
latestCount: number;
|
|
8
|
-
approvedCount: number;
|
|
9
|
-
};
|
|
10
|
-
export type FetchReportResponse = {
|
|
11
|
-
errors: {
|
|
12
|
-
message: string;
|
|
13
|
-
}[];
|
|
14
|
-
data: null | {
|
|
15
|
-
fetchHdSnowflakeGuardReport: Pick<Report, 'id' | 'originalCount' | 'latestCount' | 'approvedCount'>;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export {};
|
package/lib/src/graphql/types.js
DELETED
package/lib/src/index.d.ts
DELETED
package/lib/src/index.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
const parseMobileSource_1 = __importDefault(require("./parseMobileSource"));
|
|
15
|
-
const parseSource_1 = __importDefault(require("./parseSource"));
|
|
16
|
-
const constants_1 = require("./reports/constants");
|
|
17
|
-
const fetchGraphql_1 = __importDefault(require("./graphql/fetchGraphql"));
|
|
18
|
-
const queryGenerators_1 = require("./graphql/queryGenerators");
|
|
19
|
-
const getDiffLocs_1 = require("./utils/getDiffLocs");
|
|
20
|
-
const WEB_REGEX = /\.tsx$/;
|
|
21
|
-
const MOBILE_REGEX = /\.(tsx|jsx|js)$/;
|
|
22
|
-
const TEST_REGEX = /__tests__/;
|
|
23
|
-
const SNOWFLAKE_COMMENTS_WEB = {
|
|
24
|
-
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).',
|
|
25
|
-
sx: 'Snowflake detected! A component is customized via sx prop. Make sure to not use [prohibited CSS properties](https://docs.google.com/spreadsheets/d/1Dj8vqLdFaf-CSaSVoYqyYZIkGqF6OoyP7K4G1_9L62U/edit?usp=sharing).',
|
|
26
|
-
'styled-component': 'Please do not use styled-component to customize this component, use sx prop or inline style instead.',
|
|
27
|
-
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
|
-
};
|
|
29
|
-
const SNOWFLAKE_COMMENTS_MOBILE = {
|
|
30
|
-
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?gid=1761479144#gid=1761479144).',
|
|
31
|
-
'styled-component': 'Please do not use styled-component to customize this component.',
|
|
32
|
-
};
|
|
33
|
-
const MOBILE_REPO_NAMES = JSON.parse(process.env.MOBILE_REPO_NAMES || '[]');
|
|
34
|
-
const APPROVED_USER_LIST = JSON.parse(process.env.APPROVED_USER_LIST || '[]');
|
|
35
|
-
const checkIfDetectedSnowflakesInDiff = (diffLocs, locToComment) => {
|
|
36
|
-
const locIdx = diffLocs.findIndex(([start, end]) => {
|
|
37
|
-
return locToComment >= start && locToComment <= end;
|
|
38
|
-
});
|
|
39
|
-
return locIdx !== -1;
|
|
40
|
-
};
|
|
41
|
-
module.exports = (app) => {
|
|
42
|
-
app.on(['pull_request.opened', 'pull_request.synchronize'], (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
var _a;
|
|
44
|
-
// Get PR info
|
|
45
|
-
const prNumber = context.payload.number;
|
|
46
|
-
const repoInfo = {
|
|
47
|
-
repo: context.payload.repository.name,
|
|
48
|
-
owner: context.payload.repository.owner.login,
|
|
49
|
-
};
|
|
50
|
-
const prBranch = context.payload.pull_request.head.ref;
|
|
51
|
-
// List all changed files
|
|
52
|
-
const prFiles = yield context.octokit.pulls.listFiles(Object.assign(Object.assign({}, repoInfo), { pull_number: prNumber }));
|
|
53
|
-
const isMobile = MOBILE_REPO_NAMES.includes(repoInfo.repo);
|
|
54
|
-
const parseSource = isMobile ? parseMobileSource_1.default : parseSource_1.default;
|
|
55
|
-
const SOURCE_REGEX = isMobile ? MOBILE_REGEX : WEB_REGEX;
|
|
56
|
-
const sourceFiles = prFiles.data.filter((file) => SOURCE_REGEX.test(file.filename) &&
|
|
57
|
-
!TEST_REGEX.test(file.filename) &&
|
|
58
|
-
file.status !== 'removed');
|
|
59
|
-
// Saving file patches to get diff locations
|
|
60
|
-
const prFilePatches = sourceFiles.reduce((acc, file) => {
|
|
61
|
-
acc[file.filename] = file.patch || '';
|
|
62
|
-
return acc;
|
|
63
|
-
}, {});
|
|
64
|
-
// Get file contents
|
|
65
|
-
const prFileContentPromises = sourceFiles.map((file) => context.octokit.repos.getContent(Object.assign(Object.assign({}, repoInfo), { path: file.filename, ref: prBranch })));
|
|
66
|
-
const prFileContents = yield Promise.all(prFileContentPromises);
|
|
67
|
-
const snowflakeComments = [];
|
|
68
|
-
const approvedSnowflakeLocs = [];
|
|
69
|
-
prFileContents.forEach((file) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
71
|
-
// @ts-ignore
|
|
72
|
-
const filePath = file.data.path;
|
|
73
|
-
const diffLocs = (0, getDiffLocs_1.getDiffLocs)(prFilePatches[filePath]);
|
|
74
|
-
const stringContent = Buffer.from(
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
76
|
-
// @ts-ignore
|
|
77
|
-
file.data.content, 'base64').toString();
|
|
78
|
-
// Parse file content to check for snowflakes
|
|
79
|
-
const snowflakeReport = parseSource(stringContent);
|
|
80
|
-
snowflakeReport.styleLocs.forEach((loc) => {
|
|
81
|
-
if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
|
|
82
|
-
snowflakeComments.push({
|
|
83
|
-
path: filePath,
|
|
84
|
-
body: isMobile
|
|
85
|
-
? SNOWFLAKE_COMMENTS_MOBILE['style']
|
|
86
|
-
: SNOWFLAKE_COMMENTS_WEB['style'],
|
|
87
|
-
line: loc,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
snowflakeReport.styledComponentLocs.forEach((loc) => {
|
|
92
|
-
if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
|
|
93
|
-
snowflakeComments.push({
|
|
94
|
-
path: filePath,
|
|
95
|
-
body: isMobile
|
|
96
|
-
? SNOWFLAKE_COMMENTS_MOBILE['styled-component']
|
|
97
|
-
: SNOWFLAKE_COMMENTS_WEB['styled-component'],
|
|
98
|
-
line: loc,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
snowflakeReport.approvedLocs.forEach((loc) => {
|
|
103
|
-
if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
|
|
104
|
-
approvedSnowflakeLocs.push(loc);
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
if (!isMobile) {
|
|
108
|
-
snowflakeReport.sxLocs.forEach((loc) => {
|
|
109
|
-
if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
|
|
110
|
-
snowflakeComments.push({
|
|
111
|
-
path: filePath,
|
|
112
|
-
body: SNOWFLAKE_COMMENTS_WEB['sx'],
|
|
113
|
-
line: loc,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
snowflakeReport.classNameLocs.forEach((loc) => {
|
|
118
|
-
if (checkIfDetectedSnowflakesInDiff(diffLocs, loc)) {
|
|
119
|
-
snowflakeComments.push({
|
|
120
|
-
path: filePath,
|
|
121
|
-
body: SNOWFLAKE_COMMENTS_WEB['className'],
|
|
122
|
-
line: loc,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}));
|
|
128
|
-
// Saving report
|
|
129
|
-
const snowflakeCount = snowflakeComments.length;
|
|
130
|
-
const report = (yield (0, fetchGraphql_1.default)((0, queryGenerators_1.generateFetchReportQuery)({ repoName: repoInfo.repo, prNumber })));
|
|
131
|
-
const reportData = (_a = report.data) === null || _a === void 0 ? void 0 : _a.fetchHdSnowflakeGuardReport;
|
|
132
|
-
if (reportData) {
|
|
133
|
-
yield (0, fetchGraphql_1.default)((0, queryGenerators_1.generateUpdateReportQuery)({
|
|
134
|
-
id: reportData.id,
|
|
135
|
-
latestCount: snowflakeCount,
|
|
136
|
-
approvedCount: approvedSnowflakeLocs.length,
|
|
137
|
-
}));
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
yield (0, fetchGraphql_1.default)((0, queryGenerators_1.generateCreateReportQuery)({
|
|
141
|
-
repoName: repoInfo.repo,
|
|
142
|
-
prNumber,
|
|
143
|
-
owner: repoInfo.owner,
|
|
144
|
-
originalCount: snowflakeCount,
|
|
145
|
-
latestCount: snowflakeCount,
|
|
146
|
-
approvedCount: approvedSnowflakeLocs.length,
|
|
147
|
-
}));
|
|
148
|
-
}
|
|
149
|
-
// No snowflakes detected
|
|
150
|
-
// Create success check-run
|
|
151
|
-
if (snowflakeCount === 0) {
|
|
152
|
-
return context.octokit.checks.create(Object.assign(Object.assign({}, repoInfo), { name: 'SnowflakeGuard/Check', head_sha: context.payload.pull_request.head.sha, status: 'completed', conclusion: 'success' }));
|
|
153
|
-
}
|
|
154
|
-
// Snowflakes detected
|
|
155
|
-
// Create failed check-run & comment
|
|
156
|
-
yield context.octokit.checks.create(Object.assign(Object.assign({}, repoInfo), { name: 'SnowflakeGuard/Check', head_sha: context.payload.pull_request.head.sha, status: 'completed', conclusion: 'failure' }));
|
|
157
|
-
return context.octokit.pulls.createReview(Object.assign(Object.assign({}, repoInfo), { pull_number: prNumber, commit_id: context.payload.pull_request.head.sha, event: 'COMMENT', body: 'Snowflake Guard Bot has detected some snowflakes in this PR. Please review the following comments.', comments: snowflakeComments }));
|
|
158
|
-
}));
|
|
159
|
-
app.on('pull_request_review.submitted', (context) => {
|
|
160
|
-
const submittedType = context.payload.review.state;
|
|
161
|
-
const submittedUser = context.payload.review.user.login;
|
|
162
|
-
if (submittedType !== 'approved' ||
|
|
163
|
-
!APPROVED_USER_LIST.includes(submittedUser)) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
return context.octokit.checks.create({
|
|
167
|
-
repo: context.payload.repository.name,
|
|
168
|
-
owner: context.payload.repository.owner.login,
|
|
169
|
-
name: 'SnowflakeGuard/Check',
|
|
170
|
-
head_sha: context.payload.pull_request.head.sha,
|
|
171
|
-
status: 'completed',
|
|
172
|
-
conclusion: 'success',
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { 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,135 +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 flowParser = __importStar(require("./parsers/flow"));
|
|
41
|
-
const tsParser = __importStar(require("./parsers/typescript"));
|
|
42
|
-
const constants_1 = require("./reports/mobile/constants");
|
|
43
|
-
const constants_2 = require("./reports/constants");
|
|
44
|
-
const reportCustomStyleProperties_1 = __importDefault(require("./reports/mobile/reportCustomStyleProperties"));
|
|
45
|
-
const reportStyledComponents_1 = __importDefault(require("./reports/mobile/reportStyledComponents"));
|
|
46
|
-
const parseMobileSource = (source) => {
|
|
47
|
-
let hasHeroDesignImport = false;
|
|
48
|
-
let hasStyledComponentsImport = false;
|
|
49
|
-
const componentList = {};
|
|
50
|
-
let styledAliasName = 'styled';
|
|
51
|
-
let styledComponentLocs = [];
|
|
52
|
-
let styleLocs = [];
|
|
53
|
-
let violatingAttributes = [];
|
|
54
|
-
const approvedInlineStyleCmts = [];
|
|
55
|
-
const approvedStyledComponentLocs = [];
|
|
56
|
-
const ast = recast.parse(source, {
|
|
57
|
-
parser: source.includes('@flow') ? flowParser : tsParser,
|
|
58
|
-
});
|
|
59
|
-
recast.visit(ast, {
|
|
60
|
-
visitImportDeclaration(path) {
|
|
61
|
-
this.traverse(path);
|
|
62
|
-
const importedFrom = path.value.source.value;
|
|
63
|
-
// Check if file imports components from '@hero-design/rn'
|
|
64
|
-
if (importedFrom === '@hero-design/rn') {
|
|
65
|
-
recast.visit(path.node, {
|
|
66
|
-
visitImportSpecifier(importPath) {
|
|
67
|
-
this.traverse(importPath);
|
|
68
|
-
if (constants_1.HD_MOBILE_COMPONENTS.includes(importPath.value.imported.name)) {
|
|
69
|
-
componentList[importPath.value.local.name] =
|
|
70
|
-
importPath.value.imported.name;
|
|
71
|
-
hasHeroDesignImport = true;
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
// Check if file imports from '@emotion/native'
|
|
77
|
-
if (importedFrom === '@emotion/native') {
|
|
78
|
-
recast.visit(path.node, {
|
|
79
|
-
visitImportDefaultSpecifier(importPath) {
|
|
80
|
-
this.traverse(importPath);
|
|
81
|
-
styledAliasName = importPath.value.local.name;
|
|
82
|
-
hasStyledComponentsImport = true;
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
visitComment(path) {
|
|
88
|
-
this.traverse(path);
|
|
89
|
-
const comment = path.value.value;
|
|
90
|
-
if (comment
|
|
91
|
-
.toLowerCase()
|
|
92
|
-
.includes(constants_2.APPROVED_INLINE_STYLE_COMMENT.toLowerCase())) {
|
|
93
|
-
approvedInlineStyleCmts.push({
|
|
94
|
-
loc: path.value.loc.start.line,
|
|
95
|
-
comment,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
if (comment
|
|
99
|
-
.toLowerCase()
|
|
100
|
-
.includes(constants_2.APPROVED_STYLED_COMPONENTS_COMMENT.toLowerCase())) {
|
|
101
|
-
approvedStyledComponentLocs.push(path.value.loc.start.line);
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
});
|
|
105
|
-
const isNotApprovedStyledComponentSnowflakes = (loc) => !approvedStyledComponentLocs.includes(loc - 1);
|
|
106
|
-
if (hasHeroDesignImport) {
|
|
107
|
-
// Case 1: Using style and other style config objects to customise components
|
|
108
|
-
const customPropLocs = (0, reportCustomStyleProperties_1.default)(ast, componentList, {
|
|
109
|
-
styleCmts: approvedInlineStyleCmts,
|
|
110
|
-
});
|
|
111
|
-
styleLocs = [
|
|
112
|
-
...new Set([
|
|
113
|
-
...customPropLocs.style,
|
|
114
|
-
...customPropLocs.barStyle,
|
|
115
|
-
...customPropLocs.containerStyle,
|
|
116
|
-
...customPropLocs.textStyle,
|
|
117
|
-
]),
|
|
118
|
-
];
|
|
119
|
-
// Case 2: 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
|
-
styleLocs,
|
|
127
|
-
styledComponentLocs,
|
|
128
|
-
approvedLocs: [
|
|
129
|
-
...approvedInlineStyleCmts.map((cmt) => cmt.loc),
|
|
130
|
-
...approvedStyledComponentLocs,
|
|
131
|
-
],
|
|
132
|
-
violatingAttributes,
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
exports.default = parseMobileSource;
|
package/lib/src/parseSource.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { CompoundComponentName } from './reports/types';
|
|
2
|
-
import type { InlineStyleProps } from './reports/reportInlineStyle';
|
|
3
|
-
declare const parseSource: (source: string) => {
|
|
4
|
-
classNameLocs: number[];
|
|
5
|
-
styleLocs: number[];
|
|
6
|
-
sxLocs: number[];
|
|
7
|
-
styledComponentLocs: number[];
|
|
8
|
-
approvedLocs: number[];
|
|
9
|
-
violatingAttributes: {
|
|
10
|
-
attributeName: string;
|
|
11
|
-
attributeValue: string | null;
|
|
12
|
-
inlineStyleProps: InlineStyleProps;
|
|
13
|
-
componentName: CompoundComponentName;
|
|
14
|
-
loc: number | undefined;
|
|
15
|
-
}[];
|
|
16
|
-
};
|
|
17
|
-
export default parseSource;
|