forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathno-bad-gdpr-comment.js
More file actions
51 lines (51 loc) · 2.17 KB
/
no-bad-gdpr-comment.js
File metadata and controls
51 lines (51 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
var noBadGDPRComment = {
create: function (context) {
var _a;
return _a = {},
_a['Program'] = function (node) {
for (var _i = 0, _a = node.comments; _i < _a.length; _i++) {
var comment = _a[_i];
if (comment.type !== 'Block' || !comment.loc) {
continue;
}
if (!comment.value.includes('__GDPR__')) {
continue;
}
var dataStart = comment.value.indexOf('\n');
var data = comment.value.substring(dataStart);
var gdprData = void 0;
try {
var jsonRaw = "{ ".concat(data, " }");
gdprData = JSON.parse(jsonRaw);
}
catch (e) {
context.report({
loc: { start: comment.loc.start, end: comment.loc.end },
message: 'GDPR comment is not valid JSON',
});
}
if (gdprData) {
var len = Object.keys(gdprData).length;
if (len !== 1) {
context.report({
loc: { start: comment.loc.start, end: comment.loc.end },
message: "GDPR comment must contain exactly one key, not ".concat(Object.keys(gdprData).join(', ')),
});
}
}
}
},
_a;
},
};
module.exports = {
rules: {
'no-bad-gdpr-comment': noBadGDPRComment, // Ensure correct structure
},
};