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