Skip to content

Commit b0b9820

Browse files
committed
lint: Added more linting rules
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
1 parent 15e2bbb commit b0b9820

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/cfengine_cli/lint.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from cfbs.validate import validate_config
1818
from cfbs.cfbs_config import CFBSConfig
1919

20+
DEPRECATED_PROMISE_TYPES=["defaults", "guest_environments"]
21+
ALLOWED_BUNDLE_TYPES=["agent", "common", "monitor", "server", "edit_line"]
2022

2123
def lint_cfbs_json(filename) -> int:
2224
assert os.path.isfile(filename)
@@ -103,7 +105,36 @@ def _single_node_checks(filename, lines, node):
103105
f"Deprecation: Use 'if' instead of 'ifvarclass' at {filename}:{line}:{column}"
104106
)
105107
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
107138
return 0
108139

109140

0 commit comments

Comments
 (0)