Skip to content

Commit

Permalink
chore: fix some nightly clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jun 18, 2024
1 parent 051ceb6 commit 4e9d8a5
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ non_ascii_idents = "warn"
unit-bindings = "warn"

[workspace.lints.clippy]
all = { level = "warn" }
all = { level = "warn", priority = -1 }
empty_docs = { level = "allow", priority = 1 } # from `Tsify`
# restriction
dbg_macro = "warn"
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_linter/src/rules/unicorn/no_zero_fractions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ fn format_raw(raw: &str) -> Option<(String, bool)> {
let dot_and_fractions = after_parts.next()?;
let after = after_parts.next().unwrap_or("");

let fixed_dot_and_fractions =
dot_and_fractions.trim_end_matches(|c: char| c == '0' || c == '.' || c == '_');
let fixed_dot_and_fractions = dot_and_fractions.trim_end_matches(['0', '.', '_']);
let formatted = format!(
"{}{}{}{}",
if before.is_empty() && fixed_dot_and_fractions.is_empty() { "0" } else { before },
Expand Down
9 changes: 2 additions & 7 deletions crates/oxc_prettier/src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,20 +1334,15 @@ impl<'a> Format<'a> for NumericLiteral<'a> {
// Remove unnecessary plus and zeroes from scientific notation.
if let Some((head, tail)) = string.split_once('e') {
let negative = if tail.starts_with('-') { "-" } else { "" };
let trimmed =
tail.trim_start_matches(|c| c == '+' || c == '-').trim_start_matches('0');
let trimmed = tail.trim_start_matches(['+', '-']).trim_start_matches('0');
if trimmed.starts_with(|c: char| c.is_ascii_digit()) {
string = Cow::Owned(std::format!("{head}e{negative}{trimmed}"));
}
}

// Remove unnecessary scientific notation (1e0).
if let Some((head, tail)) = string.split_once('e') {
if tail
.trim_start_matches(|c| c == '+' || c == '-')
.trim_start_matches('0')
.is_empty()
{
if tail.trim_start_matches(['+', '-']).trim_start_matches('0').is_empty() {
string = Cow::Owned(head.to_string());
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_prettier/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ pub struct PrettierOptions {
pub trailing_comma: TrailingComma,

/// Print spaces between brackets in object literals.
///
/// * true - Example: `{ foo: bar }`.
/// * false - Example: `{foo: bar}`.
///
/// Default: true
pub bracket_spacing: bool,

Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_semantic/src/jsdoc/parser/jsdoc_parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ impl<'a> JSDocCommentPart<'a> {

let start_trimmed = self.raw.trim_start();
let trimmed_start_offset = base_len - start_trimmed.len();
let trimmed_end_offset =
trimmed_start_offset + start_trimmed.find(|c| c == '\n').unwrap_or(0);
let trimmed_end_offset = trimmed_start_offset + start_trimmed.find('\n').unwrap_or(0);
Span::new(
self.span.start + u32::try_from(trimmed_start_offset).unwrap_or_default(),
self.span.start + u32::try_from(trimmed_end_offset).unwrap_or_default(),
Expand Down
1 change: 1 addition & 0 deletions crates/oxc_traverse/src/ancestor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use std::cell::Cell;

use memoffset::offset_of;

use oxc_allocator::{Box, Vec};
#[allow(clippy::wildcard_imports)]
use oxc_ast::ast::*;
Expand Down
2 changes: 1 addition & 1 deletion tasks/coverage/src/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub trait Suite<T: Case> {

let path = path.strip_prefix(test_root).unwrap().to_owned();
// remove the Byte Order Mark in some of the TypeScript files
let code = code.trim_start_matches(|c| c == '\u{feff}').to_string();
let code = code.trim_start_matches('\u{feff}').to_string();
T::new(path, code)
})
.filter(|case| !case.skip_test_case())
Expand Down
2 changes: 1 addition & 1 deletion tasks/transform_conformance/src/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl ExecTestCase {
fn write_to_test_files(&self, content: &str) -> PathBuf {
let allocator = Allocator::default();
let new_file_name: String =
normalize_path(self.path.strip_prefix(&packages_root()).unwrap())
normalize_path(self.path.strip_prefix(packages_root()).unwrap())
.split('/')
.collect::<Vec<&str>>()
.join("-");
Expand Down

0 comments on commit 4e9d8a5

Please sign in to comment.