Skip to content

Commit 10a23df

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

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

src/cfengine_cli/lint.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
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"]
22+
2023
def lint_cfbs_json(filename) -> int:
2124
assert os.path.isfile(filename)
2225
assert filename.endswith("cfbs.json")
@@ -98,7 +101,36 @@ def _single_node_checks(filename, lines, node):
98101
f"Deprecation: Use 'if' instead of 'ifvarclass' at {filename}:{line}:{column}"
99102
)
100103
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
102134
return 0
103135

104136
def _walk(filename, lines, node) -> int:

0 commit comments

Comments
 (0)