@@ -7,7 +7,7 @@ use std::{
77} ;
88
99use oxc_diagnostics:: DiagnosticService ;
10- use oxc_formatter:: { FormatOptions , Oxfmtrc } ;
10+ use oxc_formatter:: Oxfmtrc ;
1111
1212use crate :: {
1313 cli:: { CliRunResult , FormatCommand } ,
@@ -49,8 +49,8 @@ impl FormatRunner {
4949 // NOTE: Currently, we only load single config file.
5050 // - from `--config` if specified
5151 // - else, search nearest for the nearest `.oxfmtrc.json` from cwd upwards
52- let format_options = match load_config ( & cwd, basic_options. config . as_ref ( ) ) {
53- Ok ( options ) => options ,
52+ let config = match load_config ( & cwd, basic_options. config . as_ref ( ) ) {
53+ Ok ( config ) => config ,
5454 Err ( err) => {
5555 print_and_flush_stdout (
5656 stdout,
@@ -60,11 +60,21 @@ impl FormatRunner {
6060 }
6161 } ;
6262
63+ let ignore_patterns = config. ignore_patterns . clone ( ) . unwrap_or_default ( ) ;
64+ let format_options = match config. into_format_options ( ) {
65+ Ok ( options) => options,
66+ Err ( err) => {
67+ print_and_flush_stdout ( stdout, & format ! ( "Failed to parse configuration.\n {err}\n " ) ) ;
68+ return CliRunResult :: InvalidOptionConfig ;
69+ }
70+ } ;
71+
6372 let walker = match Walk :: build (
6473 & cwd,
6574 & paths,
6675 & ignore_options. ignore_path ,
6776 ignore_options. with_node_modules ,
77+ & ignore_patterns,
6878 ) {
6979 Ok ( walker) => walker,
7080 Err ( err) => {
@@ -171,7 +181,7 @@ impl FormatRunner {
171181/// Returns error if:
172182/// - Config file is specified but not found or invalid
173183/// - Config file parsing fails
174- fn load_config ( cwd : & Path , config_path : Option < & PathBuf > ) -> Result < FormatOptions , String > {
184+ fn load_config ( cwd : & Path , config_path : Option < & PathBuf > ) -> Result < Oxfmtrc , String > {
175185 let config_path = if let Some ( config_path) = config_path {
176186 // If `--config` is explicitly specified, use that path
177187 Some ( if config_path. is_absolute ( ) {
@@ -194,9 +204,9 @@ fn load_config(cwd: &Path, config_path: Option<&PathBuf>) -> Result<FormatOption
194204 } ;
195205
196206 match config_path {
197- Some ( ref path) => Oxfmtrc :: from_file ( path) ? . into_format_options ( ) ,
207+ Some ( ref path) => Oxfmtrc :: from_file ( path) ,
198208 // Default if not specified and not found
199- None => Ok ( FormatOptions :: default ( ) ) ,
209+ None => Ok ( Oxfmtrc :: default ( ) ) ,
200210 }
201211}
202212
0 commit comments