Skip to content

Commit 58bcb48

Browse files
authored
Update README.md
1 parent 658cf60 commit 58bcb48

File tree

1 file changed

+225
-3
lines changed

1 file changed

+225
-3
lines changed

server/src/rules/README.md

Lines changed: 225 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ true == 1;
110110
### [Disallowed operators](rules/binaryExpression.ts)
111111
**Error message**: `${operator} is not allowed`
112112

113-
Only permitted operators defined in Source is allowed. Binary operators like `^` or `instanceof` is banned.
113+
Only permitted operators defined in Source is allowed. Binary operators like `^` or `instanceof` is banned, unary operators like `typeof` is also banned.
114114
```javascript
115115
100^5;
116+
typeof 1 === "number"
116117
```
117-
The expression `100^5` will throw an error.
118+
The two expressions will throw an error.
118119

119120
### [Only string or number in equality checks](rules/binaryExpression.ts)
120121
**Error message**: `Expected string or number on left/right hand side of operation, got ${type}`
@@ -153,8 +154,229 @@ can be reassigned, hence it will be a runtime error.
153154
### [Not enough parameters](rules/callExpression.ts)
154155
**Error message**: `Expected ${num_args} or more arguments, but got ${num_supplied_args}`
155156

156-
Detects when a function application has not enough parameters.
157+
Detects when a function application has not enough parameters. Currently does not work for anonymous lambdas.
157158
```javascript
158159
display();
159160
```
160161
The call to `display` needs at least 1 element.
162+
163+
### [Incomplete ternary](rules/conditionalExpression.ts)
164+
**Error message**: `Incomplete ternary`
165+
166+
Detects when a ternary does not have a consequent or alternate case.
167+
```javascript
168+
b => b ? 1;
169+
```
170+
`b ? 1` throws an error, as there is no alternate case.
171+
172+
### [No continue statements](rules/continueStatement.ts)
173+
**Error message**: `Continue statements are not allowed`
174+
175+
Bans continue statements before Source 3
176+
```javascript
177+
continue;
178+
```
179+
`continue` will throw an error.
180+
181+
### [No for statements](rules/forStatement.ts)
182+
**Error message**: `For statements are not allowed`
183+
184+
Bans for statements before Source 3
185+
```javascript
186+
for(let i = 0; i < 10; i++) {}
187+
```
188+
`for(...)` will throw an error.
189+
190+
### [Missing block statements](rules/forStatement.ts)
191+
**Error message**: `Missing curly braces around for/while/if/else`
192+
193+
Detects missing curly braces for some statements
194+
```javascript
195+
if (1 === 1)
196+
display("1 is equal to 1");
197+
```
198+
The whole expression will throw an error.
199+
200+
### [Incomplete for loop](rules/forStatement.ts)
201+
**Error message**: `Incomplete for loop`
202+
203+
Detects if a for loop is missing any parts
204+
```javascript
205+
for (let i = 0; i < 10;) {
206+
}
207+
```
208+
`for(...)` will throw an error.
209+
210+
### [Missing function name](rules/functionDeclaration.ts)
211+
**Error message**: `Missing function name`
212+
213+
Detects if function declaration is incomplete
214+
```javascript
215+
function () {}
216+
```
217+
The whole expression will throw an error.
218+
219+
### [Terminal rest element](rules/functionDeclaration.ts)
220+
**Error message**: `No params allowed after rest element`
221+
222+
If a function has a rest parameter, it must be the last parameter.
223+
```javascript
224+
function foo(arg1, ...arg2, arg3) {}
225+
(arg1, ...arg2, arg3) => {};
226+
```
227+
Both cases will throw an error around `arg3`
228+
229+
### [Identifier not declared](rules/identifier.ts)
230+
**Error message**: `Name ${name} not declared`
231+
232+
Detects if there is a declaration for an identifier in its scope.
233+
```javascript
234+
{
235+
const x = 1;
236+
{
237+
display(x);
238+
}
239+
}
240+
display(x);
241+
```
242+
The first `x` in `display(x)` should not throw an error, but the second one should.
243+
244+
### [Missing else case](rules/ifStatement.ts)
245+
**Error message**: `Missing "else" in "if-else" statement`
246+
247+
`else` case is required in an if statement before Source 3
248+
```javascript
249+
if (true) {
250+
display("hello world");
251+
}
252+
```
253+
An error will be thrown around the body of the if statement.
254+
255+
### [No module name](rules/importDeclaration.ts)
256+
**Error message**: `Expected module name`
257+
258+
Imports require the module name.
259+
```javascript
260+
import { black }
261+
```
262+
An error will be thrown around the whole import statement.
263+
264+
### [Missing closing string](rules/literal.ts)
265+
**Error message**: `Incomplete string expression`
266+
267+
Strings must be closed within the same line
268+
```javascript
269+
"hello world
270+
";
271+
```
272+
An error will be thrown on both lines.
273+
274+
### [No null literals](rules/literal.ts)
275+
**Error message**: `Null literals are not allowed`
276+
277+
Nulls are not allowed in Source 1.
278+
```javascript
279+
display(null);
280+
```
281+
An error will be thrown around `null`.
282+
283+
### [No member access](rules/memberExpression.ts)
284+
**Error message**: `Member access expressions are not allowed`
285+
286+
Member access with square brackets `[]` is not allowed before source 3.
287+
```javascript
288+
"hello world"[0];
289+
```
290+
An error will be thrown around the whole expression.
291+
292+
### [No dot abbreviations](rules/memberExpression.ts)
293+
**Error message**: `No dot abbreviations`
294+
295+
Source prohibits usage of dot access in any case.
296+
```javascript
297+
display("hello world".length);
298+
```
299+
An error will be thrown around the whole expression.
300+
301+
### [Non integer member access](rules/memberExpression.ts)
302+
**Error message**: `Expected integer as array index, got ${type}`
303+
304+
Array access must use non negative integers
305+
```javascript
306+
const arr = [1,2,3];
307+
arr[undefined]; // Expected non negative integer as array index, got undefined.
308+
arr["test"]; // Expected non negative integer as array index, got string.
309+
arr[1.1]; // Expected non negative integer as array index, got float.
310+
arr[-1]; // Expected non negative integer as array index, got negative number.
311+
```
312+
Errors are shown in the comments.
313+
314+
### [No return value](rules/returnStatement.ts)
315+
**Error message**: `Missing value in return statement`
316+
317+
Returns statements must return a value in Source.
318+
```javascript
319+
function foo() {
320+
return;
321+
}
322+
```
323+
An error will be thrown around the `return` statement.
324+
325+
### [No spread syntax](rules/spreadElement.ts)
326+
**Error message**: `Spread syntax is only allowed when supplying arguments to a function`
327+
328+
The spread syntax `...` can only be used directly inside a function call as a parameter.
329+
```javascript
330+
const x = [1,2,3];
331+
display(list(...x)); // Valid
332+
display(list((...x)); // Not valid
333+
```
334+
The second use of the spread syntax will throw an error.
335+
336+
### [No expressions in template literals](rules/templateLiteral.ts)
337+
**Error message**: `Expressions not allowed in template literal`
338+
339+
In Source, template literals are only used for multiline string, they cannot contain expressions.
340+
```javascript
341+
const x = `10 * 10 = ${10*10}`
342+
```
343+
The expression `10*10` will throw an error.
344+
345+
### [No multiple declarations](rules/variableDeclaration.ts)
346+
**Error message**: `Multiple declarations not allowed`
347+
348+
In Source, only 1 declaration is allowed in each variable declarator.
349+
```javascript
350+
const x = 1, y = 2, z = 3;
351+
```
352+
The whole statement will throw an error.
353+
354+
### [Incomplete variable declaration](rules/variableDeclaration.ts)
355+
**Error message**: `Incomplete variable declaration`
356+
357+
Detects whether left and right side of variable declaration in present;
358+
```javascript
359+
const x;
360+
```
361+
The whole statement will throw an error.
362+
363+
### [No let declaration](rules/variableDeclaration.ts)
364+
**Error message**: `Use keyword "const" instead to declare a constant`
365+
366+
Before Source 3, variables can only be declared with `const`
367+
```javascript
368+
let x = 1;
369+
```
370+
The whole statement will throw an error.
371+
372+
### [No while statement](rules/whileStatement.ts)
373+
**Error message**: `While statements are not allowed`
374+
375+
Before Source 3, while statements are not allowed.
376+
```javascript
377+
while(true) {
378+
display("hi")
379+
}
380+
```
381+
`while(...)` will throw an error.
382+

0 commit comments

Comments
 (0)