|
17 | 17 | from cfbs.validate import validate_config |
18 | 18 | from cfbs.cfbs_config import CFBSConfig |
19 | 19 |
|
| 20 | +DEPRECATED_PROMISE_TYPES=["defaults", "guest_environments"] |
| 21 | +ALLOWED_BUNDLE_TYPES=["agent", "common", "monitor", "server", "edit_line"] |
| 22 | + |
20 | 23 | def lint_cfbs_json(filename) -> int: |
21 | 24 | assert os.path.isfile(filename) |
22 | 25 | assert filename.endswith("cfbs.json") |
@@ -98,7 +101,36 @@ def _single_node_checks(filename, lines, node): |
98 | 101 | f"Deprecation: Use 'if' instead of 'ifvarclass' at {filename}:{line}:{column}" |
99 | 102 | ) |
100 | 103 | return 1 |
101 | | - # TODO add more rules here |
| 104 | + if node.type == "promise_guard": |
| 105 | + assert _text(node) and len(_text(node)) > 1 and _text(node)[-1] == ":" |
| 106 | + promise_type = _text(node)[0:-1] |
| 107 | + if promise_type in DEPRECATED_PROMISE_TYPES: |
| 108 | + _highlight_range(node, lines) |
| 109 | + print( |
| 110 | + f"Deprecation: Promise type '{promise_type}' is deprecated at {filename}:{line}:{column}" |
| 111 | + ) |
| 112 | + return 1 |
| 113 | + if node.type == "bundle_block_name": |
| 114 | + if _text(node) != _text(node).lower(): |
| 115 | + _highlight_range(node, lines) |
| 116 | + print( |
| 117 | + f"Convention: Bundle name should be lowercase at {filename}:{line}:{column}" |
| 118 | + ) |
| 119 | + return 1 |
| 120 | + if node.type == "promise_block_name": |
| 121 | + if _text(node) != _text(node).lower(): |
| 122 | + _highlight_range(node, lines) |
| 123 | + print( |
| 124 | + f"Convention: Promise type should be lowercase at {filename}:{line}:{column}" |
| 125 | + ) |
| 126 | + return 1 |
| 127 | + if node.type == "bundle_block_type": |
| 128 | + if _text(node) not in ALLOWED_BUNDLE_TYPES: |
| 129 | + _highlight_range(node, lines) |
| 130 | + print( |
| 131 | + f"Error: Bundle type must be one of ({', '.join(ALLOWED_BUNDLE_TYPES)}), not '{_text(node)}' at {filename}:{line}:{column}" |
| 132 | + ) |
| 133 | + return 1 |
102 | 134 | return 0 |
103 | 135 |
|
104 | 136 | def _walk(filename, lines, node) -> int: |
|
0 commit comments