Skip to content

Commit 6e330d4

Browse files
committed
reactor(linter): move Walk from oxlint to oxc_linter with own options struct
1 parent 24aba18 commit 6e330d4

File tree

9 files changed

+39
-22
lines changed

9 files changed

+39
-22
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/oxlint/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod output_formatter;
44
mod result;
55
mod runner;
66
mod tester;
7-
mod walk;
87

98
pub mod cli {
109

apps/oxlint/src/lint.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ use cow_utils::CowUtils;
1212
use ignore::{gitignore::Gitignore, overrides::OverrideBuilder};
1313
use oxc_diagnostics::{DiagnosticService, GraphicalReportHandler, OxcDiagnostic};
1414
use oxc_linter::{
15-
AllowWarnDeny, Config, ConfigStore, ConfigStoreBuilder, InvalidFilterKind, LintFilter,
16-
LintOptions, LintService, LintServiceOptions, Linter, Oxlintrc,
15+
AllowWarnDeny, Config, ConfigStore, ConfigStoreBuilder, FileWalker, FileWalkerOptions,
16+
InvalidFilterKind, LintFilter, LintOptions, LintService, LintServiceOptions, Linter, Oxlintrc,
1717
};
1818
use rustc_hash::{FxHashMap, FxHashSet};
1919
use serde_json::Value;
2020

2121
use crate::{
2222
cli::{CliRunResult, LintCommand, MiscOptions, ReportUnusedDirectives, Runner, WarningOptions},
2323
output_formatter::{LintCommandInfo, OutputFormatter},
24-
walk::Walk,
2524
};
2625

2726
#[derive(Debug)]
@@ -165,7 +164,15 @@ impl Runner for LintRunner {
165164
paths.push(self.cwd.clone());
166165
}
167166

168-
let walker = Walk::new(&paths, &ignore_options, override_builder);
167+
let walker = FileWalker::new(
168+
&paths,
169+
&FileWalkerOptions {
170+
no_ignore: ignore_options.no_ignore,
171+
ignore_path: ignore_options.ignore_path.clone(),
172+
symlinks: ignore_options.symlinks,
173+
},
174+
override_builder,
175+
);
169176
let paths = walker.paths();
170177
let number_of_files = paths.len();
171178

crates/oxc_linter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ convert_case = { workspace = true }
4949
cow-utils = { workspace = true }
5050
fast-glob = { workspace = true }
5151
globset = { workspace = true }
52+
ignore = { workspace = true, features = ["simd-accel"] }
5253
indexmap = { workspace = true, features = ["rayon"] }
5354
itertools = { workspace = true }
5455
javascript-globals = { workspace = true }

crates/oxc_linter/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub use crate::{
3939
options::LintOptions,
4040
options::{AllowWarnDeny, InvalidFilterKind, LintFilter, LintFilterKind},
4141
rule::{RuleCategory, RuleFixMeta, RuleMeta},
42-
service::{LintService, LintServiceOptions, RuntimeFileSystem},
42+
service::{FileWalker, FileWalkerOptions, LintService, LintServiceOptions, RuntimeFileSystem},
4343
utils::read_to_string,
4444
};
4545
use crate::{

apps/oxlint/src/walk.rs renamed to crates/oxc_linter/src/service/file_walker.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
use std::{ffi::OsStr, path::PathBuf, sync::Arc, sync::mpsc};
1+
use std::{
2+
ffi::{OsStr, OsString},
3+
path::PathBuf,
4+
sync::{Arc, mpsc},
5+
};
26

37
use ignore::{DirEntry, overrides::Override};
4-
use oxc_linter::LINTABLE_EXTENSIONS;
58

6-
use crate::cli::IgnoreOptions;
9+
use crate::LINTABLE_EXTENSIONS;
710

811
#[derive(Clone)]
912
pub struct Extensions(pub Vec<&'static str>);
@@ -14,7 +17,7 @@ impl Default for Extensions {
1417
}
1518
}
1619

17-
pub struct Walk {
20+
pub struct FileWalker {
1821
inner: ignore::WalkParallel,
1922
/// The file extensions to include during the traversal.
2023
extensions: Extensions,
@@ -52,7 +55,7 @@ impl ignore::ParallelVisitor for WalkCollector {
5255
fn visit(&mut self, entry: Result<ignore::DirEntry, ignore::Error>) -> ignore::WalkState {
5356
match entry {
5457
Ok(entry) => {
55-
if Walk::is_wanted_entry(&entry, &self.extensions) {
58+
if FileWalker::is_wanted_entry(&entry, &self.extensions) {
5659
self.paths.push(entry.path().as_os_str().into());
5760
}
5861
ignore::WalkState::Continue
@@ -61,12 +64,19 @@ impl ignore::ParallelVisitor for WalkCollector {
6164
}
6265
}
6366
}
64-
impl Walk {
67+
68+
pub struct FileWalkerOptions {
69+
pub no_ignore: bool,
70+
pub symlinks: bool,
71+
pub ignore_path: OsString,
72+
}
73+
74+
impl FileWalker {
6575
/// Will not canonicalize paths.
6676
/// # Panics
6777
pub fn new(
6878
paths: &[PathBuf],
69-
options: &IgnoreOptions,
79+
options: &FileWalkerOptions,
7080
override_builder: Option<Override>,
7181
) -> Self {
7282
assert!(!paths.is_empty(), "At least one path must be provided to Walk::new");
@@ -108,7 +118,8 @@ impl Walk {
108118
receiver.into_iter().flatten().collect()
109119
}
110120

111-
#[cfg_attr(not(test), expect(dead_code))]
121+
#[cfg(test)]
122+
#[must_use]
112123
pub fn with_extensions(mut self, extensions: Extensions) -> Self {
113124
self.extensions = extensions;
114125
self
@@ -133,25 +144,22 @@ impl Walk {
133144
mod test {
134145
use std::{env, ffi::OsString, path::Path};
135146

147+
use super::{Extensions, FileWalker, FileWalkerOptions};
136148
use ignore::overrides::OverrideBuilder;
137149

138-
use super::{Extensions, Walk};
139-
use crate::cli::IgnoreOptions;
140-
141150
#[test]
142151
fn test_walk_with_extensions() {
143152
let fixture = env::current_dir().unwrap().join("fixtures/walk_dir");
144153
let fixtures = vec![fixture.clone()];
145-
let ignore_options = IgnoreOptions {
154+
let ignore_options = FileWalkerOptions {
146155
no_ignore: false,
147156
ignore_path: OsString::from(".gitignore"),
148-
ignore_pattern: vec![],
149157
symlinks: false,
150158
};
151159

152160
let override_builder = OverrideBuilder::new("/").build().unwrap();
153161

154-
let mut paths = Walk::new(&fixtures, &ignore_options, Some(override_builder))
162+
let mut paths = FileWalker::new(&fixtures, &ignore_options, Some(override_builder))
155163
.with_extensions(Extensions(["js", "vue"].to_vec()))
156164
.paths()
157165
.into_iter()

crates/oxc_linter/src/service/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ use std::{
44
sync::Arc,
55
};
66

7+
use crate::Linter;
8+
pub use file_walker::{FileWalker, FileWalkerOptions};
79
use oxc_diagnostics::DiagnosticSender;
810
use runtime::Runtime;
911
pub use runtime::RuntimeFileSystem;
1012

11-
use crate::Linter;
12-
13+
mod file_walker;
1314
mod runtime;
1415

1516
#[cfg(feature = "language_server")]

0 commit comments

Comments
 (0)