Skip to content

Commit 9a01198

Browse files
Merge pull request #850 from rescript-association/todo-warn-error
Add docs for %todo and -warn-error
2 parents e407ce1 + c1bcc5a commit 9a01198

File tree

6 files changed

+76
-11
lines changed

6 files changed

+76
-11
lines changed

compilers/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compilers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"rescript-1000": "npm:[email protected]",
1111
"rescript-1010": "npm:[email protected]",
1212
"rescript-1100": "npm:[email protected]",
13-
"rescript-1110": "npm:[email protected].6",
13+
"rescript-1110": "npm:[email protected].8",
1414
"rescript-820": "npm:[email protected]",
1515
"rescript-902": "npm:[email protected]",
1616
"rescript-912": "npm:[email protected]"

misc_docs/syntax/extension_todo.mdx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
id: "todo"
3+
keywords: ["todo"]
4+
name: "%todo"
5+
summary: "This is the `todo` extension point."
6+
category: "extensionpoints"
7+
---
8+
9+
**Since 11.1**
10+
11+
`%todo` is used to tell the compiler that some code still needs to be implemented.
12+
13+
<CodeTab labels={["ReScript", "JS Output"]}>
14+
15+
```res
16+
let implementMeLater = (): string => %todo("This should return a string eventually.")
17+
18+
let x = implementMeLater()
19+
20+
Console.log(x->String.includes("x"))
21+
```
22+
23+
```js
24+
var Js_exn = require("./stdlib/js_exn.js");
25+
26+
function implementMeLater() {
27+
return Js_exn.raiseError("playground.res:1:37-42 - Todo: This should return a string eventually.");
28+
}
29+
30+
var x = Js_exn.raiseError("playground.res:1:37-42 - Todo: This should return a string eventually.");
31+
32+
console.log(x.includes("x"));
33+
```
34+
35+
</CodeTab>
36+
37+
It can also be used without a text message:
38+
39+
```res
40+
let implementMeLater = (): string => %todo
41+
```
42+
43+
This will crash when executed. We suggest to [promote the warning to an error](/docs/manual/latest/build-overview#compile-with-stricter-errors-in-ci) when building for production.
44+
45+
### References
46+
47+
* [Stricter compilation in CI](/docs/manual/latest/build-overview#compile-with-stricter-errors-in-ci)
48+
* [Extension Point Attributes](/docs/manual/latest/attribute#extension-point)

pages/docs/manual/latest/build-overview.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,15 @@ If you ever get into a stale build for edge-case reasons, use:
6969
```sh
7070
rescript clean
7171
```
72+
73+
## Compile with stricter errors in CI
74+
75+
**Since 11.1**
76+
77+
You may want to compile your project with stricter rules for production, than when developing. With the `-warn-error` build flag, this can easily be done, for instance in a continuous integration script. E.g.:
78+
79+
```sh
80+
rescript -warn-error +110
81+
```
82+
83+
Here, warning number 110, which is triggered when a [`%todo`](/syntax-lookup#todo) has been found, gets promoted to an error. The full list of warning numbers can be found [here](/docs/manual/latest/warning-numbers).

pages/docs/manual/latest/interop-cheatsheet.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ This is a glossary with examples. All the features are described by later pages.
5151

5252
- [`%debugger`](embed-raw-javascript#debugger)
5353
- [`%external`](bind-to-global-js-values#special-global-values)
54-
<!-- - `%node` -->
55-
<!-- - `%obj` -->
5654
- [`%raw`](embed-raw-javascript#paste-raw-js-code)
5755
- [`%re`](primitive-types#regular-expression)
56+
- [`%todo`](/syntax-lookup#todo)
5857

5958
## Raw JS
6059

src/common/WarningFlagDescription.res

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ let numeric = [
7070
(107, "Integer literal exceeds the range of representable integers of type int"),
7171
(108, "Uninterpreted delimiters (for unicode)"),
7272
(109, "Toplevel expression has unit type"),
73+
(110, "Todo found"),
7374
]
7475

7576
let letterAll = numeric->Belt.Array.map(fst)
@@ -226,7 +227,12 @@ module Parser = {
226227
| _ => ()
227228
}
228229

229-
ret
230+
ret->Belt.SortArray.stableSortBy((v1, v2) => {
231+
let a = v1.flag->Belt.Int.fromString
232+
let b = v2.flag->Belt.Int.fromString
233+
234+
compare(a, b)
235+
})
230236
}
231237

232238
let parse = (input: string): result<array<token>, string> =>

0 commit comments

Comments
 (0)