1- use std:: io:: BufWriter ;
2-
1+ /// Re-exported external linter types for use in `napi/oxlint`.
32pub use oxc_linter:: {
43 ExternalLinter , ExternalLinterLintFileCb , ExternalLinterLoadPluginCb , LintFileResult ,
54 PluginLoadResult ,
@@ -10,98 +9,20 @@ mod js_plugins;
109mod lint;
1110mod output_formatter;
1211mod result;
12+ mod run;
1313mod walk;
1414
1515#[ cfg( test) ]
1616mod tester;
1717
18- use lint:: LintRunner ;
19- use result:: CliRunResult ;
20-
2118/// Re-exported CLI-related items for use in `tasks/website`.
2219pub mod cli {
2320 pub use super :: { command:: * , lint:: LintRunner , result:: CliRunResult } ;
2421}
2522
23+ /// Main export for binary
24+ pub use run:: lint;
25+
2626#[ cfg( all( feature = "allocator" , not( miri) , not( target_family = "wasm" ) ) ) ]
2727#[ global_allocator]
2828static GLOBAL : mimalloc_safe:: MiMalloc = mimalloc_safe:: MiMalloc ;
29-
30- /// Run the linter.
31- pub fn lint ( mut external_linter : Option < ExternalLinter > ) -> CliRunResult {
32- init_tracing ( ) ;
33- init_miette ( ) ;
34-
35- let mut args = std:: env:: args_os ( ) ;
36- // If first arg is `node`, also skip script path (`node script.js ...`).
37- // Otherwise, just skip first arg (`oxlint ...`).
38- if args. next ( ) . is_some_and ( |arg| arg == "node" ) {
39- args. next ( ) ;
40- }
41- let args = args. collect :: < Vec < _ > > ( ) ;
42-
43- let cmd = crate :: cli:: lint_command ( ) ;
44- let command = match cmd. run_inner ( & * args) {
45- Ok ( cmd) => cmd,
46- Err ( e) => {
47- e. print_message ( 100 ) ;
48- return if e. exit_code ( ) == 0 {
49- CliRunResult :: LintSucceeded
50- } else {
51- CliRunResult :: InvalidOptionConfig
52- } ;
53- }
54- } ;
55-
56- command. handle_threads ( ) ;
57-
58- #[ expect( clippy:: print_stderr) ]
59- if command. experimental_js_plugins {
60- // If no `ExternalLinter`, this function was not called by `napi/oxlint`
61- if external_linter. is_none ( ) {
62- eprintln ! ( "ERROR: JS plugins are not supported at present" ) ;
63- return CliRunResult :: InvalidOptionConfig ;
64- }
65-
66- // Exit early if not 64-bit little-endian, to avoid a panic later on when trying to create
67- // a fixed-size allocator for raw transfer
68- if cfg ! ( not( all( target_pointer_width = "64" , target_endian = "little" ) ) ) {
69- eprintln ! (
70- "ERROR: JS plugins are only supported on 64-bit little-endian platforms at present"
71- ) ;
72- return CliRunResult :: InvalidOptionConfig ;
73- }
74- } else {
75- external_linter = None ;
76- }
77-
78- // stdio is blocked by LineWriter, use a BufWriter to reduce syscalls.
79- // See `https://github.com/rust-lang/rust/issues/60673`.
80- let mut stdout = BufWriter :: new ( std:: io:: stdout ( ) ) ;
81-
82- LintRunner :: new ( command, external_linter) . run ( & mut stdout)
83- }
84-
85- /// Initialize the data which relies on `is_atty` system calls so they don't block subsequent threads.
86- fn init_miette ( ) {
87- miette:: set_hook ( Box :: new ( |_| Box :: new ( miette:: MietteHandlerOpts :: new ( ) . build ( ) ) ) ) . unwrap ( ) ;
88- }
89-
90- /// To debug `oxc_resolver`:
91- /// `OXC_LOG=oxc_resolver oxlint --import-plugin`
92- fn init_tracing ( ) {
93- use tracing_subscriber:: { filter:: Targets , prelude:: * } ;
94-
95- // Usage without the `regex` feature.
96- // <https://github.com/tokio-rs/tracing/issues/1436#issuecomment-918528013>
97- tracing_subscriber:: registry ( )
98- . with ( std:: env:: var ( "OXC_LOG" ) . map_or_else (
99- |_| Targets :: new ( ) ,
100- |env_var| {
101- use std:: str:: FromStr ;
102- Targets :: from_str ( & env_var) . unwrap ( )
103- } ,
104- ) )
105- . with ( tracing_subscriber:: fmt:: layer ( ) )
106- . init ( ) ;
107- }
0 commit comments