We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5886719 commit 792c356Copy full SHA for 792c356
1 file changed
CONTRIBUTING.md
@@ -299,6 +299,27 @@ local function check_name(name)
299
end
300
```
301
302
+Prefer if-then-error over assertions:
303
+
304
+```lua
305
+-- bad
306
+local function some_func(name)
307
+ -- string concatenation happens on good- and failure-case
308
+ assert(type(name) == "string", "expected name to be a string, got " .. type(name))
309
310
+ -- do work
311
+end
312
313
+-- good
314
315
+ if type(name) ~= "string" then
316
+ error("expected name to be a string, got " .. type(name))
317
+ end
318
319
320
321
+```
322
323
Follow the return values conventions: Lua supports multiple return values, and
324
by convention, handles recoverable errors by returning `nil` plus a `string`
325
describing the error:
0 commit comments