File tree Expand file tree Collapse file tree 2 files changed +72
-6
lines changed Expand file tree Collapse file tree 2 files changed +72
-6
lines changed Original file line number Diff line number Diff line change 11using System . Diagnostics ;
22using System . IO . Abstractions ;
3+ using System . IO . Abstractions . TestingHelpers ;
34using System . Text ;
45using CSharpier . Cli . Options ;
56using CSharpier . Core ;
@@ -292,12 +293,28 @@ await FormatPhysicalFile(
292293 return 1 ;
293294 }
294295
295- var tasks = fileSystem
296- . Directory . EnumerateFiles (
297- directoryOrFilePath ,
298- "*.*" ,
299- SearchOption . AllDirectories
300- )
296+ var fileEnumerator = new ValidFilesEnumerator (
297+ directoryOrFilePath ,
298+ new EnumerationOptions ( ) { RecurseSubdirectories = true }
299+ ) ;
300+
301+ var filePaths = new List < string > ( ) ;
302+ while ( fileEnumerator . MoveNext ( ) )
303+ {
304+ filePaths . Add ( fileEnumerator . Current ) ;
305+ }
306+
307+ if ( fileSystem is MockFileSystem )
308+ {
309+ filePaths = fileSystem
310+ . Directory . EnumerateFiles (
311+ directoryOrFilePath ,
312+ "*.*" ,
313+ SearchOption . AllDirectories
314+ ) . ToList ( ) ;
315+ }
316+
317+ var tasks = filePaths
301318 . Select ( o =>
302319 FormatFile ( o , o . Replace ( directoryOrFilePath , originalDirectoryOrFile ) )
303320 )
Original file line number Diff line number Diff line change 1+ using System . IO . Enumeration ;
2+
3+ namespace CSharpier . Cli ;
4+
5+ internal class ValidFilesEnumerator ( string directory , EnumerationOptions ? options = null )
6+ : FileSystemEnumerator < string > ( directory , options )
7+ {
8+ protected override string TransformEntry ( ref FileSystemEntry entry )
9+ {
10+ return entry . ToSpecifiedFullPath ( ) ;
11+ }
12+
13+ protected override bool ShouldIncludeEntry ( ref FileSystemEntry entry )
14+ {
15+ if ( entry . IsDirectory )
16+ {
17+ return false ;
18+ }
19+
20+ var extension = Path . GetExtension ( entry . FileName ) ;
21+ if (
22+ extension
23+ is ".cs"
24+ or ".csx"
25+ or ".config"
26+ or ".csproj"
27+ or ".props"
28+ or ".slnx"
29+ or ".targets"
30+ or ".xaml"
31+ or ".xml"
32+ )
33+ {
34+ return true ;
35+ }
36+
37+ return false ;
38+ }
39+
40+ protected override bool ShouldRecurseIntoEntry ( ref FileSystemEntry entry )
41+ {
42+ if ( entry . FileName is ".git" or "bin" or "node_modules" or "obj" )
43+ {
44+ return false ;
45+ }
46+
47+ return true ;
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments