| 52 | } |
| 53 | |
| 54 | function* findErrorCodeAssertions(node, trail) { |
| 55 | if (Array.isArray(node)) { |
| 56 | for (let i = 0; i < node.length; i++) { |
| 57 | yield* findErrorCodeAssertions(node[i], [...trail, i]); |
| 58 | } |
| 59 | return; |
| 60 | } |
| 61 | if (node && typeof node === 'object') { |
| 62 | if (node.check === 'error_code') { |
| 63 | if (typeof node.value === 'string') { |
| 64 | yield { code: node.value, trail: [...trail, 'value'] }; |
| 65 | } |
| 66 | if (Array.isArray(node.allowed_values)) { |
| 67 | for (let i = 0; i < node.allowed_values.length; i++) { |
| 68 | const v = node.allowed_values[i]; |
| 69 | if (typeof v === 'string') { |
| 70 | yield { code: v, trail: [...trail, 'allowed_values', i] }; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | for (const key of Object.keys(node)) { |
| 76 | yield* findErrorCodeAssertions(node[key], [...trail, key]); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | function lintFile(filePath, { canonical, aliases }) { |
| 82 | const violations = []; |