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

Rust Edition 2024 #9289

Merged
merged 2 commits into from
Feb 22, 2025
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ rule = "run -p rulegen"
# Build oxlint in release mode
oxlint = "build --release --bin oxlint --features allocator"

[resolver]
incompatible-rust-versions = "fallback"

# Fix napi breaking in test environment <https://github.com/napi-rs/napi-rs/issues/1005#issuecomment-1011034770>
# To be able to run unit tests on macOS, support compilation to 'x86_64-apple-darwin'.
[target.'cfg(target_vendor = "apple")']
Expand Down
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
style_edition = "2024"
# Make Rust more readable given most people have wide screens nowadays.
# This is also the setting used by [rustc](https://github.com/rust-lang/rust/blob/master/rustfmt.toml)
use_small_heuristics = "Max"
Expand All @@ -9,7 +10,6 @@ reorder_modules = true

# All unstable features that we wish for
# unstable_features = true
# style_edition = "2024"
# Provide a cleaner impl order
# reorder_impl_items = true
# Provide a cleaner import sort order
Expand Down
52 changes: 26 additions & 26 deletions Cargo.lock

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

12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@ exclude = ["tasks/lint_rules", "tasks/e2e"]
[workspace.package]
authors = ["Boshen <boshenc@gmail.com>", "Oxc contributors"]
categories = ["compilers", "development-tools", "web-programming"]
edition = "2021"
homepage = "https://oxc.rs"
keywords = ["JavaScript", "TypeScript", "linter", "minifier", "parser"]
license = "MIT"
repository = "https://github.com/oxc-project/oxc"
rust-version = "1.82.0" # Support last 4 minor versions. (NOTE: bump to `edition = "2024"` when 1.85.0.
description = "A collection of JavaScript tools written in Rust."

edition = "2024"
# MSRV Policy N-2 (12 weeks) starting from v1.87.0
# Balance between the core contributors enjoying the latest version of rustc, while waiting for dependents to catch up.
rust-version = "1.85.0"

# <https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html>
[workspace.lints.rust]
absolute_paths_not_starting_with_crate = "warn"
non_ascii_idents = "warn"
unit-bindings = "warn"
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage)', 'cfg(coverage_nightly)'] }
tail_expr_drop_order = "allow" # FIXME
unsafe_op_in_unsafe_fn = "allow" # FIXME
unused_unsafe = "allow"

[workspace.lints.clippy]
all = { level = "warn", priority = -1 }
Expand All @@ -45,7 +51,7 @@ rc_buffer = "warn"
rc_mutex = "warn"
rest_pat_in_fully_bound_structs = "warn"
unnecessary_safety_comment = "warn"
undocumented_unsafe_blocks = "warn"
undocumented_unsafe_blocks = "allow" # FIXME
infinite_loop = "warn"
map_with_unused_argument_over_ranges = "warn"
unused_result_ok = "warn"
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/src/command/ignore.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ffi::OsString;

use bpaf::{doc::Style, Bpaf};
use bpaf::{Bpaf, doc::Style};

pub const NO_IGNORE_HELP: &[(&str, Style)] = &[
("Disables excluding of files from .eslintignore files, ", Style::Text),
Expand Down
9 changes: 5 additions & 4 deletions apps/oxlint/src/command/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use oxc_linter::{AllowWarnDeny, FixKind, LintPlugins};
use crate::output_formatter::OutputFormat;

use super::{
ignore::{ignore_options, IgnoreOptions},
misc_options, validate_paths, MiscOptions, PATHS_ERROR_MESSAGE, VERSION,
MiscOptions, PATHS_ERROR_MESSAGE, VERSION,
ignore::{IgnoreOptions, ignore_options},
misc_options, validate_paths,
};

#[derive(Debug, Clone, Bpaf)]
Expand Down Expand Up @@ -392,7 +393,7 @@ mod plugins {

#[cfg(test)]
mod warning_options {
use super::{lint_command, WarningOptions};
use super::{WarningOptions, lint_command};

fn get_warning_options(arg: &str) -> WarningOptions {
let args = arg.split(' ').map(std::string::ToString::to_string).collect::<Vec<_>>();
Expand Down Expand Up @@ -425,7 +426,7 @@ mod lint_options {

use oxc_linter::AllowWarnDeny;

use super::{lint_command, LintCommand, OutputFormat};
use super::{LintCommand, OutputFormat, lint_command};

fn get_lint_options(arg: &str) -> LintCommand {
let args = arg.split(' ').map(std::string::ToString::to_string).collect::<Vec<_>>();
Expand Down
4 changes: 2 additions & 2 deletions apps/oxlint/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bpaf::Bpaf;

pub use self::{
ignore::IgnoreOptions,
lint::{lint_command, LintCommand, OutputOptions, WarningOptions},
lint::{LintCommand, OutputOptions, WarningOptions, lint_command},
};

const VERSION: &str = match option_env!("OXC_VERSION") {
Expand Down Expand Up @@ -45,7 +45,7 @@ const PATHS_ERROR_MESSAGE: &str = "PATH must not contain \"..\"";

#[cfg(test)]
mod misc_options {
use super::{lint::lint_command, MiscOptions};
use super::{MiscOptions, lint::lint_command};

fn get_misc_options(arg: &str) -> MiscOptions {
let args = arg.split(' ').map(std::string::ToString::to_string).collect::<Vec<_>>();
Expand Down
12 changes: 8 additions & 4 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use cow_utils::CowUtils;
use ignore::{gitignore::Gitignore, overrides::OverrideBuilder};
use oxc_diagnostics::{DiagnosticService, GraphicalReportHandler};
use oxc_linter::{
loader::LINT_PARTIAL_LOADER_EXT, AllowWarnDeny, ConfigStoreBuilder, InvalidFilterKind,
LintFilter, LintOptions, LintService, LintServiceOptions, Linter, Oxlintrc,
AllowWarnDeny, ConfigStoreBuilder, InvalidFilterKind, LintFilter, LintOptions, LintService,
LintServiceOptions, Linter, Oxlintrc, loader::LINT_PARTIAL_LOADER_EXT,
};
use oxc_span::VALID_EXTENSIONS;
use serde_json::Value;
Expand Down Expand Up @@ -340,13 +340,17 @@ impl LintRunner {
));
}
Err(InvalidFilterKind::PluginMissing(filter)) => {
return Err((CliRunResult::InvalidOptionSeverityWithoutPluginName, format!(
return Err((
CliRunResult::InvalidOptionSeverityWithoutPluginName,
format!(
"Failed to {severity} filter {filter}: Plugin name is missing. Expected <plugin>/<rule>\n"
),
));
}
Err(InvalidFilterKind::RuleMissing(filter)) => {
return Err((CliRunResult::InvalidOptionSeverityWithoutRuleName, format!(
return Err((
CliRunResult::InvalidOptionSeverityWithoutRuleName,
format!(
"Failed to {severity} filter {filter}: Rule name is missing. Expected <plugin>/<rule>\n"
),
));
Expand Down
11 changes: 7 additions & 4 deletions apps/oxlint/src/output_formatter/checkstyle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::borrow::Cow;
use rustc_hash::FxHashMap;

use oxc_diagnostics::{
reporter::{DiagnosticReporter, DiagnosticResult, Info},
Error, Severity,
reporter::{DiagnosticReporter, DiagnosticResult, Info},
};

use crate::output_formatter::{xml_utils::xml_escape, InternalFormatter};
use crate::output_formatter::{InternalFormatter, xml_utils::xml_escape};

#[derive(Debug, Default)]
pub struct CheckStyleOutputFormatter;
Expand Down Expand Up @@ -69,8 +69,8 @@ fn format_checkstyle(diagnostics: &[Error]) -> String {
#[cfg(test)]
mod test {
use oxc_diagnostics::{
reporter::{DiagnosticReporter, DiagnosticResult},
NamedSource, OxcDiagnostic,
reporter::{DiagnosticReporter, DiagnosticResult},
};
use oxc_span::Span;

Expand All @@ -93,6 +93,9 @@ mod test {
let second_result = reporter.finish(&DiagnosticResult::default());

assert!(second_result.is_some());
assert_eq!(second_result.unwrap(), "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle version=\"4.3\"><file name=\"file://test.ts\"><error line=\"1\" column=\"1\" severity=\"warning\" message=\"error message\" source=\"\" /></file></checkstyle>\n");
assert_eq!(
second_result.unwrap(),
"<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle version=\"4.3\"><file name=\"file://test.ts\"><error line=\"1\" column=\"1\" severity=\"warning\" message=\"error message\" source=\"\" /></file></checkstyle>\n"
);
}
}
12 changes: 4 additions & 8 deletions apps/oxlint/src/output_formatter/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::time::Duration;

use crate::output_formatter::InternalFormatter;
use oxc_diagnostics::{
reporter::{DiagnosticReporter, DiagnosticResult},
Error, GraphicalReportHandler,
reporter::{DiagnosticReporter, DiagnosticResult},
};
use oxc_linter::table::RuleTable;

Expand Down Expand Up @@ -51,11 +51,7 @@ impl InternalFormatter for DefaultOutputFormatter {
impl DefaultOutputFormatter {
fn get_execution_time(duration: &Duration) -> String {
let ms = duration.as_millis();
if ms < 1000 {
format!("{ms}ms")
} else {
format!("{:.1}s", duration.as_secs_f64())
}
if ms < 1000 { format!("{ms}ms") } else { format!("{:.1}s", duration.as_secs_f64()) }
}
}

Expand Down Expand Up @@ -115,8 +111,8 @@ fn get_diagnostic_result_output(result: &DiagnosticResult) -> String {
#[cfg(test)]
mod test_implementation {
use oxc_diagnostics::{
reporter::{DiagnosticReporter, DiagnosticResult, Info},
Error, GraphicalReportHandler, GraphicalTheme,
reporter::{DiagnosticReporter, DiagnosticResult, Info},
};

use crate::output_formatter::default::get_diagnostic_result_output;
Expand Down Expand Up @@ -155,8 +151,8 @@ mod test {
use std::time::Duration;

use crate::output_formatter::{
default::{DefaultOutputFormatter, GraphicalReporter},
InternalFormatter, LintCommandInfo,
default::{DefaultOutputFormatter, GraphicalReporter},
};
use oxc_diagnostics::reporter::{DiagnosticReporter, DiagnosticResult};

Expand Down
Loading
Loading