File tree Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Expand file tree Collapse file tree 1 file changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -36,11 +36,27 @@ class FileHeaderChecker(BaseChecker):
36
36
'help' : 'The file header that should be on top of a file.' ,
37
37
}
38
38
),
39
+ (
40
+ 'file-header-ignore-empty-files' ,
41
+ {
42
+ 'default' : False ,
43
+ 'type' : 'yn' ,
44
+ 'help' : 'Ignoring the empty files.' ,
45
+ }
46
+ ),
39
47
)
40
48
41
49
def process_module (self , node ):
42
50
"""Process the astroid node stream."""
43
51
if self .config .file_header :
52
+ content = None
53
+ with node .stream () as stream :
54
+ # Explicit decoding required by python 3
55
+ content = stream .read ().decode ('utf-8' )
56
+
57
+ if self .config .file_header_ignore_empty_files and not content :
58
+ return
59
+
44
60
if sys .version_info [0 ] < 3 :
45
61
pattern = re .compile (
46
62
r'\A' + self .config .file_header , re .LOCALE | re .MULTILINE )
@@ -49,11 +65,6 @@ def process_module(self, node):
49
65
pattern = re .compile (
50
66
r'\A' + self .config .file_header , re .MULTILINE )
51
67
52
- content = None
53
- with node .stream () as stream :
54
- # Explicit decoding required by python 3
55
- content = stream .read ().decode ('utf-8' )
56
-
57
68
matches = pattern .findall (content )
58
69
59
70
if len (matches ) != 1 :
You can’t perform that action at this time.
0 commit comments