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: 1 addition & 1 deletion apps/oxlint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod tester;

/// Re-exported CLI-related items for use in `tasks/website`.
pub mod cli {
pub use super::{command::*, lint::LintRunner, result::CliRunResult};
pub use super::{command::*, lint::CliRunner, result::CliRunResult};
}

// Only include code to run linter when the `napi` feature is enabled.
Expand Down
20 changes: 10 additions & 10 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ use crate::{
use oxc_linter::LintIgnoreMatcher;

#[derive(Debug)]
pub struct LintRunner {
pub struct CliRunner {
options: LintCommand,
cwd: PathBuf,
external_linter: Option<ExternalLinter>,
}

impl LintRunner {
impl CliRunner {
pub(crate) fn new(options: LintCommand, external_linter: Option<ExternalLinter>) -> Self {
Self {
options,
Expand Down Expand Up @@ -411,7 +411,7 @@ impl LintRunner {
}
}

impl LintRunner {
impl CliRunner {
const DEFAULT_OXLINTRC: &'static str = ".oxlintrc.json";

#[must_use]
Expand Down Expand Up @@ -618,7 +618,7 @@ fn render_report(handler: &GraphicalReportHandler, diagnostic: &OxcDiagnostic) -
mod test {
use std::{fs, path::PathBuf};

use super::LintRunner;
use super::CliRunner;
use crate::tester::Tester;

// lints the full directory of fixtures,
Expand Down Expand Up @@ -988,14 +988,14 @@ mod test {

#[test]
fn test_init_config() {
assert!(!fs::exists(LintRunner::DEFAULT_OXLINTRC).unwrap());
assert!(!fs::exists(CliRunner::DEFAULT_OXLINTRC).unwrap());

let args = &["--init"];
Tester::new().with_cwd("fixtures".into()).test(args);

assert!(fs::exists(LintRunner::DEFAULT_OXLINTRC).unwrap());
assert!(fs::exists(CliRunner::DEFAULT_OXLINTRC).unwrap());

fs::remove_file(LintRunner::DEFAULT_OXLINTRC).unwrap();
fs::remove_file(CliRunner::DEFAULT_OXLINTRC).unwrap();
}

#[test]
Expand Down Expand Up @@ -1190,17 +1190,17 @@ mod test {

// Test case 1: Invalid path that should fail
let invalid_config = PathBuf::from("child/../../fixtures/linter/eslintrc.json");
let result = LintRunner::find_oxlint_config(&cwd, Some(&invalid_config));
let result = CliRunner::find_oxlint_config(&cwd, Some(&invalid_config));
assert!(result.is_err(), "Expected config lookup to fail with invalid path");

// Test case 2: Valid path that should pass
let valid_config = PathBuf::from("fixtures/linter/eslintrc.json");
let result = LintRunner::find_oxlint_config(&cwd, Some(&valid_config));
let result = CliRunner::find_oxlint_config(&cwd, Some(&valid_config));
assert!(result.is_ok(), "Expected config lookup to succeed with valid path");

// Test case 3: Valid path using parent directory (..) syntax that should pass
let valid_parent_config = PathBuf::from("fixtures/linter/../linter/eslintrc.json");
let result = LintRunner::find_oxlint_config(&cwd, Some(&valid_parent_config));
let result = CliRunner::find_oxlint_config(&cwd, Some(&valid_parent_config));
assert!(result.is_ok(), "Expected config lookup to succeed with parent directory syntax");

// Verify the resolved path is correct
Expand Down
4 changes: 2 additions & 2 deletions apps/oxlint/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use napi::{
};
use napi_derive::napi;

use crate::{lint::LintRunner, result::CliRunResult};
use crate::{lint::CliRunner, result::CliRunResult};

/// JS callback to load a JS plugin.
#[napi]
Expand Down Expand Up @@ -113,7 +113,7 @@ fn lint_impl(load_plugin: JsLoadPluginCb, lint_file: JsLintFileCb) -> CliRunResu
// See `https://github.com/rust-lang/rust/issues/60673`.
let mut stdout = BufWriter::new(std::io::stdout());

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

/// Initialize the data which relies on `is_atty` system calls so they don't block subsequent threads.
Expand Down
6 changes: 3 additions & 3 deletions apps/oxlint/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{env, path::PathBuf};
use cow_utils::CowUtils;
use lazy_regex::Regex;

use crate::cli::{LintRunner, lint_command};
use crate::cli::{CliRunner, lint_command};

pub struct Tester {
cwd: PathBuf,
Expand Down Expand Up @@ -32,7 +32,7 @@ impl Tester {

let options = lint_command().run_inner(new_args.as_slice()).unwrap();
let mut output = Vec::new();
let _ = LintRunner::new(options, None).with_cwd(self.cwd.clone()).run(&mut output);
let _ = CliRunner::new(options, None).with_cwd(self.cwd.clone()).run(&mut output);
}

pub fn test_fix(file: &str, before: &str, after: &str) {
Expand Down Expand Up @@ -78,7 +78,7 @@ impl Tester {
format!("working directory: {}\n", relative_dir.to_str().unwrap()).as_bytes(),
);
output.extend_from_slice(b"----------\n");
let result = LintRunner::new(options, None).with_cwd(self.cwd.clone()).run(&mut output);
let result = CliRunner::new(options, None).with_cwd(self.cwd.clone()).run(&mut output);

output.extend_from_slice(b"----------\n");
output.extend_from_slice(format!("CLI result: {result:?}\n").as_bytes());
Expand Down
Loading