@@ -23,8 +23,6 @@ public class AnalyzeCommand : ICommand
23
23
readonly int MAX_FILESIZE = 1024 * 1000 * 5 ; // Skip source files larger than 5 MB and log
24
24
readonly int MAX_TEXT_SAMPLE_LENGTH = 200 ; //char bytes
25
25
26
- readonly string [ ] EXCLUDEMATCH_FILEPATH = "sample,example,test,docs,.vs,.git" . Split ( "," ) ;
27
-
28
26
public enum ExitCode
29
27
{
30
28
NoMatches = 0 ,
@@ -65,7 +63,6 @@ public DateTime LastUpdated
65
63
private bool _arg_outputUniqueTagsOnly ;
66
64
private string _arg_confidenceFilters ;
67
65
private bool _arg_simpleTagsOnly ;
68
- private bool _arg_allowSampleFiles ;
69
66
private Confidence _arg_confidence ;
70
67
private WriteOnce . ConsoleVerbosity _arg_consoleVerbosityLevel ;
71
68
@@ -80,11 +77,14 @@ public AnalyzeCommand(AnalyzeCommandOptions opts)
80
77
_arg_fileFormat = opts . OutputFileFormat ;
81
78
_arg_outputTextFormat = opts . TextOutputFormat ;
82
79
_arg_outputUniqueTagsOnly = ! opts . AllowDupTags ;
83
- _arg_allowSampleFiles = opts . AllowSampleFiles ;
84
80
_arg_customRulesPath = opts . CustomRulesPath ;
85
81
_arg_confidenceFilters = opts . ConfidenceFilters ;
86
82
_arg_ignoreDefaultRules = opts . IgnoreDefaultRules ;
87
83
_arg_simpleTagsOnly = opts . SimpleTagsOnly ;
84
+ _fileExclusionList = opts . FilePathExclusions . Split ( "," ) . ToList < string > ( ) ;
85
+ if ( _fileExclusionList . Contains ( "none" ) || _fileExclusionList . Contains ( "None" ) )
86
+ _fileExclusionList . Clear ( ) ;
87
+
88
88
if ( ! Enum . TryParse ( opts . ConsoleVerbosityLevel , true , out _arg_consoleVerbosityLevel ) )
89
89
throw new OpException ( String . Format ( ErrMsg . FormatString ( ErrMsg . ID . CMD_INVALID_ARG_VALUE , "-x" ) ) ) ;
90
90
WriteOnce . Verbosity = _arg_consoleVerbosityLevel ;
@@ -98,7 +98,6 @@ public AnalyzeCommand(AnalyzeCommandOptions opts)
98
98
ConfigConfidenceFilters ( ) ;
99
99
ConfigRules ( ) ;
100
100
101
- _fileExclusionList = EXCLUDEMATCH_FILEPATH . ToList < string > ( ) ;
102
101
_uniqueTagsControl = new HashSet < string > ( ) ;
103
102
}
104
103
@@ -606,46 +605,46 @@ void UnZipAndProcess(string filename, ArchiveFileType archiveFileType)
606
605
/// <summary>
607
606
/// Common validation called by ProcessAsFile and UnzipAndProcess to ensure same order and checks made
608
607
/// </summary>
609
- /// <param name="filename "></param>
608
+ /// <param name="filePath "></param>
610
609
/// <param name="languageInfo"></param>
611
610
/// <param name="fileLength">should be > zero if called from unzip method</param>
612
611
/// <returns></returns>
613
- bool FileChecksPassed ( string filename , ref LanguageInfo languageInfo , long fileLength = 0 )
612
+ bool FileChecksPassed ( string filePath , ref LanguageInfo languageInfo , long fileLength = 0 )
614
613
{
615
- _appProfile . MetaData . FileExtensions . Add ( Path . GetExtension ( filename ) . Replace ( '.' , ' ' ) . TrimStart ( ) ) ;
614
+ _appProfile . MetaData . FileExtensions . Add ( Path . GetExtension ( filePath ) . Replace ( '.' , ' ' ) . TrimStart ( ) ) ;
616
615
617
616
// 1. Skip files written in unknown language
618
- if ( ! Language . FromFileName ( filename , ref languageInfo ) )
617
+ if ( ! Language . FromFileName ( filePath , ref languageInfo ) )
619
618
{
620
- WriteOnce . SafeLog ( ErrMsg . FormatString ( ErrMsg . ID . ANALYZE_LANGUAGE_NOTFOUND , filename ) , LogLevel . Warn ) ;
619
+ WriteOnce . SafeLog ( ErrMsg . FormatString ( ErrMsg . ID . ANALYZE_LANGUAGE_NOTFOUND , filePath ) , LogLevel . Warn ) ;
621
620
_appProfile . MetaData . FilesSkipped ++ ;
622
621
return false ;
623
622
}
624
623
625
624
_appProfile . MetaData . AddLanguage ( languageInfo . Name ) ;
626
625
627
626
// 2. Skip excluded files i.e. sample, test or similar unless ignore filter requested
628
- if ( ! _arg_allowSampleFiles && _fileExclusionList . Any ( v => filename . ToLower ( ) . Contains ( v ) ) )
627
+ if ( _fileExclusionList . Any ( v => filePath . ToLower ( ) . Contains ( v ) ) )
629
628
{
630
- WriteOnce . SafeLog ( ErrMsg . FormatString ( ErrMsg . ID . ANALYZE_EXCLUDED_TYPE_SKIPPED , filename ) , LogLevel . Warn ) ;
629
+ WriteOnce . SafeLog ( ErrMsg . FormatString ( ErrMsg . ID . ANALYZE_EXCLUDED_TYPE_SKIPPED , filePath ) , LogLevel . Warn ) ;
631
630
_appProfile . MetaData . FilesSkipped ++ ;
632
631
return false ;
633
632
}
634
633
635
634
// 3. Skip if exceeds file size limits
636
635
try
637
636
{
638
- fileLength = fileLength <= 0 ? new FileInfo ( filename ) . Length : fileLength ;
637
+ fileLength = fileLength <= 0 ? new FileInfo ( filePath ) . Length : fileLength ;
639
638
if ( fileLength > MAX_FILESIZE )
640
639
{
641
- WriteOnce . SafeLog ( ErrMsg . FormatString ( ErrMsg . ID . ANALYZE_FILESIZE_SKIPPED , filename ) , LogLevel . Warn ) ;
640
+ WriteOnce . SafeLog ( ErrMsg . FormatString ( ErrMsg . ID . ANALYZE_FILESIZE_SKIPPED , filePath ) , LogLevel . Warn ) ;
642
641
_appProfile . MetaData . FilesSkipped ++ ;
643
642
return false ;
644
643
}
645
644
}
646
645
catch ( Exception )
647
646
{
648
- throw new OpException ( ErrMsg . FormatString ( ErrMsg . ID . CMD_INVALID_FILE_OR_DIR , filename ) ) ;
647
+ throw new OpException ( ErrMsg . FormatString ( ErrMsg . ID . CMD_INVALID_FILE_OR_DIR , filePath ) ) ;
649
648
}
650
649
651
650
return true ;
0 commit comments