From 38d464c0f6924522563ad3b82ad165fbfbc26f14 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 6 Feb 2024 15:16:04 +0000 Subject: [PATCH] rebase --- .../src/configuration/linter/rules.rs | 106 ++++++++++-------- .../@biomejs/backend-jsonrpc/src/workspace.ts | 15 +++ .../@biomejs/biome/configuration_schema.json | 24 ++++ .../components/generated/NumberOfRules.astro | 2 +- .../src/content/docs/linter/rules/index.mdx | 2 +- .../linter/rules/no-restricted-imports.md | 2 - 6 files changed, 102 insertions(+), 49 deletions(-) diff --git a/crates/biome_service/src/configuration/linter/rules.rs b/crates/biome_service/src/configuration/linter/rules.rs index 233a8e464f82..d7584355546f 100644 --- a/crates/biome_service/src/configuration/linter/rules.rs +++ b/crates/biome_service/src/configuration/linter/rules.rs @@ -2251,6 +2251,9 @@ pub struct Nursery { #[doc = "Avoid re-export all"] #[serde(skip_serializing_if = "Option::is_none")] pub no_re_export_all: Option, + #[doc = "Disallow specified modules when loaded by import or require."] + #[serde(skip_serializing_if = "Option::is_none")] + pub no_restricted_imports: Option, #[doc = "Disallow disabled tests."] #[serde(skip_serializing_if = "Option::is_none")] pub no_skipped_tests: Option, @@ -2322,7 +2325,7 @@ impl DeserializableValidator for Nursery { } impl Nursery { const GROUP_NAME: &'static str = "nursery"; - pub(crate) const GROUP_RULES: [&'static str; 28] = [ + pub(crate) const GROUP_RULES: [&'static str; 29] = [ "noDuplicateJsonKeys", "noEmptyBlockStatements", "noEmptyTypeParameters", @@ -2333,6 +2336,7 @@ impl Nursery { "noMisleadingCharacterClass", "noNodejsModules", "noReExportAll", + "noRestrictedImports", "noSkippedTests", "noThenProperty", "noUnusedImports", @@ -2372,15 +2376,15 @@ impl Nursery { RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[3]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[4]), RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[5]), - RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[11]), - RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[15]), + RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[12]), 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[21]), - RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[23]), - RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[25]), + 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[24]), + RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[26]), ]; - const ALL_RULES_AS_FILTERS: [RuleFilter<'static>; 28] = [ + const ALL_RULES_AS_FILTERS: [RuleFilter<'static>; 29] = [ 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]), @@ -2409,6 +2413,7 @@ impl Nursery { 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]), + RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[28]), ]; #[doc = r" Retrieves the recommended rules"] pub(crate) fn is_recommended(&self) -> bool { @@ -2475,96 +2480,101 @@ impl Nursery { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[9])); } } - if let Some(rule) = self.no_skipped_tests.as_ref() { + if let Some(rule) = self.no_restricted_imports.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[10])); } } - if let Some(rule) = self.no_then_property.as_ref() { + if let Some(rule) = self.no_skipped_tests.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[11])); } } - if let Some(rule) = self.no_unused_imports.as_ref() { + if let Some(rule) = self.no_then_property.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[12])); } } - if let Some(rule) = self.no_unused_private_class_members.as_ref() { + if let Some(rule) = self.no_unused_imports.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[13])); } } - if let Some(rule) = self.no_useless_lone_block_statements.as_ref() { + if let Some(rule) = self.no_unused_private_class_members.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[14])); } } - if let Some(rule) = self.no_useless_ternary.as_ref() { + if let Some(rule) = self.no_useless_lone_block_statements.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[15])); } } - if let Some(rule) = self.use_await.as_ref() { + if let Some(rule) = self.no_useless_ternary.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[16])); } } - if let Some(rule) = self.use_consistent_array_type.as_ref() { + if let Some(rule) = self.use_await.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[17])); } } - if let Some(rule) = self.use_export_type.as_ref() { + if let Some(rule) = self.use_consistent_array_type.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[18])); } } - if let Some(rule) = self.use_filenaming_convention.as_ref() { + if let Some(rule) = self.use_export_type.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[19])); } } - if let Some(rule) = self.use_for_of.as_ref() { + if let Some(rule) = self.use_filenaming_convention.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[20])); } } - if let Some(rule) = self.use_grouped_type_import.as_ref() { + if let Some(rule) = self.use_for_of.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[21])); } } - if let Some(rule) = self.use_import_restrictions.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[22])); } } - if let Some(rule) = self.use_import_type.as_ref() { + if let Some(rule) = self.use_import_restrictions.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[23])); } } - if let Some(rule) = self.use_nodejs_import_protocol.as_ref() { + if let Some(rule) = self.use_import_type.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[24])); } } - if let Some(rule) = self.use_number_namespace.as_ref() { + if let Some(rule) = self.use_nodejs_import_protocol.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[25])); } } - if let Some(rule) = self.use_shorthand_function_type.as_ref() { + if let Some(rule) = self.use_number_namespace.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[26])); } } - if let Some(rule) = self.use_sorted_classes.as_ref() { + if let Some(rule) = self.use_shorthand_function_type.as_ref() { if rule.is_enabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[27])); } } + if let Some(rule) = self.use_sorted_classes.as_ref() { + if rule.is_enabled() { + index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[28])); + } + } index_set } pub(crate) fn get_disabled_rules(&self) -> IndexSet { @@ -2619,96 +2629,101 @@ impl Nursery { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[9])); } } - if let Some(rule) = self.no_skipped_tests.as_ref() { + if let Some(rule) = self.no_restricted_imports.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[10])); } } - if let Some(rule) = self.no_then_property.as_ref() { + if let Some(rule) = self.no_skipped_tests.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[11])); } } - if let Some(rule) = self.no_unused_imports.as_ref() { + if let Some(rule) = self.no_then_property.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[12])); } } - if let Some(rule) = self.no_unused_private_class_members.as_ref() { + if let Some(rule) = self.no_unused_imports.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[13])); } } - if let Some(rule) = self.no_useless_lone_block_statements.as_ref() { + if let Some(rule) = self.no_unused_private_class_members.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[14])); } } - if let Some(rule) = self.no_useless_ternary.as_ref() { + if let Some(rule) = self.no_useless_lone_block_statements.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[15])); } } - if let Some(rule) = self.use_await.as_ref() { + if let Some(rule) = self.no_useless_ternary.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[16])); } } - if let Some(rule) = self.use_consistent_array_type.as_ref() { + if let Some(rule) = self.use_await.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[17])); } } - if let Some(rule) = self.use_export_type.as_ref() { + if let Some(rule) = self.use_consistent_array_type.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[18])); } } - if let Some(rule) = self.use_filenaming_convention.as_ref() { + if let Some(rule) = self.use_export_type.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[19])); } } - if let Some(rule) = self.use_for_of.as_ref() { + if let Some(rule) = self.use_filenaming_convention.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[20])); } } - if let Some(rule) = self.use_grouped_type_import.as_ref() { + if let Some(rule) = self.use_for_of.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[21])); } } - if let Some(rule) = self.use_import_restrictions.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[22])); } } - if let Some(rule) = self.use_import_type.as_ref() { + if let Some(rule) = self.use_import_restrictions.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[23])); } } - if let Some(rule) = self.use_nodejs_import_protocol.as_ref() { + if let Some(rule) = self.use_import_type.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[24])); } } - if let Some(rule) = self.use_number_namespace.as_ref() { + if let Some(rule) = self.use_nodejs_import_protocol.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[25])); } } - if let Some(rule) = self.use_shorthand_function_type.as_ref() { + if let Some(rule) = self.use_number_namespace.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[26])); } } - if let Some(rule) = self.use_sorted_classes.as_ref() { + if let Some(rule) = self.use_shorthand_function_type.as_ref() { if rule.is_disabled() { index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[27])); } } + if let Some(rule) = self.use_sorted_classes.as_ref() { + if rule.is_disabled() { + index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[28])); + } + } index_set } #[doc = r" Checks if, given a rule name, matches one of the rules contained in this category"] @@ -2722,7 +2737,7 @@ impl Nursery { pub(crate) fn recommended_rules_as_filters() -> [RuleFilter<'static>; 12] { Self::RECOMMENDED_RULES_AS_FILTERS } - pub(crate) fn all_rules_as_filters() -> [RuleFilter<'static>; 28] { + pub(crate) fn all_rules_as_filters() -> [RuleFilter<'static>; 29] { Self::ALL_RULES_AS_FILTERS } #[doc = r" Select preset rules"] @@ -2755,6 +2770,7 @@ impl Nursery { "noMisleadingCharacterClass" => self.no_misleading_character_class.as_ref(), "noNodejsModules" => self.no_nodejs_modules.as_ref(), "noReExportAll" => self.no_re_export_all.as_ref(), + "noRestrictedImports" => self.no_restricted_imports.as_ref(), "noSkippedTests" => self.no_skipped_tests.as_ref(), "noThenProperty" => self.no_then_property.as_ref(), "noUnusedImports" => self.no_unused_imports.as_ref(), diff --git a/packages/@biomejs/backend-jsonrpc/src/workspace.ts b/packages/@biomejs/backend-jsonrpc/src/workspace.ts index 0ec1319f28d6..67d42dc45b83 100644 --- a/packages/@biomejs/backend-jsonrpc/src/workspace.ts +++ b/packages/@biomejs/backend-jsonrpc/src/workspace.ts @@ -903,6 +903,10 @@ export interface Nursery { * Avoid re-export all */ noReExportAll?: RuleConfiguration; + /** + * Disallow specified modules when loaded by import or require. + */ + noRestrictedImports?: RuleConfiguration; /** * Disallow disabled tests. */ @@ -1421,6 +1425,7 @@ export type PossibleOptions = | DeprecatedHooksOptions | NamingConventionOptions | RestrictedGlobalsOptions + | RestrictedImportsOptions | ValidAriaRoleOptions | UtilityClassSortingOptions; /** @@ -1483,6 +1488,15 @@ export interface RestrictedGlobalsOptions { */ deniedGlobals: string[]; } +/** + * Options for the rule `noRestrictedImports`. + */ +export interface RestrictedImportsOptions { + /** + * A list of names that should trigger the rule + */ + paths: {}; +} export interface ValidAriaRoleOptions { allowInvalidRoles: string[]; ignoreNonDom: boolean; @@ -1714,6 +1728,7 @@ export type Category = | "lint/nursery/noMisleadingCharacterClass" | "lint/nursery/noNodejsModules" | "lint/nursery/noReExportAll" + | "lint/nursery/noRestrictedImports" | "lint/nursery/noSkippedTests" | "lint/nursery/noThenProperty" | "lint/nursery/noTypeOnlyImportAttributes" diff --git a/packages/@biomejs/biome/configuration_schema.json b/packages/@biomejs/biome/configuration_schema.json index f7a70f73dbb7..542fbeee1310 100644 --- a/packages/@biomejs/biome/configuration_schema.json +++ b/packages/@biomejs/biome/configuration_schema.json @@ -1358,6 +1358,13 @@ { "type": "null" } ] }, + "noRestrictedImports": { + "description": "Disallow specified modules when loaded by import or require.", + "anyOf": [ + { "$ref": "#/definitions/RuleConfiguration" }, + { "type": "null" } + ] + }, "noSkippedTests": { "description": "Disallow disabled tests.", "anyOf": [ @@ -1704,6 +1711,10 @@ "description": "Options for `noRestrictedGlobals` rule", "allOf": [{ "$ref": "#/definitions/RestrictedGlobalsOptions" }] }, + { + "description": "Options for `noRestrictedImports` rule", + "allOf": [{ "$ref": "#/definitions/RestrictedImportsOptions" }] + }, { "description": "Options for `useValidAriaRole` rule", "allOf": [{ "$ref": "#/definitions/ValidAriaRoleOptions" }] @@ -1729,6 +1740,19 @@ }, "additionalProperties": false }, + "RestrictedImportsOptions": { + "description": "Options for the rule `noRestrictedImports`.", + "type": "object", + "required": ["paths"], + "properties": { + "paths": { + "description": "A list of names that should trigger the rule", + "type": "object", + "additionalProperties": { "type": "string" } + } + }, + "additionalProperties": false + }, "RuleConfiguration": { "anyOf": [ { "$ref": "#/definitions/RulePlainConfiguration" }, diff --git a/website/src/components/generated/NumberOfRules.astro b/website/src/components/generated/NumberOfRules.astro index 136102735741..901fe345df2e 100644 --- a/website/src/components/generated/NumberOfRules.astro +++ b/website/src/components/generated/NumberOfRules.astro @@ -1,2 +1,2 @@ -

Biome's linter has a total of 198 rules

\ No newline at end of file +

Biome's linter has a total of 199 rules

\ No newline at end of file diff --git a/website/src/content/docs/linter/rules/index.mdx b/website/src/content/docs/linter/rules/index.mdx index 17474aaecf4b..93d12b48cef2 100644 --- a/website/src/content/docs/linter/rules/index.mdx +++ b/website/src/content/docs/linter/rules/index.mdx @@ -241,8 +241,8 @@ Rules that belong to this group are not subject to semantic version🔧 | | [noNodejsModules](/linter/rules/no-nodejs-modules) | Forbid the use of Node.js builtin modules. | | -| [noRestrictedImports](/linter/rules/no-restricted-imports) | Disallow specified modules when loaded by import or require. | | | [noReExportAll](/linter/rules/no-re-export-all) | Avoid re-export all | | +| [noRestrictedImports](/linter/rules/no-restricted-imports) | Disallow specified modules when loaded by import or require. | | | [noSkippedTests](/linter/rules/no-skipped-tests) | Disallow disabled tests. | | | [noThenProperty](/linter/rules/no-then-property) | Disallow then property. | | | [noUnusedImports](/linter/rules/no-unused-imports) | Disallow unused imports. | 🔧 | diff --git a/website/src/content/docs/linter/rules/no-restricted-imports.md b/website/src/content/docs/linter/rules/no-restricted-imports.md index 71c2ef293169..241866bfe2eb 100644 --- a/website/src/content/docs/linter/rules/no-restricted-imports.md +++ b/website/src/content/docs/linter/rules/no-restricted-imports.md @@ -16,8 +16,6 @@ Source: