]> git.puffer.fish Git - matthieu/frr.git/commitdiff
tools: Catch JSON keys with whitespaces
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Mon, 31 Jan 2022 12:59:03 +0000 (14:59 +0200)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Thu, 3 Feb 2022 08:47:32 +0000 (10:47 +0200)
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
tools/coccinelle/json_object_add_no_whitespace.cocci [new file with mode: 0644]

diff --git a/tools/coccinelle/json_object_add_no_whitespace.cocci b/tools/coccinelle/json_object_add_no_whitespace.cocci
new file mode 100644 (file)
index 0000000..61250aa
--- /dev/null
@@ -0,0 +1,17 @@
+// Catch whitespaces in JSON keys
+
+@r@
+identifier json;
+constant key;
+identifier func =~ "json_object_";
+position p;
+@@
+
+func(json, key, ...)@p
+
+@script:python@
+fmt << r.key;
+p << r.p;
+@@
+if " " in str(fmt):
+    print("Whitespace detected in JSON keys %s:%s:%s:%s" % (p[0].file, p[0].line, p[0].column, fmt))