@@ -4,6 +4,9 @@ use std::{
44 path:: PathBuf ,
55} ;
66
7+ use ignore:: gitignore:: Gitignore ;
8+
9+ use crate :: cli:: walk:: resolve_ignore_paths;
710use crate :: cli:: { CliRunResult , FormatCommand , Mode } ;
811use crate :: core:: {
912 ConfigResolver , ExternalFormatter , FormatFileStrategy , FormatResult , JsConfigLoaderCb ,
@@ -40,7 +43,7 @@ impl StdinRunner {
4043 let stderr = & mut BufWriter :: new ( io:: stderr ( ) ) ;
4144
4245 let cwd = self . cwd ;
43- let FormatCommand { mode, config_options, .. } = self . options ;
46+ let FormatCommand { mode, config_options, ignore_options , .. } = self . options ;
4447
4548 let Mode :: Stdin ( filepath) = mode else {
4649 unreachable ! ( "`StdinRunner::run()` called with non-Stdin mode" ) ;
@@ -98,6 +101,24 @@ impl StdinRunner {
98101 return CliRunResult :: InvalidOptionConfig ;
99102 } ;
100103
104+ // Check if the file is ignored by global ignores or config`.ignorePatterns`
105+ let resolved_ignore_paths = match resolve_ignore_paths ( & cwd, & ignore_options. ignore_path ) {
106+ Ok ( paths) => paths,
107+ Err ( err) => {
108+ utils:: print_and_flush ( stderr, & format ! ( "{err}\n " ) ) ;
109+ return CliRunResult :: InvalidOptionConfig ;
110+ }
111+ } ;
112+ let is_ignored = resolved_ignore_paths. iter ( ) . any ( |ignore_path| {
113+ let ( gitignore, _) = Gitignore :: new ( ignore_path) ;
114+ gitignore. matched_path_or_any_parents ( strategy. path ( ) , false ) . is_ignore ( )
115+ } ) || config_resolver. is_path_ignored ( strategy. path ( ) , false ) ;
116+
117+ if is_ignored {
118+ utils:: print_and_flush ( stdout, & source_text) ;
119+ return CliRunResult :: FormatSucceeded ;
120+ }
121+
101122 // Resolve options for the stdin file entry
102123 let resolved_options = config_resolver. resolve ( & strategy) ;
103124
0 commit comments