Skip to content

Commit

Permalink
feat(lint): useCollapsedIf JS lint rule (#4179)
Browse files Browse the repository at this point in the history
Signed-off-by: Naoki Ikeguchi <[email protected]>
  • Loading branch information
siketyan authored Oct 16, 2024
1 parent 89d34b2 commit bbb93b9
Show file tree
Hide file tree
Showing 12 changed files with 1,534 additions and 24 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 43 additions & 24 deletions crates/biome_configuration/src/analyzer/linter/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3395,6 +3395,9 @@ pub struct Nursery {
#[doc = "Use at() instead of integer index access."]
#[serde(skip_serializing_if = "Option::is_none")]
pub use_at_index: Option<RuleFixConfiguration<biome_js_analyze::options::UseAtIndex>>,
#[doc = "Enforce using single if instead of nested if clauses."]
#[serde(skip_serializing_if = "Option::is_none")]
pub use_collapsed_if: Option<RuleFixConfiguration<biome_js_analyze::options::UseCollapsedIf>>,
#[doc = "Enforce declaring components only within modules that export React Components exclusively."]
#[serde(skip_serializing_if = "Option::is_none")]
pub use_component_export_only_modules:
Expand Down Expand Up @@ -3488,6 +3491,7 @@ impl Nursery {
"useAdjacentOverloadSignatures",
"useAriaPropsSupportedByRole",
"useAtIndex",
"useCollapsedIf",
"useComponentExportOnlyModules",
"useConsistentCurlyBraces",
"useConsistentMemberAccessibility",
Expand Down Expand Up @@ -3528,9 +3532,9 @@ impl Nursery {
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[27]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[28]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[32]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[36]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[37]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[42]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[38]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[43]),
];
const ALL_RULES_AS_FILTERS: &'static [RuleFilter<'static>] = &[
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[0]),
Expand Down Expand Up @@ -3578,6 +3582,7 @@ impl Nursery {
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[42]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[43]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[44]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[45]),
];
#[doc = r" Retrieves the recommended rules"]
pub(crate) fn is_recommended_true(&self) -> bool {
Expand Down Expand Up @@ -3764,61 +3769,66 @@ impl Nursery {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[33]));
}
}
if let Some(rule) = self.use_component_export_only_modules.as_ref() {
if let Some(rule) = self.use_collapsed_if.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[34]));
}
}
if let Some(rule) = self.use_consistent_curly_braces.as_ref() {
if let Some(rule) = self.use_component_export_only_modules.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[35]));
}
}
if let Some(rule) = self.use_consistent_member_accessibility.as_ref() {
if let Some(rule) = self.use_consistent_curly_braces.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[36]));
}
}
if let Some(rule) = self.use_deprecated_reason.as_ref() {
if let Some(rule) = self.use_consistent_member_accessibility.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[37]));
}
}
if let Some(rule) = self.use_explicit_type.as_ref() {
if let Some(rule) = self.use_deprecated_reason.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[38]));
}
}
if let Some(rule) = self.use_guard_for_in.as_ref() {
if let Some(rule) = self.use_explicit_type.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[39]));
}
}
if let Some(rule) = self.use_import_restrictions.as_ref() {
if let Some(rule) = self.use_guard_for_in.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[40]));
}
}
if let Some(rule) = self.use_sorted_classes.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[41]));
}
}
if let Some(rule) = self.use_strict_mode.as_ref() {
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[42]));
}
}
if let Some(rule) = self.use_trim_start_end.as_ref() {
if let Some(rule) = self.use_strict_mode.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[43]));
}
}
if let Some(rule) = self.use_valid_autocomplete.as_ref() {
if let Some(rule) = self.use_trim_start_end.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[44]));
}
}
if let Some(rule) = self.use_valid_autocomplete.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[45]));
}
}
index_set
}
pub(crate) fn get_disabled_rules(&self) -> FxHashSet<RuleFilter<'static>> {
Expand Down Expand Up @@ -3993,61 +4003,66 @@ impl Nursery {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[33]));
}
}
if let Some(rule) = self.use_component_export_only_modules.as_ref() {
if let Some(rule) = self.use_collapsed_if.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[34]));
}
}
if let Some(rule) = self.use_consistent_curly_braces.as_ref() {
if let Some(rule) = self.use_component_export_only_modules.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[35]));
}
}
if let Some(rule) = self.use_consistent_member_accessibility.as_ref() {
if let Some(rule) = self.use_consistent_curly_braces.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[36]));
}
}
if let Some(rule) = self.use_deprecated_reason.as_ref() {
if let Some(rule) = self.use_consistent_member_accessibility.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[37]));
}
}
if let Some(rule) = self.use_explicit_type.as_ref() {
if let Some(rule) = self.use_deprecated_reason.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[38]));
}
}
if let Some(rule) = self.use_guard_for_in.as_ref() {
if let Some(rule) = self.use_explicit_type.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[39]));
}
}
if let Some(rule) = self.use_import_restrictions.as_ref() {
if let Some(rule) = self.use_guard_for_in.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[40]));
}
}
if let Some(rule) = self.use_sorted_classes.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[41]));
}
}
if let Some(rule) = self.use_strict_mode.as_ref() {
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[42]));
}
}
if let Some(rule) = self.use_trim_start_end.as_ref() {
if let Some(rule) = self.use_strict_mode.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[43]));
}
}
if let Some(rule) = self.use_valid_autocomplete.as_ref() {
if let Some(rule) = self.use_trim_start_end.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[44]));
}
}
if let Some(rule) = self.use_valid_autocomplete.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[45]));
}
}
index_set
}
#[doc = r" Checks if, given a rule name, matches one of the rules contained in this category"]
Expand Down Expand Up @@ -4220,6 +4235,10 @@ impl Nursery {
.use_at_index
.as_ref()
.map(|conf| (conf.level(), conf.get_options())),
"useCollapsedIf" => self
.use_collapsed_if
.as_ref()
.map(|conf| (conf.level(), conf.get_options())),
"useComponentExportOnlyModules" => self
.use_component_export_only_modules
.as_ref()
Expand Down
1 change: 1 addition & 0 deletions crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ define_categories! {
"lint/nursery/useAriaPropsSupportedByRole": "https://biomejs.dev/linter/rules/use-aria-props-supported-by-role",
"lint/nursery/useAtIndex": "https://biomejs.dev/linter/rules/use-at-index",
"lint/nursery/useBiomeSuppressionComment": "https://biomejs.dev/linter/rules/use-biome-suppression-comment",
"lint/nursery/useCollapsedIf": "https://biomejs.dev/linter/rules/use-collapsed-if",
"lint/nursery/useComponentExportOnlyModules": "https://biomejs.dev/linter/rules/use-components-only-module",
"lint/nursery/useConsistentCurlyBraces": "https://biomejs.dev/linter/rules/use-consistent-curly-braces",
"lint/nursery/useConsistentMemberAccessibility": "https://biomejs.dev/linter/rules/use-consistent-member-accessibility",
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_js_analyze/src/lint/nursery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod no_useless_string_raw;
pub mod use_adjacent_overload_signatures;
pub mod use_aria_props_supported_by_role;
pub mod use_at_index;
pub mod use_collapsed_if;
pub mod use_component_export_only_modules;
pub mod use_consistent_curly_braces;
pub mod use_consistent_member_accessibility;
Expand Down Expand Up @@ -67,6 +68,7 @@ declare_lint_group! {
self :: use_adjacent_overload_signatures :: UseAdjacentOverloadSignatures ,
self :: use_aria_props_supported_by_role :: UseAriaPropsSupportedByRole ,
self :: use_at_index :: UseAtIndex ,
self :: use_collapsed_if :: UseCollapsedIf ,
self :: use_component_export_only_modules :: UseComponentExportOnlyModules ,
self :: use_consistent_curly_braces :: UseConsistentCurlyBraces ,
self :: use_consistent_member_accessibility :: UseConsistentMemberAccessibility ,
Expand Down
Loading

0 comments on commit bbb93b9

Please sign in to comment.