Commit Diff


commit - 620fee9d279f77145b88073ecc432543fbbac7b7
commit + 4bdba0c89beaf1b4416b25d6d4ce09cfa21b35e1
blob - 3123be8dc2e7c680fd704526e10e328699e85d76
blob + e62724c834e856b3d4c91e319b50ef2b80ebdcca
--- README.md
+++ README.md
@@ -53,6 +53,7 @@ $ spatch --sp-file coccinelle/mmap_map_failed.cocci --
 
 - `tarantool/box/box_cfg_raw_access`
 - `tarantool/box/grant_guest_full_access`
+- `tarantool/box/missed_if_not_exist`
 - `tarantool/box/set_trigger_once`
 - `tarantool/crypto/insecure-hash-algorithm`
 - `tarantool/digest/insecure-hash-algorithm`
blob - /dev/null
blob + ccff8bd70d4567f125acf60970a68ccd8a67e786 (mode 644)
--- /dev/null
+++ rules/lua/tarantool/box/missed_if_not_exist.lua
@@ -0,0 +1,23 @@
+-- ok: missed_if_not_exist
+box.schema.space.create('tmp', { if_not_exists = true })
+-- ruleid: missed_if_not_exist
+box.schema.space.create('tmp', { })
+-- ruleid: missed_if_not_exist
+box.schema.space.create('tmp')
+
+-- ok: missed_if_not_exist
+box.schema.func.create('my_func', {
+    takes_raw_args = true,
+	if_not_exists = true,
+})
+-- ruleid: missed_if_not_exist
+box.schema.func.create('my_func', { takes_raw_args = true })
+
+local space
+space = box.schema.space.create('tmp', { if_not_exists = true })
+-- ok: missed_if_not_exist
+space:create_index('idx', { if_not_exists = true })
+
+space = box.schema.space.create('tmp', { if_not_exists = true })
+-- ruleid: missed_if_not_exist
+space:create_index('idx', { unique = true })
blob - /dev/null
blob + 2f963d9d1901495cceb573114935688235e6f7b5 (mode 644)
--- /dev/null
+++ rules/lua/tarantool/box/missed_if_not_exist.yaml
@@ -0,0 +1,24 @@
+rules:
+  - id: missed_if_not_exist
+    pattern-either:
+      - patterns:
+          - pattern-inside: box.schema.space.create(...)
+          - pattern-not: box.schema.space.create($NAME, { ..., if_not_exists = true, ... })
+      - patterns:
+          - pattern-inside: box.schema.func.create(...)
+          - pattern-not: box.schema.func.create($NAME, { ..., if_not_exists = true, ... })
+      #- pattern: |
+      #    $SPACE = box.schema.space.create(...)
+      #    $SPACE:create_index($NAME, { if_not_exists = true })
+    message: if_not_exist
+    languages: [lua]
+    severity: WARNING
+
+# TODO: box.schema.user.grant()
+# https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_schema/user_grant/
+# box.schema.user.create()
+# https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_schema/user_create/
+# box.schema.role.grant()
+# https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_schema/role_grant/
+# box.schema.sequence.create()
+# https://www.tarantool.io/en/doc/latest/how-to/db/sequences/