Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ similar_names = "allow"
fn_params_excessive_bools = "allow"
complexity = { level = "warn", priority = -1 }
too_many_arguments = "allow"
non_std_lazy_statics = "allow"
needless_continue = "allow" # FIXME
# nursery
nursery = { level = "warn", priority = -1 }
# `const` functions do not make sense for our project because this is not a `const` library.
Expand Down
16 changes: 10 additions & 6 deletions apps/oxlint/src/output_formatter/stylish.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Write;

use oxc_diagnostics::{
Error, Severity,
reporter::{DiagnosticReporter, DiagnosticResult, Info},
Expand Down Expand Up @@ -70,7 +72,7 @@ fn format_stylish(diagnostics: &[Error]) -> String {
.max()
.unwrap_or(0);

output.push_str(&format!("\n\u{1b}[4m{filename}\u{1b}[0m\n"));
let _ = write!(output, "\n\u{1b}[4m{filename}\u{1b}[0m\n");

for diagnostic in diagnostics {
match diagnostic.severity() {
Expand All @@ -87,21 +89,23 @@ fn format_stylish(diagnostics: &[Error]) -> String {
let info = Info::new(diagnostic);
let rule = diagnostic.code().map_or_else(String::new, |code| code.to_string());
let position = format!("{}:{}", info.start.line, info.start.column);
output.push_str(
&format!(" \u{1b}[2m{position:max_len_width$}\u{1b}[0m {severity_str} {diagnostic} \u{1b}[2m{rule}\u{1b}[0m\n"),
let _ = writeln!(
output,
" \u{1b}[2m{position:max_len_width$}\u{1b}[0m {severity_str} {diagnostic} \u{1b}[2m{rule}\u{1b}[0m"
);
}
}

let total = total_errors + total_warnings;
if total > 0 {
let summary_color = if total_errors > 0 { "\u{1b}[31m" } else { "\u{1b}[33m" };
output.push_str(&format!(
"\n{summary_color}✖ {total} problem{} ({total_errors} error{}, {total_warnings} warning{})\u{1b}[0m\n",
let _ = writeln!(
output,
"\n{summary_color}✖ {total} problem{} ({total_errors} error{}, {total_warnings} warning{})\u{1b}[0m",
if total == 1 { "" } else { "s" },
if total_errors == 1 { "" } else { "s" },
if total_warnings == 1 { "" } else { "s" }
));
);
}

output
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_codegen/src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ impl Codegen<'_> {
}
if Self::should_keep_leading_comment(&comment) {
leading_comments.push(comment);
continue;
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_ecmascript/src/constant_evaluation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub trait ConstantEvaluation<'a>: MayHaveSideEffects {
/// Use the specific functions (e.g. [`ConstantEvaluation::evaluate_value_to_boolean`], [`ConstantEvaluation::evaluate_value`]).
///
/// - target_ty: How the result will be used.
/// For example, if the result will be converted to a boolean,
/// passing `Some(ValueType::Boolean)` will allow to utilize that information.
/// For example, if the result will be converted to a boolean,
/// passing `Some(ValueType::Boolean)` will allow to utilize that information.
fn evaluate_value_to(
&self,
ctx: &impl ConstantEvaluationCtx<'a>,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ecmascript/src/string_to_big_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl StringToBigInt<'_> for &str {
return None;
}

return BigInt::parse_bytes(s[2..].as_bytes(), radix);
return BigInt::parse_bytes(&s.as_bytes()[2..], radix);
}

BigInt::parse_bytes(s.as_bytes(), 10)
Expand Down
13 changes: 4 additions & 9 deletions crates/oxc_formatter/src/formatter/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,23 +546,18 @@ fn clean_interned(
match element {
FormatElement::Tag(Tag::StartConditionalContent(condition)) => {
condition_content_stack.push(condition.clone());
continue;
}
FormatElement::Tag(Tag::EndConditionalContent) => {
condition_content_stack.pop();
continue;
}
// All content within an expanded conditional gets dropped. If there's a
// matching flat variant, that will still get kept.
_ if condition_content_stack
.iter()
.last()
.is_some_and(|condition| condition.mode == PrintMode::Expanded) =>
{
continue;
}
.is_some_and(|condition| condition.mode == PrintMode::Expanded) => {}

FormatElement::Line(LineMode::Soft) => continue,
FormatElement::Line(LineMode::Soft) => {}
FormatElement::Line(LineMode::SoftOrSpace) => {
cleaned.push(FormatElement::Space);
}
Expand Down Expand Up @@ -610,9 +605,9 @@ impl<'ast> Buffer<'ast> for RemoveSoftLinesBuffer<'_, 'ast> {
}
// All content within an expanded conditional gets dropped. If there's a
// matching flat variant, that will still get kept.
_ if self.is_in_expanded_conditional_content() => continue,
_ if self.is_in_expanded_conditional_content() => {}

FormatElement::Line(LineMode::Soft) => continue,
FormatElement::Line(LineMode::Soft) => {}
FormatElement::Line(LineMode::SoftOrSpace) => {
self.inner.write_element(FormatElement::Space)?;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_formatter/src/formatter/comments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ pub enum CommentPlacement {
/// Makes the comment a...
///
/// * [trailing comment] of the [`preceding_node`] if both the [`following_node`] and [`preceding_node`] are not [None]
/// and the comment and [`preceding_node`] are only separated by a space (there's no token between the comment and [`preceding_node`]).
/// and the comment and [`preceding_node`] are only separated by a space (there's no token between the comment and [`preceding_node`]).
/// * [leading comment] of the [`following_node`] if the [`following_node`] is not [None]
/// * [trailing comment] of the [`preceding_node`] if the [`preceding_node`] is not [None]
/// * [dangling comment] of the [`enclosing_node`].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ impl FormatElements for [FormatElement] {
element if ignore_depth == 0 && element.will_break() => {
return true;
}
_ => continue,
_ => {}
}
}

Expand Down Expand Up @@ -628,7 +628,7 @@ impl FormatElements for [FormatElement] {
element if ignore_depth == 0 && element.may_directly_break() => {
return true;
}
_ => continue,
_ => {}
}
}

Expand Down
2 changes: 0 additions & 2 deletions crates/oxc_formatter/src/formatter/printer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,6 @@ impl<'a, 'print> FitsMeasurer<'a, 'print> {
if predicate.is_end(element)? {
break;
}

continue;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_isolated_declarations/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl<'a> IsolatedDeclarations<'a> {
method_annotations.insert(name, annotation);
}
}
_ => continue,
_ => {}
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions crates/oxc_isolated_declarations/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod deno;

use std::{fs, path::Path, sync::Arc};
use std::{fmt::Write, fs, path::Path, sync::Arc};

use oxc_allocator::Allocator;
use oxc_codegen::CodeGenerator;
Expand Down Expand Up @@ -28,9 +28,10 @@ fn transform(path: &Path, source_text: &str) -> String {
.map(|d| d.clone().with_source_code(Arc::clone(&source)))
.fold(String::new(), |s, error| s + &format!("{error:?}"));

snapshot.push_str(&format!(
let _ = write!(
snapshot,
"==================== Errors ====================\n{error_messages}\n\n```"
));
);
}

snapshot
Expand Down
18 changes: 9 additions & 9 deletions crates/oxc_language_server/src/linter/tester.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Write;

use oxc_linter::Linter;
use tower_lsp::lsp_types::{CodeDescription, NumberOrString, Url};

Expand Down Expand Up @@ -29,10 +31,8 @@ fn get_snapshot_from_report(report: &DiagnosticReport) -> String {
.enumerate()
.map(|(i, info)| {
let mut result = String::new();
result.push_str(&format!(
"related_information[{}].message: {:?}",
i, info.message
));
let _ =
write!(result, "related_information[{}].message: {:?}", i, info.message);
// replace everything between `file://` and `oxc_language_server` with `<variable>`, to avoid
// the absolute path causing snapshot test failures in different environments
let mut location = info.location.uri.to_string();
Expand All @@ -46,13 +46,13 @@ fn get_snapshot_from_report(report: &DiagnosticReport) -> String {
"<variable>",
);

result.push_str(&format!(
"\nrelated_information[{i}].location.uri: {location:?}",
));
result.push_str(&format!(
let _ =
write!(result, "\nrelated_information[{i}].location.uri: {location:?}",);
let _ = write!(
result,
"\nrelated_information[{}].location.range: {:?}",
i, info.location.range
));
);
result
})
.collect::<Vec<_>>()
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/ast_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ pub fn get_static_property_name<'a>(parent_node: &AstNode<'a>) -> Option<Cow<'a,
}
PropertyKey::BigIntLiteral(bigint) => Some(Cow::Borrowed(bigint.raw.as_str())),
PropertyKey::TemplateLiteral(template) => {
if template.expressions.len() == 0 && template.quasis.len() == 1 {
if template.expressions.is_empty() && template.quasis.len() == 1 {
if let Some(cooked) = &template.quasis[0].value.cooked {
return Some(Cow::Borrowed(cooked.as_str()));
}
Expand Down
5 changes: 3 additions & 2 deletions crates/oxc_linter/src/loader/partial_loader/astro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ impl<'a> AstroPartialLoader<'a> {
let js_start;
let js_end;
// find opening "<script"
if let Some(offset) = script_start_finder.find(self.source_text[pointer..].as_bytes()) {
if let Some(offset) = script_start_finder.find(&self.source_text.as_bytes()[pointer..])
{
pointer += offset + SCRIPT_START.len();
} else {
break;
Expand All @@ -78,7 +79,7 @@ impl<'a> AstroPartialLoader<'a> {
js_end = pointer;
// find "</script>" if no self closing tag was found
} else if let Some(offset) =
script_end_finder.find(self.source_text[pointer..].as_bytes())
script_end_finder.find(&self.source_text.as_bytes()[pointer..])
{
js_end = pointer + offset;
pointer += offset + SCRIPT_END.len();
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/loader/partial_loader/svelte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<'a> SveltePartialLoader<'a> {
let mut pointer = 0;

// find opening "<script"
let offset = script_start_finder.find(self.source_text[pointer..].as_bytes())?;
let offset = script_start_finder.find(&self.source_text.as_bytes()[pointer..])?;
pointer += offset + SCRIPT_START.len();

// find closing ">"
Expand All @@ -38,7 +38,7 @@ impl<'a> SveltePartialLoader<'a> {
let js_start = pointer;

// find "</script>"
let offset = script_end_finder.find(self.source_text[pointer..].as_bytes())?;
let offset = script_end_finder.find(&self.source_text.as_bytes()[pointer..])?;
let js_end = pointer + offset;

let source_text = &self.source_text[js_start..js_end];
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/loader/partial_loader/vue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<'a> VuePartialLoader<'a> {
let script_start_finder = Finder::new(SCRIPT_START);

// find opening "<script"
let offset = script_start_finder.find(self.source_text[*pointer..].as_bytes())?;
let offset = script_start_finder.find(&self.source_text.as_bytes()[*pointer..])?;
*pointer += offset + SCRIPT_START.len();

// skip `<script-`
Expand All @@ -56,7 +56,7 @@ impl<'a> VuePartialLoader<'a> {

// find "</script>"
let script_end_finder = Finder::new(SCRIPT_END);
let offset = script_end_finder.find(self.source_text[*pointer..].as_bytes())?;
let offset = script_end_finder.find(&self.source_text.as_bytes()[*pointer..])?;
let js_end = *pointer + offset;
*pointer += offset + SCRIPT_END.len();

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/default_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl Rule for DefaultCase {
let has_default_comment = ctx
.semantic()
.comments_range(last_case.span.start..switch.span.end)
.last()
.next_back()
.is_some_and(|comment| {
let raw = ctx.source_range(comment.content_span()).trim();
match &self.comment_pattern {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/guard_for_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Rule for GuardForIn {
{
return;
}
Statement::BlockStatement(block_body) if block_body.body.len() >= 1 => {
Statement::BlockStatement(block_body) if !block_body.body.is_empty() => {
let block_statement = &block_body.body[0];
if let Statement::IfStatement(i) = block_statement {
if let Statement::ContinueStatement(_) = &i.consequent {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_fallthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl NoFallthrough {
let comment = semantic
.comments_range(range)
.map(|comment| ctx.source_range(comment.content_span()))
.last()
.next_back()
.map(str::trim);

comment.is_some_and(|comment| self.is_comment_fall_through(comment))
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_lone_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Rule for NoLoneBlocks {

if stmt.body.is_empty() {
let is_comment_in_stmt =
ctx.comments_range(stmt.span.start..stmt.span.end).last().is_some();
ctx.comments_range(stmt.span.start..stmt.span.end).next_back().is_some();

if !is_comment_in_stmt
&& !matches!(parent_node.kind(), AstKind::TryStatement(_) | AstKind::CatchClause(_))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub struct ScientificNotation<'a> {
impl PartialEq for ScientificNotation<'_> {
fn eq(&self, other: &Self) -> bool {
if self.int == other.int && self.frac == other.frac {
if self.int == "0" && self.frac == "" {
if self.int == "0" && self.frac.is_empty() {
return true;
}
return self.exp == other.exp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Rule for NoObjectConstructor {

if ident.name == "Object"
&& ctx.is_reference_to_global_variable(ident)
&& arguments.len() == 0
&& arguments.is_empty()
&& type_parameters.is_none()
{
ctx.diagnostic(no_object_constructor_diagnostic(span));
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_linter/src/rules/eslint/no_regex_spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ impl NoRegexSpaces {
}

fn is_regexp_new_expression(expr: &NewExpression<'_>) -> bool {
expr.callee.is_specific_id("RegExp") && expr.arguments.len() > 0
expr.callee.is_specific_id("RegExp") && !expr.arguments.is_empty()
}

fn is_regexp_call_expression(expr: &CallExpression<'_>) -> bool {
expr.callee.is_specific_id("RegExp") && expr.arguments.len() > 0
expr.callee.is_specific_id("RegExp") && !expr.arguments.is_empty()
}

// For skipping if there aren't any consecutive spaces in the source, to avoid reporting cases
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/rules/eslint/no_useless_escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ fn check_string(string: &str) -> Vec<usize> {
}

let quote_char = string.chars().next().unwrap();
let bytes = &string[1..string.len() - 1].as_bytes();
let bytes = &string.as_bytes()[1..string.len() - 1];
let escapes = memmem::find_iter(bytes, "\\").collect::<Vec<_>>();

if escapes.is_empty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn has_left_hand_object(node: &MemberExpression) -> bool {
let object = node.object().get_inner_expression();

if let Expression::ObjectExpression(object_expr) = object {
return object_expr.properties.len() == 0;
return object_expr.properties.is_empty();
}

let object_node_to_check = match object.get_member_expr() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Rule for PreferPromiseRejectErrors {
return;
};

if ident.name != "Promise" || new_expr.arguments.len() == 0 {
if ident.name != "Promise" || new_expr.arguments.is_empty() {
return;
}

Expand All @@ -125,11 +125,11 @@ impl Rule for PreferPromiseRejectErrors {
}

fn check_reject_call(call_expr: &CallExpression, ctx: &LintContext, allow_empty_reject: bool) {
if call_expr.arguments.len() == 0 && allow_empty_reject {
if call_expr.arguments.is_empty() && allow_empty_reject {
return;
}

if call_expr.arguments.len() == 0
if call_expr.arguments.is_empty()
|| call_expr.arguments[0].as_expression().is_some_and(|e| !could_be_error(ctx, e))
|| is_undefined(&call_expr.arguments[0])
{
Expand Down
Loading
Loading