Skip to content

Commit e247bde

Browse files
author
Sergey Vilgelm
committed
Ignoring empty files
Add `file-header-ignore-empty-files` configuration option to ignore empty files
1 parent a35c450 commit e247bde

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

pylintfileheader/file_header_checker.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,27 @@ class FileHeaderChecker(BaseChecker):
3636
'help': 'The file header that should be on top of a file.',
3737
}
3838
),
39+
(
40+
'file-header-ignore-empty-files',
41+
{
42+
'default': False,
43+
'type': 'yn',
44+
'help': 'Ignoring the empty files.',
45+
}
46+
),
3947
)
4048

4149
def process_module(self, node):
4250
"""Process the astroid node stream."""
4351
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+
4460
if sys.version_info[0] < 3:
4561
pattern = re.compile(
4662
r'\A' + self.config.file_header, re.LOCALE | re.MULTILINE)
@@ -49,11 +65,6 @@ def process_module(self, node):
4965
pattern = re.compile(
5066
r'\A' + self.config.file_header, re.MULTILINE)
5167

52-
content = None
53-
with node.stream() as stream:
54-
# Explicit decoding required by python 3
55-
content = stream.read().decode('utf-8')
56-
5768
matches = pattern.findall(content)
5869

5970
if len(matches) != 1:

0 commit comments

Comments
 (0)