Skip to content

Commit fbbc41b

Browse files
authored
Merge pull request #395 from Minnozz/document-warning-numbers
Document warning numbers
2 parents 05bf3cb + 034010d commit fbbc41b

File tree

13 files changed

+136
-58
lines changed

13 files changed

+136
-58
lines changed

data/sidebar_manual_latest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
"build-external-stdlib",
5757
"build-pinned-dependencies",
5858
"interop-with-js-build-systems",
59-
"build-performance"
59+
"build-performance",
60+
"warning-numbers"
6061
],
6162
"Guides": [
6263
"converting-from-js"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
id: "module-warning-decorator"
3+
keywords: ["warning", "decorator"]
4+
name: "@@warning"
5+
summary: "This is the `@@warning` decorator."
6+
category: "decorators"
7+
---
8+
9+
The `@@warning` decorator is used to modify the enabled compiler warnings for the current module. See [here](/docs/manual/latest/warning-numbers) for all available warning numbers.
10+
11+
### Examples
12+
13+
<CodeTab labels={["ReScript", "JS Output"]}>
14+
15+
```res
16+
// Disables warning 27 for the current module
17+
@@warning("-27")
18+
```
19+
20+
```js
21+
```
22+
23+
</CodeTab>
24+
25+
### References
26+
27+
* [Warning Numbers](/docs/manual/latest/warning-numbers)

pages/docs/manual/latest/attribute.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ let customTriple = foo => foo * 3
5959

6060
</CodeTab>
6161

62-
1. `@@warning("-27")` is a standalone attribute that annotates the entire file. Those attributes start with `@@`. Here, it carries the data `"-27"`.
62+
1. `@@warning("-27")` is a standalone attribute that annotates the entire file. Those attributes start with `@@`. Here, it carries the data `"-27"`. You can find a full list of all available warnings [here](./warning-numbers).
6363
2. `@unboxed` annotates the type definition.
6464
3. `@val` annotates the `external` statement.
6565
4. `@as("aria-label")` annotates the `ariaLabel` record field.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Selectively turn on/off certain warnings and/or turn them into hard errors. Exam
166166

167167
Turn off warning `44` and `102` (polymorphic comparison). Turn warning `5` (partial application whose result has function type and is ignored) into a hard error.
168168

169-
The warning number are shown in the build output when they're triggered. The complete list is [here](https://caml.inria.fr/pub/docs/manual-ocaml/comp.html#sec281), a little bit below. `100` and up are ReScript-specific.
169+
The warning numbers are shown in the build output when they're triggered. See [Warning Numbers](./warning-numbers) for the complete list.
170170

171171
## bsc-flags
172172

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: "Warning Numbers"
3+
description: "Available compiler warning numbers in ReScript"
4+
canonical: "/docs/manual/latest/warning-numbers"
5+
---
6+
7+
# Warning Numbers
8+
9+
You can configure which warnings the ReScript compiler generates
10+
[in the build configuration](/docs/manual/latest/build-configuration#warnings) or
11+
[using the `@@warning()` decorator](/syntax-lookup#module-warning-decorator).
12+
13+
<WarningTable />

src/common/Mdx.mjs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ var MdxChildren = {
7474
};
7575

7676
var Components = {
77-
t: (function (prim0, prim1, prim2, prim3, prim4, prim5, prim6, prim7, prim8, prim9, prim10, prim11, prim12, prim13, prim14, prim15, prim16, prim17, prim18, prim19, prim20, prim21, prim22, prim23, prim24, prim25, prim26) {
77+
t: (function (prim0, prim1, prim2, prim3, prim4, prim5, prim6, prim7, prim8, prim9, prim10, prim11, prim12, prim13, prim14, prim15, prim16, prim17, prim18, prim19, prim20, prim21, prim22, prim23, prim24, prim25, prim26, prim27) {
7878
var tmp = {};
7979
if (prim0 !== undefined) {
8080
tmp.Cite = Caml_option.valFromOption(prim0);
@@ -95,64 +95,67 @@ var Components = {
9595
tmp.CodeTab = Caml_option.valFromOption(prim5);
9696
}
9797
if (prim6 !== undefined) {
98-
tmp.p = Caml_option.valFromOption(prim6);
98+
tmp.WarningTable = Caml_option.valFromOption(prim6);
9999
}
100100
if (prim7 !== undefined) {
101-
tmp.li = Caml_option.valFromOption(prim7);
101+
tmp.p = Caml_option.valFromOption(prim7);
102102
}
103103
if (prim8 !== undefined) {
104-
tmp.h1 = Caml_option.valFromOption(prim8);
104+
tmp.li = Caml_option.valFromOption(prim8);
105105
}
106106
if (prim9 !== undefined) {
107-
tmp.h2 = Caml_option.valFromOption(prim9);
107+
tmp.h1 = Caml_option.valFromOption(prim9);
108108
}
109109
if (prim10 !== undefined) {
110-
tmp.h3 = Caml_option.valFromOption(prim10);
110+
tmp.h2 = Caml_option.valFromOption(prim10);
111111
}
112112
if (prim11 !== undefined) {
113-
tmp.h4 = Caml_option.valFromOption(prim11);
113+
tmp.h3 = Caml_option.valFromOption(prim11);
114114
}
115115
if (prim12 !== undefined) {
116-
tmp.h5 = Caml_option.valFromOption(prim12);
116+
tmp.h4 = Caml_option.valFromOption(prim12);
117117
}
118118
if (prim13 !== undefined) {
119-
tmp.ul = Caml_option.valFromOption(prim13);
119+
tmp.h5 = Caml_option.valFromOption(prim13);
120120
}
121121
if (prim14 !== undefined) {
122-
tmp.ol = Caml_option.valFromOption(prim14);
122+
tmp.ul = Caml_option.valFromOption(prim14);
123123
}
124124
if (prim15 !== undefined) {
125-
tmp.table = Caml_option.valFromOption(prim15);
125+
tmp.ol = Caml_option.valFromOption(prim15);
126126
}
127127
if (prim16 !== undefined) {
128-
tmp.thead = Caml_option.valFromOption(prim16);
128+
tmp.table = Caml_option.valFromOption(prim16);
129129
}
130130
if (prim17 !== undefined) {
131-
tmp.th = Caml_option.valFromOption(prim17);
131+
tmp.thead = Caml_option.valFromOption(prim17);
132132
}
133133
if (prim18 !== undefined) {
134-
tmp.td = Caml_option.valFromOption(prim18);
134+
tmp.th = Caml_option.valFromOption(prim18);
135135
}
136136
if (prim19 !== undefined) {
137-
tmp.blockquote = Caml_option.valFromOption(prim19);
137+
tmp.td = Caml_option.valFromOption(prim19);
138138
}
139139
if (prim20 !== undefined) {
140-
tmp.inlineCode = Caml_option.valFromOption(prim20);
140+
tmp.blockquote = Caml_option.valFromOption(prim20);
141141
}
142142
if (prim21 !== undefined) {
143-
tmp.strong = Caml_option.valFromOption(prim21);
143+
tmp.inlineCode = Caml_option.valFromOption(prim21);
144144
}
145145
if (prim22 !== undefined) {
146-
tmp.hr = Caml_option.valFromOption(prim22);
146+
tmp.strong = Caml_option.valFromOption(prim22);
147147
}
148148
if (prim23 !== undefined) {
149-
tmp.code = Caml_option.valFromOption(prim23);
149+
tmp.hr = Caml_option.valFromOption(prim23);
150150
}
151151
if (prim24 !== undefined) {
152-
tmp.pre = Caml_option.valFromOption(prim24);
152+
tmp.code = Caml_option.valFromOption(prim24);
153153
}
154154
if (prim25 !== undefined) {
155-
tmp.a = Caml_option.valFromOption(prim25);
155+
tmp.pre = Caml_option.valFromOption(prim25);
156+
}
157+
if (prim26 !== undefined) {
158+
tmp.a = Caml_option.valFromOption(prim26);
156159
}
157160
return tmp;
158161
})

src/common/Mdx.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ module Components = {
105105
"children": MdxChildren.t,
106106
"labels": option<array<string>>,
107107
}>,
108+
@as("WarningTable") @optional
109+
warningTable: React.component<props>,
108110
/* Common markdown elements */
109111
@optional
110112
p: React.component<props>,

src/common/Mdx.resi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module Components: {
3838
~intro: React.component<props>=?,
3939
~urlBox: React.component<{"text": string, "href": string, "children": MdxChildren.t}>=?,
4040
~codeTab: React.component<{"children": MdxChildren.t, "labels": option<array<string>>}>=?,
41+
~warningTable: React.component<props>=?,
4142
~p: React.component<props>=?,
4243
~li: React.component<props>=?,
4344
~h1: React.component<props>=?,

src/common/WarningFlagDescription.mjs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -259,47 +259,45 @@ var numeric = [
259259
],
260260
[
261261
101,
262-
"BuckleScript warning: Unused bs attributes"
262+
"Unused bs attributes"
263263
],
264264
[
265265
102,
266-
"BuckleScript warning: polymorphic comparison introduced (maybe unsafe)"
266+
"Polymorphic comparison introduced (maybe unsafe)"
267267
],
268268
[
269269
103,
270-
"BuckleScript warning: about fragile FFI definitions"
270+
"Fragile FFI definitions"
271271
],
272272
[
273273
104,
274-
"BuckleScript warning: bs.deriving warning with customized message "
274+
"bs.deriving warning with customized message "
275275
],
276276
[
277277
105,
278-
"BuckleScript warning: the external name is inferred from val name is unsafe from refactoring when changing value name"
278+
"External name is inferred from val name is unsafe from refactoring when changing value name"
279279
],
280280
[
281281
106,
282-
"BuckleScript warning: Unimplemented primitive used:"
282+
"Unimplemented primitive used:"
283283
],
284284
[
285285
107,
286-
"BuckleScript warning: Integer literal exceeds the range of representable integers of type int"
286+
"Integer literal exceeds the range of representable integers of type int"
287287
],
288288
[
289289
108,
290-
"BuckleScript warning: Uninterpreted delimiters (for unicode)"
290+
"Uninterpreted delimiters (for unicode)"
291291
],
292292
[
293293
109,
294294
"Toplevel expression has unit type"
295295
]
296296
];
297297

298-
var ret = [];
299-
300-
for(var i = 1; i <= 108; ++i){
301-
ret.push(i);
302-
}
298+
Belt_Array.map(numeric, (function (prim) {
299+
return prim[0];
300+
}));
303301

304302
var letterDescriptions = [[
305303
"a",

src/common/WarningFlagDescription.res

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,21 @@ let numeric = [
7373
(60, "Unused module declaration"),
7474
(61, "Unboxable type in primitive declaration"),
7575
(62, "Type constraint on GADT type declaration"),
76-
(101, "BuckleScript warning: Unused bs attributes"),
77-
(102, "BuckleScript warning: polymorphic comparison introduced (maybe unsafe)"),
78-
(103, "BuckleScript warning: about fragile FFI definitions"),
79-
(104, "BuckleScript warning: bs.deriving warning with customized message "),
76+
(101, "Unused bs attributes"),
77+
(102, "Polymorphic comparison introduced (maybe unsafe)"),
78+
(103, "Fragile FFI definitions"),
79+
(104, "bs.deriving warning with customized message "),
8080
(
8181
105,
82-
"BuckleScript warning: the external name is inferred from val name is unsafe from refactoring when changing value name",
82+
"External name is inferred from val name is unsafe from refactoring when changing value name",
8383
),
84-
(106, "BuckleScript warning: Unimplemented primitive used:"),
85-
(
86-
107,
87-
"BuckleScript warning: Integer literal exceeds the range of representable integers of type int",
88-
),
89-
(108, "BuckleScript warning: Uninterpreted delimiters (for unicode)"),
84+
(106, "Unimplemented primitive used:"),
85+
(107, "Integer literal exceeds the range of representable integers of type int"),
86+
(108, "Uninterpreted delimiters (for unicode)"),
9087
(109, "Toplevel expression has unit type"),
9188
]
9289

93-
let lastWarningNumber = 108
94-
let letterAll = {
95-
let ret = []
96-
for i in 1 to lastWarningNumber {
97-
Js.Array2.push(ret, i)->ignore
98-
}
99-
ret
100-
}
90+
let letterAll = numeric->Belt.Array.map(fst)
10191

10292
// we keep the original variable name `letter` like in warnings.ml
10393
let _letter = l =>

0 commit comments

Comments
 (0)