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
12 changes: 12 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ oxc_linter = { path = "crates/oxc_linter" }
oxc_macros = { path = "crates/oxc_macros" }
oxc_tasks_common = { path = "tasks/common" }
oxc_tasks_transform_checker = { path = "tasks/transform_checker" }
oxlint = { path = "apps/oxlint" }

# Relaxed version so the user can decide which version to use.
napi = "3.0.0-beta"
Expand Down
3 changes: 3 additions & 0 deletions apps/oxlint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ description.workspace = true
workspace = true

[lib]
crate-type = ["lib"]
path = "src/lib.rs"
doctest = false

[[bin]]
Expand All @@ -34,6 +36,7 @@ bpaf = { workspace = true, features = ["autocomplete", "bright-color", "derive"]
cow-utils = { workspace = true }
ignore = { workspace = true, features = ["simd-accel"] }
miette = { workspace = true }
napi = { workspace = true }
rayon = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true }
Expand Down
63 changes: 62 additions & 1 deletion apps/oxlint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,67 @@ mod tester;
mod walk;

pub mod cli {

pub use crate::{command::*, lint::LintRunner, result::CliRunResult, runner::Runner};
}

#[cfg(all(feature = "allocator", not(miri), not(target_family = "wasm")))]
#[global_allocator]
static GLOBAL: mimalloc_safe::MiMalloc = mimalloc_safe::MiMalloc;

use cli::{CliRunResult, LintRunner, Runner};
use std::{ffi::OsStr, io::BufWriter};

pub fn lint() -> CliRunResult {
init_tracing();
init_miette();

let mut args = std::env::args_os().peekable();

let args = match args.peek() {
Some(s) if s == OsStr::new("node") => args.skip(2),
_ => args.skip(1),
};
let args = args.collect::<Vec<_>>();

// SAFELY skip first two args (node + script.js)
// let cli_args = std::env::args_os().skip(2);
let cmd = crate::cli::lint_command();
let command = match cmd.run_inner(&*args) {
Ok(cmd) => cmd,
Err(e) => {
e.print_message(100);
return CliRunResult::InvalidOptionConfig;
}
};

command.handle_threads();
// stdio is blocked by LineWriter, use a BufWriter to reduce syscalls.
// See `https://github.com/rust-lang/rust/issues/60673`.
let mut stdout = BufWriter::new(std::io::stdout());

LintRunner::new(command).run(&mut stdout)
}

// Initialize the data which relies on `is_atty` system calls so they don't block subsequent threads.
fn init_miette() {
miette::set_hook(Box::new(|_| Box::new(miette::MietteHandlerOpts::new().build()))).unwrap();
}

/// To debug `oxc_resolver`:
/// `OXC_LOG=oxc_resolver oxlint --import-plugin`
fn init_tracing() {
use tracing_subscriber::{filter::Targets, prelude::*};

// Usage without the `regex` feature.
// <https://github.com/tokio-rs/tracing/issues/1436#issuecomment-918528013>
tracing_subscriber::registry()
.with(std::env::var("OXC_LOG").map_or_else(
|_| Targets::new(),
|env_var| {
use std::str::FromStr;
Targets::from_str(&env_var).unwrap()
},
))
.with(tracing_subscriber::fmt::layer())
.init();
}
43 changes: 2 additions & 41 deletions apps/oxlint/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,5 @@
// NOTE: Miri does not support custom allocators
#[cfg(all(feature = "allocator", not(miri), not(target_family = "wasm")))]
#[global_allocator]
static GLOBAL: mimalloc_safe::MiMalloc = mimalloc_safe::MiMalloc;

use oxlint::cli::{CliRunResult, LintRunner, Runner};
use std::io::BufWriter;
use oxlint::{cli::CliRunResult, lint};

fn main() -> CliRunResult {
init_tracing();
init_miette();

let command = oxlint::cli::lint_command().run();
command.handle_threads();
// stdio is blocked by LineWriter, use a BufWriter to reduce syscalls.
// See `https://github.com/rust-lang/rust/issues/60673`.
let mut stdout = BufWriter::new(std::io::stdout());

LintRunner::new(command).run(&mut stdout)
}

// Initialize the data which relies on `is_atty` system calls so they don't block subsequent threads.
fn init_miette() {
miette::set_hook(Box::new(|_| Box::new(miette::MietteHandlerOpts::new().build()))).unwrap();
}

/// To debug `oxc_resolver`:
/// `OXC_LOG=oxc_resolver oxlint --import-plugin`
fn init_tracing() {
use tracing_subscriber::{filter::Targets, prelude::*};

// Usage without the `regex` feature.
// <https://github.com/tokio-rs/tracing/issues/1436#issuecomment-918528013>
tracing_subscriber::registry()
.with(std::env::var("OXC_LOG").map_or_else(
|_| Targets::new(),
|env_var| {
use std::str::FromStr;
Targets::from_str(&env_var).unwrap()
},
))
.with(tracing_subscriber::fmt::layer())
.init();
lint()
}
2 changes: 2 additions & 0 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"**/CHANGELOG.md",
"pnpm-workspace.yaml",
"pnpm-lock.yaml",
"napi/oxlint2/src/bindings.js",
"napi/oxlint2/src/bindings.d.ts",
"napi/{transform,minify,playground}/index.js",
"napi/{parser,transform,minify,playground}/index.d.ts",
"napi/{parser,transform,minify,playground}/*.wasi-browser.js",
Expand Down
43 changes: 43 additions & 0 deletions napi/oxlint2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "oxc_linter_napi"
version = "0.1.0"
authors.workspace = true
categories.workspace = true
edition.workspace = true
homepage.workspace = true
include = ["/src", "build.rs"]
keywords.workspace = true
license.workspace = true
publish = false
repository.workspace = true
rust-version.workspace = true
description.workspace = true

[lints]
workspace = true

[lib]
crate-type = ["cdylib", "lib"]
test = false
doctest = false

[dependencies]
oxlint = { workspace = true }

napi = { workspace = true, features = ["async"] }
napi-derive = { workspace = true }

[target.'cfg(not(any(target_os = "linux", target_os = "freebsd", target_arch = "arm", target_family = "wasm")))'.dependencies]
mimalloc-safe = { workspace = true, optional = true, features = ["skip_collect_on_exit"] }

[target.'cfg(all(target_os = "linux", not(target_arch = "arm"), not(target_arch = "aarch64")))'.dependencies]
mimalloc-safe = { workspace = true, optional = true, features = ["skip_collect_on_exit", "local_dynamic_tls"] }

[target.'cfg(all(target_os = "linux", target_arch = "aarch64"))'.dependencies]
mimalloc-safe = { workspace = true, optional = true, features = ["skip_collect_on_exit", "local_dynamic_tls", "no_opt_arch"] }

[build-dependencies]
napi-build = { workspace = true }

[features]
default = []
1 change: 1 addition & 0 deletions napi/oxlint2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Oxlint 2
3 changes: 3 additions & 0 deletions napi/oxlint2/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
napi_build::setup();
}
44 changes: 44 additions & 0 deletions napi/oxlint2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "oxlint2",
"version": "0.1.0",
"main": "src/index.js",
"type": "module",
"scripts": {
"build-dev": "napi build --platform --js ./bindings.js --dts ./bindings.d.ts --output-dir src --no-dts-cache --esm",
"build": "pnpm run build-dev --release",
"test": "echo 'No tests defined yet'"
},
"engines": {
"node": ">=20.0.0"
},
"description": "Staging package for oxlint while we integrate custom JS plugins into oxlint",
"author": "Boshen and oxc contributors",
"license": "MIT",
"homepage": "https://oxc.rs",
"bugs": "https://github.com/oxc-project/oxc/issues",
"repository": {
"type": "git",
"url": "https://github.com/oxc-project/oxc.git",
"directory": "napi/oxlint2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"devDependencies": {
"typescript": "catalog:"
},
"napi": {
"binaryName": "oxlint",
"targets": [
"win32-x64",
"win32-arm64",
"linux-x64-gnu",
"linux-arm64-gnu",
"linux-x64-musl",
"linux-arm64-musl",
"darwin-x64",
"darwin-arm64"
]
}
}
3 changes: 3 additions & 0 deletions napi/oxlint2/src/bindings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* auto-generated by NAPI-RS */
/* eslint-disable */
export declare function lint(): boolean
Loading
Loading