|
| 1 | +# Rules |
| 2 | +Documentation for all diagnostics sent back to the client. |
| 3 | +## Warnings |
| 4 | + |
| 5 | +### [No unused variables](ast.ts) |
| 6 | +**Error message**: `Unused name` |
| 7 | +Flags variables that are declared but not used within the code. |
| 8 | +```javascript |
| 9 | +const pi = 3.14; |
| 10 | +display(5*5*3.14); |
| 11 | +``` |
| 12 | +The variable `pi` should have a warning. |
| 13 | + |
| 14 | +## Errors |
| 15 | + |
| 16 | +### [Missing semicolon](ast.ts) |
| 17 | +Identifies statements that are missing semicolons. |
| 18 | +```javascript |
| 19 | +const x = 1; |
| 20 | +``` |
| 21 | +The line ending should have an error. |
| 22 | + |
| 23 | +### [Trailing comma](ast.ts) |
| 24 | +Identifies expressions that have trailing commas. |
| 25 | +```javascript |
| 26 | +const x = [1,2,3,]; |
| 27 | +``` |
| 28 | +The comma after `3` should have an error. |
| 29 | + |
| 30 | +### [No namespace/default imports](ast.ts) |
| 31 | +**Error message**: `Only normal imports are allowed` |
| 32 | +Bans namespace and default imports. |
| 33 | +```javascript |
| 34 | +import * as rune from "rune"; |
| 35 | +import black from "rune"; |
| 36 | +``` |
| 37 | +Both lines will throw an error around the identifier. |
| 38 | + |
| 39 | +### [Unexpected token in function parameters](ast.ts) |
| 40 | +**Error message**: `Unexpected token` |
| 41 | +Only allows identifiers as function parameters |
| 42 | +```javascript |
| 43 | +function foo(a+b) {} |
| 44 | +``` |
| 45 | +`a+b` will throw an error. |
| 46 | + |
| 47 | +### [Redeclaration of variables](ast.ts) |
| 48 | +**Error message**: `Identifier '${name}' has already been declared` |
| 49 | +Bans redeclaration of names in the same scope |
| 50 | +```javascript |
| 51 | +let x = 1; |
| 52 | +let x = 2; |
| 53 | +``` |
| 54 | +The second `x` will throw an error. |
| 55 | + |
| 56 | +### [No array expressions](rules/arrayExpression.ts) |
| 57 | +**Error message**: `Array expressions are not allowed` |
| 58 | +Bans array expressions before Source 3 |
| 59 | +```javascript |
| 60 | +const x = [1,2,3]; |
| 61 | +``` |
| 62 | +The array `[1,2,3];` will throw an error. |
| 63 | + |
| 64 | +### [No empty elements](rules/arrayExpression.ts) |
| 65 | +**Error message**: `No holes are allowed in array literals` |
| 66 | +Bans empty elements in array expressions |
| 67 | +```javascript |
| 68 | +[1,,3]; |
| 69 | +``` |
| 70 | +The array `[1,,3]` will throw an error. |
| 71 | + |
| 72 | +### [Constant reassignment](rules/assignmentExpression.ts) |
| 73 | +**Error message**: `Cannot assign new value to constant ${name}` |
| 74 | +Bans reassignment to constant variable |
| 75 | +```javascript |
| 76 | +const x = 1; |
| 77 | +x = 2; |
| 78 | +``` |
| 79 | +The second `x` will throw an error |
| 80 | + |
| 81 | +### [Incomplete binary expression](rules/binaryExpression.ts) |
| 82 | +**Error message**: `Incomplete binary expression` |
| 83 | +Detects when a binary expression is missing a left/right node |
| 84 | +```javascript |
| 85 | +10 + ; |
| 86 | +5 === ; |
| 87 | +``` |
| 88 | +Both lines will throw an error |
| 89 | + |
| 90 | +### [Force strict equality](rules/binaryExpression.ts) |
| 91 | +**Error message**: `Use ===/!== instead of ==/!=` |
| 92 | +Bans the use of loose equality checks `==` and `!=` |
| 93 | +```javascript |
| 94 | +true == 1; |
| 95 | +``` |
| 96 | + |
| 97 | +### [Disallowed operators](rules/binaryExpression.ts) |
| 98 | +**Error message**: `${operator} is not allowed` |
| 99 | +Only permitted operators defined in Source is allowed. Binary operators like `^` or `instanceof` is banned. |
| 100 | +```javascript |
| 101 | +100^5; |
| 102 | +``` |
| 103 | +The expression `100^5` will throw an error. |
| 104 | + |
| 105 | +### [Only string or number in equality checks](rules/binaryExpression.ts) |
| 106 | +**Error message**: `Expected string or number on left/right hand side of operation, got ${type}` |
| 107 | +Before Source 3, only strings or numbers can be in equality checks |
| 108 | +```javascript |
| 109 | +true === 1; // Expected string or number on left hand side of operation, got boolean |
| 110 | +true === (1 === 1); // Expected string or number on left hand side of operation, got boolean |
| 111 | +(1 === 1) === undefined; // Expected string or number on right hand side of operation, got undefined |
| 112 | +"string" === 1; // Expected string on left hand side of operation, got number |
| 113 | +``` |
| 114 | +Errors are shown in the comments. |
| 115 | + |
| 116 | +### [No break statements](rules/breakStatement.ts) |
| 117 | +**Error message**: `Break statements are not allowed;` |
| 118 | +No break statements before Source 3 |
| 119 | +```javascript |
| 120 | +break; |
| 121 | +``` |
| 122 | +`break` will throw an error. |
| 123 | + |
| 124 | +### [Calling a non function](rules/callExpression.ts) |
| 125 | +**Error message**: `${name} is not a function` |
| 126 | +Cannot call identifiers that are not a function |
| 127 | +```javascript |
| 128 | +const x = 1; |
| 129 | +x(); |
| 130 | +let y = 1; |
| 131 | +y() |
| 132 | +``` |
| 133 | +The function application on `x` will throw an error, however the function application on `y` will not, as y |
| 134 | +can be reassigned, hence it will be a runtime error. |
| 135 | + |
| 136 | +### [Not enough parameters](rules/callExpression.ts) |
| 137 | +**Error message**: `Expected ${num_args} or more arguments, but got ${num_supplied_args}` |
| 138 | +Detects when a function application has not enough parameters. |
| 139 | +```javascript |
| 140 | +display(); |
| 141 | +``` |
| 142 | +The call to `display` needs at least 1 element. |
| 143 | + |
| 144 | +```javascript |
| 145 | +``` |
0 commit comments