diff --git a/data/sidebar_manual_latest.json b/data/sidebar_manual_latest.json index 2d012c67d..06ab499cc 100644 --- a/data/sidebar_manual_latest.json +++ b/data/sidebar_manual_latest.json @@ -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" diff --git a/misc_docs/syntax/decorator_module_warning.mdx b/misc_docs/syntax/decorator_module_warning.mdx new file mode 100644 index 000000000..7af8eae61 --- /dev/null +++ b/misc_docs/syntax/decorator_module_warning.mdx @@ -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 + + + +```res +// Disables warning 27 for the current module +@@warning("-27") +``` + +```js +``` + + + +### References + +* [Warning Numbers](/docs/manual/latest/warning-numbers) diff --git a/pages/docs/manual/latest/attribute.mdx b/pages/docs/manual/latest/attribute.mdx index 07024c568..2d1eaf463 100644 --- a/pages/docs/manual/latest/attribute.mdx +++ b/pages/docs/manual/latest/attribute.mdx @@ -59,7 +59,7 @@ let customTriple = foo => foo * 3 -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. diff --git a/pages/docs/manual/latest/build-configuration.mdx b/pages/docs/manual/latest/build-configuration.mdx index f7869bd0b..6b642acc0 100644 --- a/pages/docs/manual/latest/build-configuration.mdx +++ b/pages/docs/manual/latest/build-configuration.mdx @@ -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 diff --git a/pages/docs/manual/latest/warning-numbers.mdx b/pages/docs/manual/latest/warning-numbers.mdx new file mode 100644 index 000000000..fd59f286c --- /dev/null +++ b/pages/docs/manual/latest/warning-numbers.mdx @@ -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). + + diff --git a/src/common/Mdx.mjs b/src/common/Mdx.mjs index 3167117ec..e4fc9aeb8 100644 --- a/src/common/Mdx.mjs +++ b/src/common/Mdx.mjs @@ -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); @@ -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; }) diff --git a/src/common/Mdx.res b/src/common/Mdx.res index 80280ecd0..fae89a278 100644 --- a/src/common/Mdx.res +++ b/src/common/Mdx.res @@ -105,6 +105,8 @@ module Components = { "children": MdxChildren.t, "labels": option>, }>, + @as("WarningTable") @optional + warningTable: React.component, /* Common markdown elements */ @optional p: React.component, diff --git a/src/common/Mdx.resi b/src/common/Mdx.resi index 56f419827..9afaf3f42 100644 --- a/src/common/Mdx.resi +++ b/src/common/Mdx.resi @@ -38,6 +38,7 @@ module Components: { ~intro: React.component=?, ~urlBox: React.component<{"text": string, "href": string, "children": MdxChildren.t}>=?, ~codeTab: React.component<{"children": MdxChildren.t, "labels": option>}>=?, + ~warningTable: React.component=?, ~p: React.component=?, ~li: React.component=?, ~h1: React.component=?, diff --git a/src/common/WarningFlagDescription.mjs b/src/common/WarningFlagDescription.mjs index 9b395b14c..53c9f6d20 100644 --- a/src/common/WarningFlagDescription.mjs +++ b/src/common/WarningFlagDescription.mjs @@ -259,35 +259,35 @@ 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, @@ -295,11 +295,9 @@ var numeric = [ ] ]; -var ret = []; - -for(var i = 1; i <= 108; ++i){ - ret.push(i); -} +Belt_Array.map(numeric, (function (prim) { + return prim[0]; + })); var letterDescriptions = [[ "a", diff --git a/src/common/WarningFlagDescription.res b/src/common/WarningFlagDescription.res index 85b648a93..22423fee7 100644 --- a/src/common/WarningFlagDescription.res +++ b/src/common/WarningFlagDescription.res @@ -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 => diff --git a/src/components/ApiMarkdown.mjs b/src/components/ApiMarkdown.mjs index 70967a414..e465e7433 100644 --- a/src/components/ApiMarkdown.mjs +++ b/src/components/ApiMarkdown.mjs @@ -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 , diff --git a/src/components/Markdown.mjs b/src/components/Markdown.mjs index a287a2c29..4ca1e1df9 100644 --- a/src/components/Markdown.mjs +++ b/src/components/Markdown.mjs @@ -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) { @@ -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", { @@ -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 diff --git a/src/components/Markdown.res b/src/components/Markdown.res index 6ac1b07ed..4de9b1693 100644 --- a/src/components/Markdown.res +++ b/src/components/Markdown.res @@ -343,6 +343,26 @@ module CodeTab = { } } +module WarningTable = { + @react.component + let make = (~children) => { + + + {React.string("#")} {React.string("Description")} + + + {WarningFlagDescription.lookupAll() + ->Belt.Array.map(((number, description)) => + + {React.string(number)} {React.string(description)} + + ) + ->React.array} + + + } +} + module Blockquote = { @react.component let make = (~children) => @@ -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,