From 4c1a868c361d8348adb17e9ad11925324c987650 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 26 Jun 2023 09:12:21 +0100 Subject: [PATCH 1/4] feat(rome_js_analyze): rule `noVoid` --- CHANGELOG.md | 8 ++- .../src/categories.rs | 7 +-- .../src/analyzers/nursery/no_void.rs | 54 +++++++++++++++++++ .../tests/specs/nursery/noVoid/invalid.js | 4 ++ .../specs/nursery/noVoid/invalid.js.snap | 43 +++++++++++++++ crates/rome_js_syntax/src/expr_ext.rs | 6 +++ .../src/configuration/parse/json/rules.rs | 19 +++++++ editors/vscode/configuration_schema.json | 7 +++ npm/rome/configuration_schema.json | 7 +++ website/src/pages/lint/rules/index.mdx | 6 +++ website/src/pages/lint/rules/noVoid.md | 37 +++++++++++++ 11 files changed, 194 insertions(+), 4 deletions(-) create mode 100644 crates/rome_js_analyze/src/analyzers/nursery/no_void.rs create mode 100644 crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js create mode 100644 crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js.snap create mode 100644 website/src/pages/lint/rules/noVoid.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 967c1a6b9be..56860554f3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,7 +100,13 @@ multiple files: This rule proposes turning function expressions into arrow functions. Function expressions that use `this` are ignored. -- [`noDuplicateJsonKeys`](https://docs.rome.tools/lint/rules/noDuplicateJsonKeys/) +- Add [`noDuplicateJsonKeys`](https://docs.rome.tools/lint/rules/noDuplicateJsonKeys/) + + This rule disallow duplicate keys in a JSON object. + +- Add [`noVoid`](https://docs.rome.tools/lint/rules/novoid/) + + This rules disallow the use of `void`. #### Other changes diff --git a/crates/rome_diagnostics_categories/src/categories.rs b/crates/rome_diagnostics_categories/src/categories.rs index ee97c83cc40..c0aedb288f3 100644 --- a/crates/rome_diagnostics_categories/src/categories.rs +++ b/crates/rome_diagnostics_categories/src/categories.rs @@ -99,9 +99,10 @@ define_categories! { "lint/nursery/noStaticOnlyClass": "https://docs.rome.tools/lint/rules/noStaticOnlyClass", "lint/nursery/noDuplicateJsonKeys": "https://docs.rome.tools/lint/rules/noDuplicateJsonKeys", "lint/nursery/useNamingConvention": "https://docs.rome.tools/lint/rules/useNamingConvention", -"lint/nursery/noGlobalIsNan": "https://docs.rome.tools/lint/rules/noGlobalIsNan", -"lint/nursery/noGlobalIsFinite": "https://docs.rome.tools/lint/rules/noGlobalIsFinite", -"lint/nursery/useArrowFunction": "https://docs.rome.tools/lint/rules/useArrowFunction", + "lint/nursery/noGlobalIsNan": "https://docs.rome.tools/lint/rules/noGlobalIsNan", + "lint/nursery/noGlobalIsFinite": "https://docs.rome.tools/lint/rules/noGlobalIsFinite", + "lint/nursery/useArrowFunction": "https://docs.rome.tools/lint/rules/useArrowFunction", + "lint/nursery/noVoid": "https://docs.rome.tools/lint/rules/noVoid", // Insert new nursery rule here diff --git a/crates/rome_js_analyze/src/analyzers/nursery/no_void.rs b/crates/rome_js_analyze/src/analyzers/nursery/no_void.rs new file mode 100644 index 00000000000..7a9e46c2737 --- /dev/null +++ b/crates/rome_js_analyze/src/analyzers/nursery/no_void.rs @@ -0,0 +1,54 @@ +use rome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic}; +use rome_console::markup; +use rome_js_syntax::JsUnaryExpression; +use rome_rowan::AstNode; + +declare_rule! { + /// Disallow the use of `void`. + /// + /// > The `void` operator is often used merely to obtain the undefined primitive value, + /// > usually using `void(0)` (which is equivalent to `void 0`). In these cases, the global variable `undefined` can be used. + /// + /// Source: https://eslint.org/docs/latest/rules/no-void + /// + /// ## Examples + /// + /// ### Invalid + /// + /// ```js,expect_diagnostic + /// void 0; + /// ``` + /// + pub(crate) NoVoid { + version: "next", + name: "noVoid", + recommended: false, + } +} + +impl Rule for NoVoid { + type Query = Ast; + type State = (); + type Signals = Option; + type Options = (); + + fn run(ctx: &RuleContext) -> Self::Signals { + let expression = ctx.query(); + if expression.is_void().ok()? { + Some(()) + } else { + None + } + } + + fn diagnostic(ctx: &RuleContext, _: &Self::State) -> Option { + let node = ctx.query(); + Some(RuleDiagnostic::new( + rule_category!(), + node.range(), + markup! { + "The use of ""void"" is not allowed." + }, + )) + } +} diff --git a/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js b/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js new file mode 100644 index 00000000000..1bbdec8c673 --- /dev/null +++ b/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js @@ -0,0 +1,4 @@ +void 0; +function f() { + return void 0; +} diff --git a/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js.snap new file mode 100644 index 00000000000..124154dba42 --- /dev/null +++ b/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js.snap @@ -0,0 +1,43 @@ +--- +source: crates/rome_js_analyze/tests/spec_tests.rs +expression: invalid.js +--- +# Input +```js +void 0; +function f() { + return void 0; +} + +``` + +# Diagnostics +``` +invalid.js:1:1 lint/nursery/noVoid ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! The use of void is not allowed. + + > 1 │ void 0; + │ ^^^^^^ + 2 │ function f() { + 3 │ return void 0; + + +``` + +``` +invalid.js:3:9 lint/nursery/noVoid ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! The use of void is not allowed. + + 1 │ void 0; + 2 │ function f() { + > 3 │ return void 0; + │ ^^^^^^ + 4 │ } + 5 │ + + +``` + + diff --git a/crates/rome_js_syntax/src/expr_ext.rs b/crates/rome_js_syntax/src/expr_ext.rs index fea902b09b3..76cce721f3c 100644 --- a/crates/rome_js_syntax/src/expr_ext.rs +++ b/crates/rome_js_syntax/src/expr_ext.rs @@ -353,6 +353,12 @@ impl JsUnaryExpression { }) } + pub fn is_void(&self) -> SyntaxResult { + let operator = self.operator()?; + + Ok(matches!(operator, JsUnaryOperator::Void)) + } + /// This function checks that `JsUnaryExpression` is a signed numeric literal: /// ```js /// +123 diff --git a/crates/rome_service/src/configuration/parse/json/rules.rs b/crates/rome_service/src/configuration/parse/json/rules.rs index 37262f64c29..c992b996c30 100644 --- a/crates/rome_service/src/configuration/parse/json/rules.rs +++ b/crates/rome_service/src/configuration/parse/json/rules.rs @@ -1363,6 +1363,7 @@ impl VisitNode for Nursery { "noRedundantRoles", "noSelfAssign", "noStaticOnlyClass", + "noVoid", "useAriaPropTypes", "useArrowFunction", "useCamelCase", @@ -1664,6 +1665,24 @@ impl VisitNode for Nursery { )); } }, + "noVoid" => match value { + AnyJsonValue::JsonStringValue(_) => { + let mut configuration = RuleConfiguration::default(); + self.map_to_known_string(&value, name_text, &mut configuration, diagnostics)?; + self.no_void = Some(configuration); + } + AnyJsonValue::JsonObjectValue(_) => { + let mut configuration = RuleConfiguration::default(); + self.map_to_object(&value, name_text, &mut configuration, diagnostics)?; + self.no_void = Some(configuration); + } + _ => { + diagnostics.push(DeserializationDiagnostic::new_incorrect_type( + "object or string", + value.range(), + )); + } + }, "useAriaPropTypes" => match value { AnyJsonValue::JsonStringValue(_) => { let mut configuration = RuleConfiguration::default(); diff --git a/editors/vscode/configuration_schema.json b/editors/vscode/configuration_schema.json index 9cae0ba2a90..409f510406f 100644 --- a/editors/vscode/configuration_schema.json +++ b/editors/vscode/configuration_schema.json @@ -845,6 +845,13 @@ { "type": "null" } ] }, + "noVoid": { + "description": "Disallow the use of void.", + "anyOf": [ + { "$ref": "#/definitions/RuleConfiguration" }, + { "type": "null" } + ] + }, "recommended": { "description": "It enables the recommended rules for this group", "type": ["boolean", "null"] diff --git a/npm/rome/configuration_schema.json b/npm/rome/configuration_schema.json index 9cae0ba2a90..409f510406f 100644 --- a/npm/rome/configuration_schema.json +++ b/npm/rome/configuration_schema.json @@ -845,6 +845,13 @@ { "type": "null" } ] }, + "noVoid": { + "description": "Disallow the use of void.", + "anyOf": [ + { "$ref": "#/definitions/RuleConfiguration" }, + { "type": "null" } + ] + }, "recommended": { "description": "It enables the recommended rules for this group", "type": ["boolean", "null"] diff --git a/website/src/pages/lint/rules/index.mdx b/website/src/pages/lint/rules/index.mdx index 49ef0f6e5c3..6d20d3dd11a 100644 --- a/website/src/pages/lint/rules/index.mdx +++ b/website/src/pages/lint/rules/index.mdx @@ -987,6 +987,12 @@ Disallow assignments where both sides are exactly the same. This rule reports when a class has no non-static members, such as for a class used exclusively as a static namespace.
+

+ noVoid +

+Disallow the use of void. +
+

useAriaPropTypes

diff --git a/website/src/pages/lint/rules/noVoid.md b/website/src/pages/lint/rules/noVoid.md new file mode 100644 index 00000000000..6a1f064b328 --- /dev/null +++ b/website/src/pages/lint/rules/noVoid.md @@ -0,0 +1,37 @@ +--- +title: Lint Rule noVoid +parent: lint/rules/index +--- + +# noVoid (since vnext) + +Disallow the use of `void`. + +>The `void` operator is often used merely to obtain the undefined primitive value, +usually using `void(0)` (which is equivalent to `void 0`). In these cases, the global variable `undefined` can be used. + + +Source: https://eslint.org/docs/latest/rules/no-void + +## Examples + +### Invalid + +```jsx +void 0; +``` + +
nursery/noVoid.js:1:1 lint/nursery/noVoid ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
+
+   The use of void is not allowed.
+  
+  > 1 │ void 0;
+   ^^^^^^
+    2 │ 
+  
+
+ +## Related links + +- [Disable a rule](/linter/#disable-a-lint-rule) +- [Rule options](/linter/#rule-options) From 09f8c951e9044bde184426040a76d6ac83576ac8 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 26 Jun 2023 09:16:23 +0100 Subject: [PATCH 2/4] rebase --- .../tests/specs/nursery/noVoid/invalid.js | 3 ++ .../specs/nursery/noVoid/invalid.js.snap | 34 ++++++++++++++++++- .../tests/specs/nursery/noVoid/valid.js | 4 +++ .../tests/specs/nursery/noVoid/valid.js.snap | 14 ++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 crates/rome_js_analyze/tests/specs/nursery/noVoid/valid.js create mode 100644 crates/rome_js_analyze/tests/specs/nursery/noVoid/valid.js.snap diff --git a/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js b/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js index 1bbdec8c673..7c4e6434f9a 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js +++ b/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js @@ -2,3 +2,6 @@ void 0; function f() { return void 0; } +var foo = void 0; +void(0); + diff --git a/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js.snap index 124154dba42..1cc7fc6070f 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js.snap +++ b/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js.snap @@ -8,6 +8,9 @@ void 0; function f() { return void 0; } +var foo = void 0; +void(0); + ``` @@ -35,7 +38,36 @@ invalid.js:3:9 lint/nursery/noVoid ━━━━━━━━━━━━━━━ > 3 │ return void 0; │ ^^^^^^ 4 │ } - 5 │ + 5 │ var foo = void 0; + + +``` + +``` +invalid.js:5:11 lint/nursery/noVoid ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! The use of void is not allowed. + + 3 │ return void 0; + 4 │ } + > 5 │ var foo = void 0; + │ ^^^^^^ + 6 │ void(0); + 7 │ + + +``` + +``` +invalid.js:6:1 lint/nursery/noVoid ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + ! The use of void is not allowed. + + 4 │ } + 5 │ var foo = void 0; + > 6 │ void(0); + │ ^^^^^^^ + 7 │ ``` diff --git a/crates/rome_js_analyze/tests/specs/nursery/noVoid/valid.js b/crates/rome_js_analyze/tests/specs/nursery/noVoid/valid.js new file mode 100644 index 00000000000..bb367abd692 --- /dev/null +++ b/crates/rome_js_analyze/tests/specs/nursery/noVoid/valid.js @@ -0,0 +1,4 @@ +var foo = bar(); +foo.void(); +foo.void = bar; +delete foo; diff --git a/crates/rome_js_analyze/tests/specs/nursery/noVoid/valid.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noVoid/valid.js.snap new file mode 100644 index 00000000000..ed71efa201b --- /dev/null +++ b/crates/rome_js_analyze/tests/specs/nursery/noVoid/valid.js.snap @@ -0,0 +1,14 @@ +--- +source: crates/rome_js_analyze/tests/spec_tests.rs +expression: valid.js +--- +# Input +```js +var foo = bar(); +foo.void(); +foo.void = bar; +delete foo; + +``` + + From c9139e9a50c5b5155c58d23c601867d0ff9dcfe8 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 26 Jun 2023 10:53:59 +0100 Subject: [PATCH 3/4] documentation --- crates/rome_js_analyze/src/analyzers/nursery/no_void.rs | 8 ++++++-- editors/vscode/configuration_schema.json | 2 +- npm/rome/configuration_schema.json | 2 +- website/src/pages/lint/rules/index.mdx | 2 +- website/src/pages/lint/rules/noVoid.md | 4 +++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/rome_js_analyze/src/analyzers/nursery/no_void.rs b/crates/rome_js_analyze/src/analyzers/nursery/no_void.rs index 7a9e46c2737..aee3ec2fd6a 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery/no_void.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery/no_void.rs @@ -4,7 +4,7 @@ use rome_js_syntax::JsUnaryExpression; use rome_rowan::AstNode; declare_rule! { - /// Disallow the use of `void`. + /// Disallow the use of `void` operators, which is not a familiar operator. /// /// > The `void` operator is often used merely to obtain the undefined primitive value, /// > usually using `void(0)` (which is equivalent to `void 0`). In these cases, the global variable `undefined` can be used. @@ -49,6 +49,10 @@ impl Rule for NoVoid { markup! { "The use of ""void"" is not allowed." }, - )) + ).note( + markup!{ + "If you use ""void"" to alter the return type of a function or return `undefined`, use the global `undefined` instead." + } + )) } } diff --git a/editors/vscode/configuration_schema.json b/editors/vscode/configuration_schema.json index 409f510406f..3757a21bd8d 100644 --- a/editors/vscode/configuration_schema.json +++ b/editors/vscode/configuration_schema.json @@ -846,7 +846,7 @@ ] }, "noVoid": { - "description": "Disallow the use of void.", + "description": "Disallow the use of void operators, which is not a familiar operator.", "anyOf": [ { "$ref": "#/definitions/RuleConfiguration" }, { "type": "null" } diff --git a/npm/rome/configuration_schema.json b/npm/rome/configuration_schema.json index 409f510406f..3757a21bd8d 100644 --- a/npm/rome/configuration_schema.json +++ b/npm/rome/configuration_schema.json @@ -846,7 +846,7 @@ ] }, "noVoid": { - "description": "Disallow the use of void.", + "description": "Disallow the use of void operators, which is not a familiar operator.", "anyOf": [ { "$ref": "#/definitions/RuleConfiguration" }, { "type": "null" } diff --git a/website/src/pages/lint/rules/index.mdx b/website/src/pages/lint/rules/index.mdx index 6d20d3dd11a..54ca9111dbb 100644 --- a/website/src/pages/lint/rules/index.mdx +++ b/website/src/pages/lint/rules/index.mdx @@ -990,7 +990,7 @@ This rule reports when a class has no non-static members, such as for a class us

noVoid

-Disallow the use of void. +Disallow the use of void operators, which is not a familiar operator.

diff --git a/website/src/pages/lint/rules/noVoid.md b/website/src/pages/lint/rules/noVoid.md index 6a1f064b328..dab3827466a 100644 --- a/website/src/pages/lint/rules/noVoid.md +++ b/website/src/pages/lint/rules/noVoid.md @@ -5,7 +5,7 @@ parent: lint/rules/index # noVoid (since vnext) -Disallow the use of `void`. +Disallow the use of `void` operators, which is not a familiar operator. >The `void` operator is often used merely to obtain the undefined primitive value, usually using `void(0)` (which is equivalent to `void 0`). In these cases, the global variable `undefined` can be used. @@ -29,6 +29,8 @@ void 0; ^^^^^^ 2 │ + If you use void to alter the return type of a function or return `undefined`, use the global `undefined` instead. + ## Related links From 56aceeae32c94c2104ed3ad5ff22fa4326d4f278 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Mon, 26 Jun 2023 10:56:22 +0100 Subject: [PATCH 4/4] rebase --- .../rome_js_analyze/src/analyzers/nursery.rs | 3 +- .../specs/nursery/noVoid/invalid.js.snap | 8 ++ .../src/configuration/linter/rules.rs | 77 +++++++++++-------- npm/backend-jsonrpc/src/workspace.ts | 5 ++ .../components/generated/NumberOfRules.astro | 2 +- 5 files changed, 63 insertions(+), 32 deletions(-) diff --git a/crates/rome_js_analyze/src/analyzers/nursery.rs b/crates/rome_js_analyze/src/analyzers/nursery.rs index 76d7423e2f8..5383d086c8d 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery.rs @@ -6,6 +6,7 @@ pub(crate) mod no_duplicate_jsx_props; pub(crate) mod no_for_each; pub(crate) mod no_self_assign; pub(crate) mod no_static_only_class; +pub(crate) mod no_void; pub(crate) mod use_arrow_function; pub(crate) mod use_grouped_type_import; pub(crate) mod use_heading_content; @@ -13,4 +14,4 @@ pub(crate) mod use_is_nan; pub(crate) mod use_literal_enum_members; pub(crate) mod use_literal_keys; pub(crate) mod use_simple_number_keys; -declare_group! { pub (crate) Nursery { name : "nursery" , rules : [self :: no_confusing_arrow :: NoConfusingArrow , self :: no_duplicate_jsx_props :: NoDuplicateJsxProps , self :: no_for_each :: NoForEach , self :: no_self_assign :: NoSelfAssign , self :: no_static_only_class :: NoStaticOnlyClass , self :: use_arrow_function :: UseArrowFunction , self :: use_grouped_type_import :: UseGroupedTypeImport , self :: use_heading_content :: UseHeadingContent , self :: use_is_nan :: UseIsNan , self :: use_literal_enum_members :: UseLiteralEnumMembers , self :: use_literal_keys :: UseLiteralKeys , self :: use_simple_number_keys :: UseSimpleNumberKeys ,] } } +declare_group! { pub (crate) Nursery { name : "nursery" , rules : [self :: no_confusing_arrow :: NoConfusingArrow , self :: no_duplicate_jsx_props :: NoDuplicateJsxProps , self :: no_for_each :: NoForEach , self :: no_self_assign :: NoSelfAssign , self :: no_static_only_class :: NoStaticOnlyClass , self :: no_void :: NoVoid , self :: use_arrow_function :: UseArrowFunction , self :: use_grouped_type_import :: UseGroupedTypeImport , self :: use_heading_content :: UseHeadingContent , self :: use_is_nan :: UseIsNan , self :: use_literal_enum_members :: UseLiteralEnumMembers , self :: use_literal_keys :: UseLiteralKeys , self :: use_simple_number_keys :: UseSimpleNumberKeys ,] } } diff --git a/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js.snap b/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js.snap index 1cc7fc6070f..4b9c61c186a 100644 --- a/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js.snap +++ b/crates/rome_js_analyze/tests/specs/nursery/noVoid/invalid.js.snap @@ -25,6 +25,8 @@ invalid.js:1:1 lint/nursery/noVoid ━━━━━━━━━━━━━━━ 2 │ function f() { 3 │ return void 0; + i If you use void to alter the return type of a function or return `undefined`, use the global `undefined` instead. + ``` @@ -40,6 +42,8 @@ invalid.js:3:9 lint/nursery/noVoid ━━━━━━━━━━━━━━━ 4 │ } 5 │ var foo = void 0; + i If you use void to alter the return type of a function or return `undefined`, use the global `undefined` instead. + ``` @@ -55,6 +59,8 @@ invalid.js:5:11 lint/nursery/noVoid ━━━━━━━━━━━━━━ 6 │ void(0); 7 │ + i If you use void to alter the return type of a function or return `undefined`, use the global `undefined` instead. + ``` @@ -69,6 +75,8 @@ invalid.js:6:1 lint/nursery/noVoid ━━━━━━━━━━━━━━━ │ ^^^^^^^ 7 │ + i If you use void to alter the return type of a function or return `undefined`, use the global `undefined` instead. + ``` diff --git a/crates/rome_service/src/configuration/linter/rules.rs b/crates/rome_service/src/configuration/linter/rules.rs index af82f22efd6..90abd09e4c8 100644 --- a/crates/rome_service/src/configuration/linter/rules.rs +++ b/crates/rome_service/src/configuration/linter/rules.rs @@ -1872,6 +1872,10 @@ pub struct Nursery { #[bpaf(long("no-static-only-class"), argument("on|off|warn"), optional, hide)] #[serde(skip_serializing_if = "Option::is_none")] pub no_static_only_class: Option, + #[doc = "Disallow the use of void operators, which is not a familiar operator."] + #[bpaf(long("no-void"), argument("on|off|warn"), optional, hide)] + #[serde(skip_serializing_if = "Option::is_none")] + pub no_void: Option, #[doc = "Enforce that ARIA state and property values are valid."] #[bpaf(long("use-aria-prop-types"), argument("on|off|warn"), optional, hide)] #[serde(skip_serializing_if = "Option::is_none")] @@ -1943,7 +1947,7 @@ pub struct Nursery { } impl Nursery { const GROUP_NAME: &'static str = "nursery"; - pub(crate) const GROUP_RULES: [&'static str; 27] = [ + pub(crate) const GROUP_RULES: [&'static str; 28] = [ "noAccumulatingSpread", "noAriaUnsupportedElements", "noBannedTypes", @@ -1959,6 +1963,7 @@ impl Nursery { "noRedundantRoles", "noSelfAssign", "noStaticOnlyClass", + "noVoid", "useAriaPropTypes", "useArrowFunction", "useCamelCase", @@ -2001,14 +2006,14 @@ impl Nursery { RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[12]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[13]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[14]), - RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[16]), - RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[18]), + RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[17]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[19]), - RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[22]), + RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[20]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[23]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[24]), + RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[25]), ]; - const ALL_RULES_AS_FILTERS: [RuleFilter<'static>; 27] = [ + const ALL_RULES_AS_FILTERS: [RuleFilter<'static>; 28] = [ RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[0]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[1]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[2]), @@ -2036,6 +2041,7 @@ impl Nursery { RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[24]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[25]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[26]), + RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[27]), ]; #[doc = r" Retrieves the recommended rules"] pub(crate) fn is_recommended(&self) -> bool { matches!(self.recommended, Some(true)) } @@ -2121,66 +2127,71 @@ impl Nursery { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[14])); } } - if let Some(rule) = self.use_aria_prop_types.as_ref() { + if let Some(rule) = self.no_void.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[15])); } } - if let Some(rule) = self.use_arrow_function.as_ref() { + if let Some(rule) = self.use_aria_prop_types.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[16])); } } - if let Some(rule) = self.use_camel_case.as_ref() { + if let Some(rule) = self.use_arrow_function.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[17])); } } - if let Some(rule) = self.use_exhaustive_dependencies.as_ref() { + if let Some(rule) = self.use_camel_case.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[18])); } } - if let Some(rule) = self.use_grouped_type_import.as_ref() { + if let Some(rule) = self.use_exhaustive_dependencies.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[19])); } } - if let Some(rule) = self.use_heading_content.as_ref() { + if let Some(rule) = self.use_grouped_type_import.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[20])); } } - if let Some(rule) = self.use_hook_at_top_level.as_ref() { + if let Some(rule) = self.use_heading_content.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[21])); } } - if let Some(rule) = self.use_is_nan.as_ref() { + if let Some(rule) = self.use_hook_at_top_level.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[22])); } } - if let Some(rule) = self.use_literal_enum_members.as_ref() { + if let Some(rule) = self.use_is_nan.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[23])); } } - if let Some(rule) = self.use_literal_keys.as_ref() { + if let Some(rule) = self.use_literal_enum_members.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[24])); } } - if let Some(rule) = self.use_naming_convention.as_ref() { + if let Some(rule) = self.use_literal_keys.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[25])); } } - if let Some(rule) = self.use_simple_number_keys.as_ref() { + if let Some(rule) = self.use_naming_convention.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[26])); } } + if let Some(rule) = self.use_simple_number_keys.as_ref() { + if rule.is_enabled() { + index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[27])); + } + } index_set } pub(crate) fn get_disabled_rules(&self) -> IndexSet { @@ -2260,66 +2271,71 @@ impl Nursery { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[14])); } } - if let Some(rule) = self.use_aria_prop_types.as_ref() { + if let Some(rule) = self.no_void.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[15])); } } - if let Some(rule) = self.use_arrow_function.as_ref() { + if let Some(rule) = self.use_aria_prop_types.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[16])); } } - if let Some(rule) = self.use_camel_case.as_ref() { + if let Some(rule) = self.use_arrow_function.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[17])); } } - if let Some(rule) = self.use_exhaustive_dependencies.as_ref() { + if let Some(rule) = self.use_camel_case.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[18])); } } - if let Some(rule) = self.use_grouped_type_import.as_ref() { + if let Some(rule) = self.use_exhaustive_dependencies.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[19])); } } - if let Some(rule) = self.use_heading_content.as_ref() { + if let Some(rule) = self.use_grouped_type_import.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[20])); } } - if let Some(rule) = self.use_hook_at_top_level.as_ref() { + if let Some(rule) = self.use_heading_content.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[21])); } } - if let Some(rule) = self.use_is_nan.as_ref() { + if let Some(rule) = self.use_hook_at_top_level.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[22])); } } - if let Some(rule) = self.use_literal_enum_members.as_ref() { + if let Some(rule) = self.use_is_nan.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[23])); } } - if let Some(rule) = self.use_literal_keys.as_ref() { + if let Some(rule) = self.use_literal_enum_members.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[24])); } } - if let Some(rule) = self.use_naming_convention.as_ref() { + if let Some(rule) = self.use_literal_keys.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[25])); } } - if let Some(rule) = self.use_simple_number_keys.as_ref() { + if let Some(rule) = self.use_naming_convention.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[26])); } } + if let Some(rule) = self.use_simple_number_keys.as_ref() { + if rule.is_disabled() { + index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[27])); + } + } index_set } #[doc = r" Checks if, given a rule name, matches one of the rules contained in this category"] @@ -2331,7 +2347,7 @@ impl Nursery { pub(crate) fn recommended_rules_as_filters() -> [RuleFilter<'static>; 16] { Self::RECOMMENDED_RULES_AS_FILTERS } - pub(crate) fn all_rules_as_filters() -> [RuleFilter<'static>; 27] { Self::ALL_RULES_AS_FILTERS } + pub(crate) fn all_rules_as_filters() -> [RuleFilter<'static>; 28] { Self::ALL_RULES_AS_FILTERS } #[doc = r" Select preset rules"] pub(crate) fn collect_preset_rules( &self, @@ -2367,6 +2383,7 @@ impl Nursery { "noRedundantRoles" => self.no_redundant_roles.as_ref(), "noSelfAssign" => self.no_self_assign.as_ref(), "noStaticOnlyClass" => self.no_static_only_class.as_ref(), + "noVoid" => self.no_void.as_ref(), "useAriaPropTypes" => self.use_aria_prop_types.as_ref(), "useArrowFunction" => self.use_arrow_function.as_ref(), "useCamelCase" => self.use_camel_case.as_ref(), diff --git a/npm/backend-jsonrpc/src/workspace.ts b/npm/backend-jsonrpc/src/workspace.ts index 199f95b02f3..4e04015c7f7 100644 --- a/npm/backend-jsonrpc/src/workspace.ts +++ b/npm/backend-jsonrpc/src/workspace.ts @@ -565,6 +565,10 @@ export interface Nursery { * This rule reports when a class has no non-static members, such as for a class used exclusively as a static namespace. */ noStaticOnlyClass?: RuleConfiguration; + /** + * Disallow the use of void operators, which is not a familiar operator. + */ + noVoid?: RuleConfiguration; /** * It enables the recommended rules for this group */ @@ -1126,6 +1130,7 @@ export type Category = | "lint/nursery/noGlobalIsNan" | "lint/nursery/noGlobalIsFinite" | "lint/nursery/useArrowFunction" + | "lint/nursery/noVoid" | "lint/performance/noDelete" | "lint/security/noDangerouslySetInnerHtml" | "lint/security/noDangerouslySetInnerHtmlWithChildren" diff --git a/website/src/components/generated/NumberOfRules.astro b/website/src/components/generated/NumberOfRules.astro index f57b1c92f67..0328d3eb1c5 100644 --- a/website/src/components/generated/NumberOfRules.astro +++ b/website/src/components/generated/NumberOfRules.astro @@ -1,2 +1,2 @@ -

Rome's linter has a total of 146 rules

\ No newline at end of file +

Rome's linter has a total of 147 rules

\ No newline at end of file