Skip to content

Commit

Permalink
refactor: allow new clippy rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Sep 18, 2024
1 parent e2e6850 commit be4f0a1
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 80 deletions.
27 changes: 18 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ empty_docs = "allow" # there are some false positives inside biome_
multiple_crate_versions = "allow"

# pedantic
assigning_clones = "warn"
checked_conversions = "warn"
cloned_instead_of_copied = "warn"
copy_iterator = "warn"
Expand All @@ -35,10 +36,12 @@ implicit_hasher = "warn"
index_refutable_slice = "warn"
inefficient_to_string = "warn"
invalid_upcast_comparisons = "warn"
iter_filter_is_ok = "warn"
iter_not_returning_iterator = "warn"
large_stack_arrays = "warn"
large_types_passed_by_value = "warn"
macro_use_imports = "warn"
manual_is_variant_and = "warn"
manual_ok_or = "warn"
manual_string_new = "warn"
map_flatten = "warn"
Expand All @@ -50,9 +53,12 @@ needless_bitwise_bool = "warn"
needless_continue = "warn"
needless_for_each = "warn"
no_effect_underscore_binding = "warn"
option_as_ref_cloned = "warn"
ref_binding_to_reference = "warn"
ref_option_ref = "warn"
single_char_pattern = "warn"
stable_sort_primitive = "warn"
str_split_at_newline = "warn"
unnecessary_box_returns = "warn"
unnecessary_join = "warn"
unnested_or_patterns = "warn"
Expand All @@ -61,15 +67,18 @@ verbose_bit_mask = "warn"
zero_sized_map_values = "warn"

# restriction
empty_drop = "warn"
float_cmp_const = "warn"
get_unwrap = "warn"
infinite_loop = "warn"
lossy_float_literal = "warn"
rc_buffer = "warn"
rc_mutex = "warn"
rest_pat_in_fully_bound_structs = "warn"
verbose_file_reads = "warn"
cfg_not_test = "warn"
empty_drop = "warn"
empty_enum_variants_with_brackets = "warn"
float_cmp_const = "warn"
get_unwrap = "warn"
infinite_loop = "warn"
lossy_float_literal = "warn"
rc_buffer = "warn"
rc_mutex = "warn"
rest_pat_in_fully_bound_structs = "warn"
string_lit_chars_any = "warn"
verbose_file_reads = "warn"
# https://github.com/rustwasm/wasm-bindgen/issues/3944
#mem_forget = "warn"

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_grit_patterns/src/grit_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Iterator for AncestorIterator {
type Item = GritNode;

fn next(&mut self) -> Option<Self::Item> {
let node = self.node.as_ref().cloned()?;
let node = self.node.clone()?;
self.node = node.parent();
Some(node)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_grit_patterns/src/grit_target_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl<'a> Iterator for AncestorIterator<'a> {
type Item = GritTargetNode<'a>;

fn next(&mut self) -> Option<Self::Item> {
let node = self.node.as_ref().cloned()?;
let node = self.node.clone()?;
self.node = node.parent();
Some(node)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,7 @@ impl Visitor for CognitiveComplexityVisitor {
impl CognitiveComplexityVisitor {
fn on_enter(&mut self, node: &JsSyntaxNode) {
let parent = self.stack.last();
if parent
.map(|parent| parent.score == MAX_SCORE)
.unwrap_or_default()
{
if parent.is_some_and(|parent| parent.score == MAX_SCORE) {
return; // No need for further processing if we're already at the max.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,20 +386,17 @@ fn has_curly_braces(node: &AnyJsxCurlyQuery) -> bool {
}

fn contains_string_literal(node: &JsxExpressionAttributeValue) -> bool {
node.expression()
.map(|expr| {
matches!(
expr,
AnyJsExpression::AnyJsLiteralExpression(
AnyJsLiteralExpression::JsStringLiteralExpression(_)
)
node.expression().is_ok_and(|expr| {
matches!(
expr,
AnyJsExpression::AnyJsLiteralExpression(
AnyJsLiteralExpression::JsStringLiteralExpression(_)
)
})
.unwrap_or_default()
)
})
}

fn contains_jsx_tag(node: &JsxExpressionAttributeValue) -> bool {
node.expression()
.map(|expr| matches!(expr, AnyJsExpression::JsxTagExpression(_)))
.unwrap_or_default()
.is_ok_and(|expr| matches!(expr, AnyJsExpression::JsxTagExpression(_)))
}
12 changes: 4 additions & 8 deletions crates/biome_js_analyze/src/services/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,28 @@ impl ManifestServices {
self.manifest
.as_ref()
.as_ref()
.map(|pkg| pkg.dependencies.contains(specifier))
.unwrap_or_default()
.is_some_and(|pkg| pkg.dependencies.contains(specifier))
}

pub(crate) fn is_dev_dependency(&self, specifier: &str) -> bool {
self.manifest
.as_ref()
.as_ref()
.map(|pkg| pkg.dev_dependencies.contains(specifier))
.unwrap_or_default()
.is_some_and(|pkg| pkg.dev_dependencies.contains(specifier))
}

pub(crate) fn is_peer_dependency(&self, specifier: &str) -> bool {
self.manifest
.as_ref()
.as_ref()
.map(|pkg| pkg.peer_dependencies.contains(specifier))
.unwrap_or_default()
.is_some_and(|pkg| pkg.peer_dependencies.contains(specifier))
}

pub(crate) fn is_optional_dependency(&self, specifier: &str) -> bool {
self.manifest
.as_ref()
.as_ref()
.map(|pkg| pkg.optional_dependencies.contains(specifier))
.unwrap_or_default()
.is_some_and(|pkg| pkg.optional_dependencies.contains(specifier))
}
}

Expand Down
22 changes: 9 additions & 13 deletions crates/biome_js_analyze/src/suppression_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,14 @@ impl SuppressionAction for JsSuppressionAction {
// There are some tokens that might contains newlines in their tokens, only
// few nodes matches this criteria. If the token is inside one of those nodes,
// then we check its content.
let nodes_that_might_contain_newlines = current_token
.parent()
.map(|node| {
matches!(
node.kind(),
JsSyntaxKind::JSX_TEXT
| JsSyntaxKind::JS_STRING_LITERAL
| JsSyntaxKind::TEMPLATE_CHUNK
)
})
.unwrap_or_default();
let nodes_that_might_contain_newlines = current_token.parent().is_some_and(|node| {
matches!(
node.kind(),
JsSyntaxKind::JSX_TEXT
| JsSyntaxKind::JS_STRING_LITERAL
| JsSyntaxKind::TEMPLATE_CHUNK
)
});
if current_token
.trailing_trivia()
.pieces()
Expand Down Expand Up @@ -154,8 +151,7 @@ impl SuppressionAction for JsSuppressionAction {
// quick check is the element is inside a list
if current_jsx_element
.parent()
.map(|p| JsxChildList::can_cast(p.kind()))
.unwrap_or_default()
.is_some_and(|p| JsxChildList::can_cast(p.kind()))
{
let jsx_comment = jsx_expression_child(
token(T!['{']).with_trailing_trivia([(
Expand Down
3 changes: 1 addition & 2 deletions crates/biome_js_syntax/src/expr_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ impl JsReferenceIdentifier {
/// ```
pub fn has_name(&self, name: &str) -> bool {
self.value_token()
.map(|token| token.text_trimmed() == name)
.unwrap_or_default()
.is_ok_and(|token| token.text_trimmed() == name)
}

pub fn name(&self) -> SyntaxResult<TokenText> {
Expand Down
16 changes: 7 additions & 9 deletions crates/biome_service/src/file_handlers/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,13 @@ fn parse(
) -> ParseResult {
let mut options = JsParserOptions {
grit_metavariables: false,
parse_class_parameter_decorators: settings
.map(|settings| {
settings
.languages
.javascript
.parser
.parse_class_parameter_decorators
})
.unwrap_or_default(),
parse_class_parameter_decorators: settings.is_some_and(|settings| {
settings
.languages
.javascript
.parser
.parse_class_parameter_decorators
}),
};
if let Some(settings) = settings {
options = settings
Expand Down
3 changes: 1 addition & 2 deletions crates/biome_service/src/file_handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,8 +1006,7 @@ impl<'a, 'b> AssistsVisitor<'a, 'b> {

let organize_imports_enabled = self
.settings
.map(|settings| settings.organize_imports.enabled)
.unwrap_or_default();
.is_some_and(|settings| settings.organize_imports.enabled);
if organize_imports_enabled && self.import_sorting.match_rule::<R>() {
self.enabled_rules.push(self.import_sorting);
return;
Expand Down
3 changes: 1 addition & 2 deletions crates/biome_service/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ impl FileFeaturesResult {
fn supports_for(&self, feature: &FeatureKind) -> bool {
self.features_supported
.get(feature)
.map(|support_kind| matches!(support_kind, SupportKind::Supported))
.unwrap_or_default()
.is_some_and(|support_kind| matches!(support_kind, SupportKind::Supported))
}

pub fn supports_lint(&self) -> bool {
Expand Down
31 changes: 13 additions & 18 deletions crates/biome_service/src/workspace/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,24 +311,19 @@ impl WorkspaceServer {
|| settings.files.included_files.matches_path(path);
!is_included
|| settings.files.ignored_files.matches_path(path)
|| settings
.files
.git_ignore
.as_ref()
.map(|ignore| {
// `matched_path_or_any_parents` panics if `source` is not under the gitignore root.
// This checks excludes absolute paths that are not a prefix of the base root.
if !path.has_root() || path.starts_with(ignore.path()) {
// Because Biome passes a list of paths,
// we use `matched_path_or_any_parents` instead of `matched`.
ignore
.matched_path_or_any_parents(path, path.is_dir())
.is_ignore()
} else {
false
}
})
.unwrap_or_default()
|| settings.files.git_ignore.as_ref().is_some_and(|ignore| {
// `matched_path_or_any_parents` panics if `source` is not under the gitignore root.
// This checks excludes absolute paths that are not a prefix of the base root.
if !path.has_root() || path.starts_with(ignore.path()) {
// Because Biome passes a list of paths,
// we use `matched_path_or_any_parents` instead of `matched`.
ignore
.matched_path_or_any_parents(path, path.is_dir())
.is_ignore()
} else {
false
}
})
}

/// Check whether a file is ignored in the feature `ignore`/`include`
Expand Down

0 comments on commit be4f0a1

Please sign in to comment.