Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion data/sidebar_manual_latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"build-external-stdlib",
"build-pinned-dependencies",
"interop-with-js-build-systems",
"build-performance"
"build-performance",
"warning-numbers"
],
"Guides": [
"converting-from-js"
Expand Down
27 changes: 27 additions & 0 deletions misc_docs/syntax/decorator_module_warning.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
id: "module-warning-decorator"
keywords: ["warning", "decorator"]
name: "@@warning"
summary: "This is the `@@warning` decorator."
category: "decorators"
---

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.

### Examples

<CodeTab labels={["ReScript", "JS Output"]}>

```res
// Disables warning 27 for the current module
@@warning("-27")
```

```js
```

</CodeTab>

### References

* [Warning Numbers](/docs/manual/latest/warning-numbers)
2 changes: 1 addition & 1 deletion pages/docs/manual/latest/attribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let customTriple = foo => foo * 3

</CodeTab>

1. `@@warning("-27")` is a standalone attribute that annotates the entire file. Those attributes start with `@@`. Here, it carries the data `"-27"`.
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).
2. `@unboxed` annotates the type definition.
3. `@val` annotates the `external` statement.
4. `@as("aria-label")` annotates the `ariaLabel` record field.
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/manual/latest/build-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Selectively turn on/off certain warnings and/or turn them into hard errors. Exam

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.

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.
The warning numbers are shown in the build output when they're triggered. See [Warning Numbers](./warning-numbers) for the complete list.

## bsc-flags

Expand Down
13 changes: 13 additions & 0 deletions pages/docs/manual/latest/warning-numbers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: "Warning Numbers"
description: "Available compiler warning numbers in ReScript"
canonical: "/docs/manual/latest/warning-numbers"
---

# Warning Numbers

You can configure which warnings the ReScript compiler generates
[in the build configuration](/docs/manual/latest/build-configuration#warnings) or
[using the `@@warning()` decorator](/syntax-lookup#module-warning-decorator).

<WarningTable />
45 changes: 24 additions & 21 deletions src/common/Mdx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var MdxChildren = {
};

var Components = {
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) {
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) {
var tmp = {};
if (prim0 !== undefined) {
tmp.Cite = Caml_option.valFromOption(prim0);
Expand All @@ -95,64 +95,67 @@ var Components = {
tmp.CodeTab = Caml_option.valFromOption(prim5);
}
if (prim6 !== undefined) {
tmp.p = Caml_option.valFromOption(prim6);
tmp.WarningTable = Caml_option.valFromOption(prim6);
}
if (prim7 !== undefined) {
tmp.li = Caml_option.valFromOption(prim7);
tmp.p = Caml_option.valFromOption(prim7);
}
if (prim8 !== undefined) {
tmp.h1 = Caml_option.valFromOption(prim8);
tmp.li = Caml_option.valFromOption(prim8);
}
if (prim9 !== undefined) {
tmp.h2 = Caml_option.valFromOption(prim9);
tmp.h1 = Caml_option.valFromOption(prim9);
}
if (prim10 !== undefined) {
tmp.h3 = Caml_option.valFromOption(prim10);
tmp.h2 = Caml_option.valFromOption(prim10);
}
if (prim11 !== undefined) {
tmp.h4 = Caml_option.valFromOption(prim11);
tmp.h3 = Caml_option.valFromOption(prim11);
}
if (prim12 !== undefined) {
tmp.h5 = Caml_option.valFromOption(prim12);
tmp.h4 = Caml_option.valFromOption(prim12);
}
if (prim13 !== undefined) {
tmp.ul = Caml_option.valFromOption(prim13);
tmp.h5 = Caml_option.valFromOption(prim13);
}
if (prim14 !== undefined) {
tmp.ol = Caml_option.valFromOption(prim14);
tmp.ul = Caml_option.valFromOption(prim14);
}
if (prim15 !== undefined) {
tmp.table = Caml_option.valFromOption(prim15);
tmp.ol = Caml_option.valFromOption(prim15);
}
if (prim16 !== undefined) {
tmp.thead = Caml_option.valFromOption(prim16);
tmp.table = Caml_option.valFromOption(prim16);
}
if (prim17 !== undefined) {
tmp.th = Caml_option.valFromOption(prim17);
tmp.thead = Caml_option.valFromOption(prim17);
}
if (prim18 !== undefined) {
tmp.td = Caml_option.valFromOption(prim18);
tmp.th = Caml_option.valFromOption(prim18);
}
if (prim19 !== undefined) {
tmp.blockquote = Caml_option.valFromOption(prim19);
tmp.td = Caml_option.valFromOption(prim19);
}
if (prim20 !== undefined) {
tmp.inlineCode = Caml_option.valFromOption(prim20);
tmp.blockquote = Caml_option.valFromOption(prim20);
}
if (prim21 !== undefined) {
tmp.strong = Caml_option.valFromOption(prim21);
tmp.inlineCode = Caml_option.valFromOption(prim21);
}
if (prim22 !== undefined) {
tmp.hr = Caml_option.valFromOption(prim22);
tmp.strong = Caml_option.valFromOption(prim22);
}
if (prim23 !== undefined) {
tmp.code = Caml_option.valFromOption(prim23);
tmp.hr = Caml_option.valFromOption(prim23);
}
if (prim24 !== undefined) {
tmp.pre = Caml_option.valFromOption(prim24);
tmp.code = Caml_option.valFromOption(prim24);
}
if (prim25 !== undefined) {
tmp.a = Caml_option.valFromOption(prim25);
tmp.pre = Caml_option.valFromOption(prim25);
}
if (prim26 !== undefined) {
tmp.a = Caml_option.valFromOption(prim26);
}
return tmp;
})
Expand Down
2 changes: 2 additions & 0 deletions src/common/Mdx.res
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ module Components = {
"children": MdxChildren.t,
"labels": option<array<string>>,
}>,
@as("WarningTable") @optional
warningTable: React.component<props>,
/* Common markdown elements */
@optional
p: React.component<props>,
Expand Down
1 change: 1 addition & 0 deletions src/common/Mdx.resi
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module Components: {
~intro: React.component<props>=?,
~urlBox: React.component<{"text": string, "href": string, "children": MdxChildren.t}>=?,
~codeTab: React.component<{"children": MdxChildren.t, "labels": option<array<string>>}>=?,
~warningTable: React.component<props>=?,
~p: React.component<props>=?,
~li: React.component<props>=?,
~h1: React.component<props>=?,
Expand Down
24 changes: 11 additions & 13 deletions src/common/WarningFlagDescription.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -259,47 +259,45 @@ var numeric = [
],
[
101,
"BuckleScript warning: Unused bs attributes"
"Unused bs attributes"
],
[
102,
"BuckleScript warning: polymorphic comparison introduced (maybe unsafe)"
"Polymorphic comparison introduced (maybe unsafe)"
],
[
103,
"BuckleScript warning: about fragile FFI definitions"
"Fragile FFI definitions"
],
[
104,
"BuckleScript warning: bs.deriving warning with customized message "
"bs.deriving warning with customized message "
],
[
105,
"BuckleScript warning: the external name is inferred from val name is unsafe from refactoring when changing value name"
"External name is inferred from val name is unsafe from refactoring when changing value name"
],
[
106,
"BuckleScript warning: Unimplemented primitive used:"
"Unimplemented primitive used:"
],
[
107,
"BuckleScript warning: Integer literal exceeds the range of representable integers of type int"
"Integer literal exceeds the range of representable integers of type int"
],
[
108,
"BuckleScript warning: Uninterpreted delimiters (for unicode)"
"Uninterpreted delimiters (for unicode)"
],
[
109,
"Toplevel expression has unit type"
]
];

var ret = [];

for(var i = 1; i <= 108; ++i){
ret.push(i);
}
Belt_Array.map(numeric, (function (prim) {
return prim[0];
}));

var letterDescriptions = [[
"a",
Expand Down
28 changes: 9 additions & 19 deletions src/common/WarningFlagDescription.res
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,21 @@ let numeric = [
(60, "Unused module declaration"),
(61, "Unboxable type in primitive declaration"),
(62, "Type constraint on GADT type declaration"),
(101, "BuckleScript warning: Unused bs attributes"),
(102, "BuckleScript warning: polymorphic comparison introduced (maybe unsafe)"),
(103, "BuckleScript warning: about fragile FFI definitions"),
(104, "BuckleScript warning: bs.deriving warning with customized message "),
(101, "Unused bs attributes"),
(102, "Polymorphic comparison introduced (maybe unsafe)"),
(103, "Fragile FFI definitions"),
(104, "bs.deriving warning with customized message "),
(
105,
"BuckleScript warning: the external name is inferred from val name is unsafe from refactoring when changing value name",
"External name is inferred from val name is unsafe from refactoring when changing value name",
),
(106, "BuckleScript warning: Unimplemented primitive used:"),
(
107,
"BuckleScript warning: Integer literal exceeds the range of representable integers of type int",
),
(108, "BuckleScript warning: Uninterpreted delimiters (for unicode)"),
(106, "Unimplemented primitive used:"),
(107, "Integer literal exceeds the range of representable integers of type int"),
(108, "Uninterpreted delimiters (for unicode)"),
(109, "Toplevel expression has unit type"),
]

let lastWarningNumber = 108
let letterAll = {
let ret = []
for i in 1 to lastWarningNumber {
Js.Array2.push(ret, i)->ignore
}
ret
}
let letterAll = numeric->Belt.Array.map(fst)

// we keep the original variable name `letter` like in warnings.ml
let _letter = l =>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ApiMarkdown.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function ApiMarkdown$H2(Props) {
}));
}

var $$default = Mdx.Components.t(undefined, undefined, undefined, Markdown.Intro.make, undefined, undefined, Markdown.P.make, Markdown.Li.make, Markdown.H1.make, ApiMarkdown$H2, Markdown.H3.make, Markdown.H4.make, Markdown.H5.make, Markdown.Ul.make, Markdown.Ol.make, undefined, Markdown.Thead.make, Markdown.Th.make, Markdown.Td.make, undefined, Markdown.InlineCode.make, undefined, undefined, Markdown.Code.make, Markdown.Pre.make, Markdown.A.make, undefined);
var $$default = Mdx.Components.t(undefined, undefined, undefined, Markdown.Intro.make, undefined, undefined, undefined, Markdown.P.make, Markdown.Li.make, Markdown.H1.make, ApiMarkdown$H2, Markdown.H3.make, Markdown.H4.make, Markdown.H5.make, Markdown.Ul.make, Markdown.Ol.make, undefined, Markdown.Thead.make, Markdown.Th.make, Markdown.Td.make, undefined, Markdown.InlineCode.make, undefined, undefined, Markdown.Code.make, Markdown.Pre.make, Markdown.A.make, undefined);

export {
$$default ,
Expand Down
24 changes: 23 additions & 1 deletion src/components/Markdown.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
import * as Belt_Option from "rescript/lib/es6/belt_Option.js";
import * as Caml_option from "rescript/lib/es6/caml_option.js";
import * as CodeExample from "./CodeExample.mjs";
import * as WarningFlagDescription from "../common/WarningFlagDescription.mjs";
import * as ParseNumericRangeJs from "../ffi/parse-numeric-range.js";

function Markdown$P(Props) {
Expand Down Expand Up @@ -444,6 +445,27 @@ function Markdown$CodeTab(Props) {
}));
}

function Markdown$WarningTable(Props) {
return React.createElement(Markdown$Table, {
children: null
}, React.createElement(Markdown$Thead, {
children: React.createElement("tr", undefined, React.createElement(Markdown$Th, {
children: "#"
}), React.createElement(Markdown$Th, {
children: "Description"
}))
}), React.createElement("tbody", undefined, Belt_Array.map(WarningFlagDescription.lookupAll(undefined), (function (param) {
var number = param[0];
return React.createElement("tr", {
key: number
}, React.createElement(Markdown$Td, {
children: number
}), React.createElement(Markdown$Td, {
children: param[1]
}));
}))));
}

function Markdown$Blockquote(Props) {
var children = Props.children;
return React.createElement("blockquote", {
Expand Down Expand Up @@ -601,7 +623,7 @@ var Strong = {
make: Markdown$Strong
};

var $$default = Mdx.Components.t(Markdown$Cite, Markdown$Info, Markdown$Warn, Markdown$Intro, Markdown$UrlBox, Markdown$CodeTab, Markdown$P, Markdown$Li, Markdown$H1, Markdown$H2, Markdown$H3, Markdown$H4, Markdown$H5, Markdown$Ul, Markdown$Ol, Markdown$Table, Markdown$Thead, Markdown$Th, Markdown$Td, Markdown$Blockquote, Markdown$InlineCode, Markdown$Strong, Markdown$Hr, Markdown$Code, Markdown$Pre, Markdown$A, undefined);
var $$default = Mdx.Components.t(Markdown$Cite, Markdown$Info, Markdown$Warn, Markdown$Intro, Markdown$UrlBox, Markdown$CodeTab, Markdown$WarningTable, Markdown$P, Markdown$Li, Markdown$H1, Markdown$H2, Markdown$H3, Markdown$H4, Markdown$H5, Markdown$Ul, Markdown$Ol, Markdown$Table, Markdown$Thead, Markdown$Th, Markdown$Td, Markdown$Blockquote, Markdown$InlineCode, Markdown$Strong, Markdown$Hr, Markdown$Code, Markdown$Pre, Markdown$A, undefined);

var UrlBox = {
make: Markdown$UrlBox
Expand Down
21 changes: 21 additions & 0 deletions src/components/Markdown.res
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,26 @@ module CodeTab = {
}
}

module WarningTable = {
@react.component
let make = (~children) => {
<Table>
<Thead>
<tr> <Th> {React.string("#")} </Th> <Th> {React.string("Description")} </Th> </tr>
</Thead>
<tbody>
{WarningFlagDescription.lookupAll()
->Belt.Array.map(((number, description)) =>
<tr key=number>
<Td> {React.string(number)} </Td> <Td> {React.string(description)} </Td>
</tr>
)
->React.array}
</tbody>
</Table>
}
}

module Blockquote = {
@react.component
let make = (~children) =>
Expand Down Expand Up @@ -497,6 +517,7 @@ let default = Mdx.Components.t(
~warn=Warn.make,
~urlBox=UrlBox.make,
~codeTab=CodeTab.make,
~warningTable=WarningTable.make,
~p=P.make,
~li=Li.make,
~h1=H1.make,
Expand Down