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
14 changes: 7 additions & 7 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ impl Runner for LintRunner {
..
} = self.options;

let use_nested_config = experimental_nested_config &&
// If the `--config` option is explicitly passed, we should not search for nested config files
// as the passed config file takes absolute precedence.
basic_options.config.is_none();

let mut paths = paths;
let provided_path_count = paths.len();
let now = Instant::now();
Expand Down Expand Up @@ -151,7 +156,7 @@ impl Runner for LintRunner {
if provided_path_count > 0 {
if let Some(end) = output_formatter.lint_command_info(&LintCommandInfo {
number_of_files: 0,
number_of_rules: 0,
number_of_rules: None,
threads_count: rayon::current_num_threads(),
start_time: now.elapsed(),
}) {
Expand All @@ -175,12 +180,7 @@ impl Runner for LintRunner {
let mut nested_oxlintrc = FxHashMap::<&Path, Oxlintrc>::default();
let mut nested_configs = FxHashMap::<PathBuf, ConfigStore>::default();

let use_nested_config =
// If the `--config` option is explicitly passed, we should not search for nested config files
// as the passed config file takes absolute precedence.
basic_options.config.is_none();

if experimental_nested_config && use_nested_config {
if use_nested_config {
// get all of the unique directories among the paths to use for search for
// oxlint config files in those directories
// e.g. `/some/file.js` and `/some/other/file.js` would both result in `/some`
Expand Down
33 changes: 26 additions & 7 deletions apps/oxlint/src/output_formatter/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ impl InternalFormatter for DefaultOutputFormatter {
let time = Self::get_execution_time(&lint_command_info.start_time);
let s = if lint_command_info.number_of_files == 1 { "" } else { "s" };

Some(format!(
"Finished in {time} on {} file{s} with {} rules using {} threads.\n",
lint_command_info.number_of_files,
lint_command_info.number_of_rules,
lint_command_info.threads_count
))
if let Some(number_of_rules) = lint_command_info.number_of_rules {
Some(format!(
"Finished in {time} on {} file{s} with {} rules using {} threads.\n",
lint_command_info.number_of_files, number_of_rules, lint_command_info.threads_count
))
} else {
Some(format!(
"Finished in {time} on {} file{s} using {} threads.\n",
lint_command_info.number_of_files, lint_command_info.threads_count
))
}
}

#[cfg(not(test))]
Expand Down Expand Up @@ -169,7 +174,7 @@ mod test {
let formatter = DefaultOutputFormatter;
let result = formatter.lint_command_info(&LintCommandInfo {
number_of_files: 5,
number_of_rules: 10,
number_of_rules: Some(10),
threads_count: 12,
start_time: Duration::new(1, 0),
});
Expand All @@ -181,6 +186,20 @@ mod test {
);
}

#[test]
fn lint_command_info_unknown_rules() {
let formatter = DefaultOutputFormatter;
let result = formatter.lint_command_info(&LintCommandInfo {
number_of_files: 5,
number_of_rules: None,
threads_count: 12,
start_time: Duration::new(1, 0),
});

assert!(result.is_some());
assert_eq!(result.unwrap(), "Finished in 1.0s on 5 files using 12 threads.\n");
}

#[test]
fn reporter_finish_no_results() {
let mut reporter = GraphicalReporter::default();
Expand Down
5 changes: 3 additions & 2 deletions apps/oxlint/src/output_formatter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ impl FromStr for OutputFormat {
pub struct LintCommandInfo {
/// The number of files that were linted.
pub number_of_files: usize,
/// The number of lint rules that were run.
pub number_of_rules: usize,
/// The number of lint rules that were run. If the number varies and can't be clearly
/// computed, then this defaults to None.
pub number_of_rules: Option<usize>,
/// The used CPU threads count
pub threads_count: usize,
/// Some reporters want to output the duration it took to finished the task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source: apps/oxlint/src/tester.rs
arguments: --ignore-path fixtures/issue_7566/.oxlintignore fixtures/issue_7566/tests/main.js fixtures/issue_7566/tests/function/main.js
working directory:
----------
Finished in <variable>ms on 0 files with 0 rules using 1 threads.
Finished in <variable>ms on 0 files using 1 threads.
----------
CLI result: LintNoFilesFound
----------
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source: apps/oxlint/src/tester.rs
arguments: --ignore-path fixtures/linter/.customignore fixtures/linter/nan.js
working directory:
----------
Finished in <variable>ms on 0 files with 0 rules using 1 threads.
Finished in <variable>ms on 0 files using 1 threads.
----------
CLI result: LintNoFilesFound
----------
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source: apps/oxlint/src/tester.rs
arguments: -c fixtures/config_ignore_patterns/ignore_extension/eslintrc.json fixtures/config_ignore_patterns/ignore_extension/main.js
working directory:
----------
Finished in <variable>ms on 0 files with 0 rules using 1 threads.
Finished in <variable>ms on 0 files using 1 threads.
----------
CLI result: LintNoFilesFound
----------
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ working directory: fixtures/extends_config
`----

Found 0 warnings and 3 errors.
Finished in <variable>ms on 2 files with 100 rules using 1 threads.
Finished in <variable>ms on 2 files using 1 threads.
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ working directory: fixtures/extends_config
help: Delete this code.

Found 1 warning and 0 errors.
Finished in <variable>ms on 1 file with 100 rules using 1 threads.
Finished in <variable>ms on 1 file using 1 threads.
----------
CLI result: LintSucceeded
----------
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ working directory: fixtures/nested_config
help: Delete this code.

Found 1 warning and 2 errors.
Finished in <variable>ms on 7 files with 100 rules using 1 threads.
Finished in <variable>ms on 7 files using 1 threads.
----------
CLI result: LintFoundErrors
----------
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ working directory: fixtures/nested_config
help: Delete this console statement.

Found 1 warning and 5 errors.
Finished in <variable>ms on 7 files with 101 rules using 1 threads.
Finished in <variable>ms on 7 files using 1 threads.
----------
CLI result: LintFoundErrors
----------
7 changes: 5 additions & 2 deletions crates/oxc_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ impl Linter {
&self.options
}

pub fn number_of_rules(&self) -> usize {
self.config.number_of_rules()
/// Returns the number of rules that will are being used, unless there
/// nested configurations in use, in which case it returns `None` since the
/// number of rules depends on which file is being linted.
pub fn number_of_rules(&self) -> Option<usize> {
self.nested_configs.is_empty().then_some(self.config.number_of_rules())
}

pub fn run<'a>(
Expand Down
Loading