Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lint): add rule useAtIndex #4120

Merged
merged 50 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8445e7e
add: rule useAtIndex
GunseiKPaseri Sep 28, 2024
52c2ac0
add: rule document
GunseiKPaseri Sep 28, 2024
34e3279
fix: add_option & better error message
GunseiKPaseri Sep 28, 2024
102397d
fix: replace snapshot
GunseiKPaseri Sep 28, 2024
af07b0f
add: fix [hoge.length - unknown - 1]
GunseiKPaseri Sep 29, 2024
03cb8ef
add: fix slice(hoge)[0]
GunseiKPaseri Sep 29, 2024
2c0e290
refactor: Use Cow to remove unnecessary clones of error messages
GunseiKPaseri Sep 29, 2024
927444e
refactor: use math(at_vaue, arg.len())
GunseiKPaseri Sep 29, 2024
53a51ca
refactor: split the function
GunseiKPaseri Sep 29, 2024
46fd905
refactor: fix solve_parenthesized_expression ownership
GunseiKPaseri Sep 29, 2024
94f103e
refactor: use match touple
GunseiKPaseri Sep 29, 2024
bf4c03c
refactor: Organize the error types for slice
GunseiKPaseri Sep 29, 2024
7a388cc
refactor: convert SliceType to struct
GunseiKPaseri Sep 29, 2024
9a3d9a6
refactor: impl struct function
GunseiKPaseri Sep 29, 2024
fe32c96
refactor: use match {_ if hoge => ... }
GunseiKPaseri Sep 29, 2024
9e17312
refactor: integrate the branches in ErrorType::Slice
GunseiKPaseri Sep 29, 2024
df06a49
test: use .jsonc
GunseiKPaseri Sep 29, 2024
2ff8b95
test: add no lodash testcase
GunseiKPaseri Sep 29, 2024
e14e34a
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 3, 2024
d4f6da4
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 3, 2024
fef17d3
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 3, 2024
c5986d8
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 3, 2024
0b83a26
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 3, 2024
3f470f1
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 3, 2024
794b3a4
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 3, 2024
2371f54
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 3, 2024
58cea0d
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 3, 2024
80c8eaa
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 3, 2024
8057c53
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 3, 2024
6c7d450
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 3, 2024
8f309f7
fix: use initialize the struct
GunseiKPaseri Oct 3, 2024
637c44d
fix: remove fix rule for lodash
GunseiKPaseri Oct 3, 2024
ded38aa
fix: Omission of modifications in the proposed corrections.
GunseiKPaseri Oct 3, 2024
cc56e7f
refactor: rename function
GunseiKPaseri Oct 3, 2024
8c45f9b
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 3, 2024
5bb55e8
fix: remove check_all_index_access option
GunseiKPaseri Oct 3, 2024
bc1d20c
fix: use omit_parentheses()
GunseiKPaseri Oct 3, 2024
2305e65
fix: use .get_arguments_by_index([])
GunseiKPaseri Oct 3, 2024
827d4a8
doc: replace "hoge" => "foo"
GunseiKPaseri Oct 3, 2024
29324d7
refactor: move impl Rule
GunseiKPaseri Oct 3, 2024
9aebbb7
Merge branch 'main' into use-at-index
GunseiKPaseri Oct 3, 2024
4516098
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 9, 2024
ab9d214
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 9, 2024
90d2c97
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 9, 2024
4528b4e
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 9, 2024
44109dc
Update crates/biome_js_analyze/src/lint/nursery/use_at_index.rs
GunseiKPaseri Oct 9, 2024
456efb0
refactor: format & lint
GunseiKPaseri Oct 9, 2024
5fbbe90
doc: fix comment typo
GunseiKPaseri Oct 9, 2024
4a98336
test: fix test
GunseiKPaseri Oct 9, 2024
387634a
Merge branch 'main' into use-at-index
GunseiKPaseri Oct 9, 2024
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
12 changes: 12 additions & 0 deletions crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs

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

63 changes: 41 additions & 22 deletions crates/biome_configuration/src/analyzer/linter/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3377,6 +3377,9 @@ pub struct Nursery {
#[serde(skip_serializing_if = "Option::is_none")]
pub use_aria_props_supported_by_role:
Option<RuleConfiguration<biome_js_analyze::options::UseAriaPropsSupportedByRole>>,
#[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 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 @@ -3463,6 +3466,7 @@ impl Nursery {
"noValueAtRule",
"useAdjacentOverloadSignatures",
"useAriaPropsSupportedByRole",
"useAtIndex",
"useComponentExportOnlyModules",
"useConsistentCurlyBraces",
"useConsistentMemberAccessibility",
Expand Down Expand Up @@ -3500,9 +3504,9 @@ 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[28]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[31]),
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[33]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[37]),
];
const ALL_RULES_AS_FILTERS: &'static [RuleFilter<'static>] = &[
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[0]),
Expand Down Expand Up @@ -3544,6 +3548,7 @@ impl Nursery {
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[38]),
RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[39]),
];
#[doc = r" Retrieves the recommended rules"]
pub(crate) fn is_recommended_true(&self) -> bool {
Expand Down Expand Up @@ -3705,56 +3710,61 @@ impl Nursery {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[28]));
}
}
if let Some(rule) = self.use_component_export_only_modules.as_ref() {
if let Some(rule) = self.use_at_index.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[29]));
}
}
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[30]));
}
}
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[31]));
}
}
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[32]));
}
}
if let Some(rule) = self.use_explicit_function_return_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[33]));
}
}
if let Some(rule) = self.use_import_restrictions.as_ref() {
if let Some(rule) = self.use_explicit_function_return_type.as_ref() {
if rule.is_enabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[34]));
}
}
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[35]));
}
}
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[36]));
}
}
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[37]));
}
}
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[38]));
}
}
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[39]));
}
}
index_set
}
pub(crate) fn get_disabled_rules(&self) -> FxHashSet<RuleFilter<'static>> {
Expand Down Expand Up @@ -3904,56 +3914,61 @@ impl Nursery {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[28]));
}
}
if let Some(rule) = self.use_component_export_only_modules.as_ref() {
if let Some(rule) = self.use_at_index.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[29]));
}
}
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[30]));
}
}
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[31]));
}
}
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[32]));
}
}
if let Some(rule) = self.use_explicit_function_return_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[33]));
}
}
if let Some(rule) = self.use_import_restrictions.as_ref() {
if let Some(rule) = self.use_explicit_function_return_type.as_ref() {
if rule.is_disabled() {
index_set.insert(RuleFilter::Rule(Self::GROUP_NAME, Self::GROUP_RULES[34]));
}
}
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[35]));
}
}
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[36]));
}
}
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[37]));
}
}
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[38]));
}
}
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[39]));
}
}
index_set
}
#[doc = r" Checks if, given a rule name, matches one of the rules contained in this category"]
Expand Down Expand Up @@ -4106,6 +4121,10 @@ impl Nursery {
.use_aria_props_supported_by_role
.as_ref()
.map(|conf| (conf.level(), conf.get_options())),
"useAtIndex" => self
.use_at_index
.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 @@ -182,6 +182,7 @@ define_categories! {
"lint/nursery/noValueAtRule": "https://biomejs.dev/linter/rules/no-value-at-rule",
"lint/nursery/useAdjacentOverloadSignatures": "https://biomejs.dev/linter/rules/use-adjacent-overload-signatures",
"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/useComponentExportOnlyModules": "https://biomejs.dev/linter/rules/use-components-only-module",
"lint/nursery/useConsistentCurlyBraces": "https://biomejs.dev/linter/rules/use-consistent-curly-braces",
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 @@ -23,6 +23,7 @@ pub mod no_template_curly_in_string;
pub mod no_useless_escape_in_regex;
pub mod use_adjacent_overload_signatures;
pub mod use_aria_props_supported_by_role;
pub mod use_at_index;
pub mod use_component_export_only_modules;
pub mod use_consistent_curly_braces;
pub mod use_consistent_member_accessibility;
Expand Down Expand Up @@ -58,6 +59,7 @@ declare_lint_group! {
self :: no_useless_escape_in_regex :: NoUselessEscapeInRegex ,
self :: use_adjacent_overload_signatures :: UseAdjacentOverloadSignatures ,
self :: use_aria_props_supported_by_role :: UseAriaPropsSupportedByRole ,
self :: use_at_index :: UseAtIndex ,
self :: use_component_export_only_modules :: UseComponentExportOnlyModules ,
self :: use_consistent_curly_braces :: UseConsistentCurlyBraces ,
self :: use_consistent_member_accessibility :: UseConsistentMemberAccessibility ,
Expand Down
Loading