|
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"] |
20 | 22 |
|
21 | 23 | def lint_cfbs_json(filename) -> int: |
22 | 24 | assert os.path.isfile(filename) |
@@ -103,7 +105,36 @@ def _single_node_checks(filename, lines, node): |
103 | 105 | f"Deprecation: Use 'if' instead of 'ifvarclass' at {filename}:{line}:{column}" |
104 | 106 | ) |
105 | 107 | return 1 |
106 | | - # TODO add more rules here |
| 108 | + if node.type == "promise_guard": |
| 109 | + assert _text(node) and len(_text(node)) > 1 and _text(node)[-1] == ":" |
| 110 | + promise_type = _text(node)[0:-1] |
| 111 | + if promise_type in DEPRECATED_PROMISE_TYPES: |
| 112 | + _highlight_range(node, lines) |
| 113 | + print( |
| 114 | + f"Deprecation: Promise type '{promise_type}' is deprecated at {filename}:{line}:{column}" |
| 115 | + ) |
| 116 | + return 1 |
| 117 | + if node.type == "bundle_block_name": |
| 118 | + if _text(node) != _text(node).lower(): |
| 119 | + _highlight_range(node, lines) |
| 120 | + print( |
| 121 | + f"Convention: Bundle name should be lowercase at {filename}:{line}:{column}" |
| 122 | + ) |
| 123 | + return 1 |
| 124 | + if node.type == "promise_block_name": |
| 125 | + if _text(node) != _text(node).lower(): |
| 126 | + _highlight_range(node, lines) |
| 127 | + print( |
| 128 | + f"Convention: Promise type should be lowercase at {filename}:{line}:{column}" |
| 129 | + ) |
| 130 | + return 1 |
| 131 | + if node.type == "bundle_block_type": |
| 132 | + if _text(node) not in ALLOWED_BUNDLE_TYPES: |
| 133 | + _highlight_range(node, lines) |
| 134 | + print( |
| 135 | + f"Error: Bundle type must be one of ({', '.join(ALLOWED_BUNDLE_TYPES)}), not '{_text(node)}' at {filename}:{line}:{column}" |
| 136 | + ) |
| 137 | + return 1 |
107 | 138 | return 0 |
108 | 139 |
|
109 | 140 |
|
|
0 commit comments