@@ -24,7 +24,7 @@ def __get__(self, cls, owner):
2424 return classmethod (self .fget ).__get__ (None , owner )()
2525
2626
27- class BasePlugin ( object ) :
27+ class BasePlugin :
2828 """
2929 This is an abstract class to define Plugins API.
3030
@@ -70,17 +70,15 @@ def __init__(
7070 :param false_positive_heuristics: List of fp-heuristic functions
7171 applicable to this plugin
7272 """
73- self .exclude_lines_regex = None
74- if exclude_lines_regex :
75- self .exclude_lines_regex = re .compile (exclude_lines_regex )
73+ self .exclude_lines_regex = (
74+ re .compile (exclude_lines_regex )
75+ if exclude_lines_regex
76+ else None
77+ )
7678
7779 self .should_verify = should_verify
7880
79- self .false_positive_heuristics = (
80- false_positive_heuristics
81- if false_positive_heuristics
82- else []
83- )
81+ self .false_positive_heuristics = false_positive_heuristics or []
8482
8583 @classproperty
8684 def disable_flag_text (cls ):
@@ -101,6 +99,19 @@ def disable_flag_text(cls):
10199 def default_options (cls ):
102100 return {}
103101
102+ def _is_excluded_line (self , line ):
103+ return (
104+ any (
105+ allowlist_regex .search (line )
106+ for allowlist_regex in ALLOWLIST_REGEXES
107+ )
108+ or
109+ (
110+ self .exclude_lines_regex and
111+ self .exclude_lines_regex .search (line )
112+ )
113+ )
114+
104115 def analyze (self , file , filename ):
105116 """
106117 :param file: The File object itself.
@@ -114,6 +125,13 @@ def analyze(self, file, filename):
114125 file_lines = tuple (file .readlines ())
115126 for line_num , line in enumerate (file_lines , start = 1 ):
116127 results = self .analyze_line (line , line_num , filename )
128+ if (
129+ not results
130+ or
131+ self ._is_excluded_line (line )
132+ ):
133+ continue
134+
117135 if not self .should_verify :
118136 potential_secrets .update (results )
119137 continue
@@ -146,18 +164,6 @@ def analyze_line(self, string, line_num, filename):
146164
147165 NOTE: line_num and filename are used for PotentialSecret creation only.
148166 """
149- if (
150- any (
151- allowlist_regex .search (string ) for allowlist_regex in ALLOWLIST_REGEXES
152- )
153-
154- or (
155- self .exclude_lines_regex and
156- self .exclude_lines_regex .search (string )
157- )
158- ):
159- return {}
160-
161167 return self .analyze_string_content (
162168 string ,
163169 line_num ,
0 commit comments