Skip to content

Commit 969917d

Browse files
author
Frances Hocutt
committed
Fix filepath bug in openlinter.rules.check_file_presence()
There was an issue where the script was looking for files in the directory it was being run from, not the location it was given. Fixed. Improved a variable name.
1 parent d969a44 commit 969917d

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

openlinter/rules.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,20 @@ def check_file_presence(keyword, directory):
3939
files = os.listdir(directory)
4040
# this is unfortunately nested, FIXME?
4141
for f in files:
42-
if os.path.isfile(f):
42+
if os.path.isfile(os.path.join(directory, f)):
4343
# in case there's anything in the path that matches keyword,
4444
# only match the filename
4545
filename = os.path.split(f)[1]
4646
if keyword in filename:
47-
if check_for_file_content(os.path.join(directory,f)):
48-
return True
49-
else:
50-
return None
51-
47+
return True
5248
# if loop finishes, file name not found
5349
return False
5450

5551

56-
def check_for_file_content(filename):
52+
def check_for_file_content(filepath):
5753
"""Return True if the file has > 0 B, False otherwise."""
5854
# note this gives FileNotFoundError if there is no file at filepath
59-
return os.path.getsize(filename) > 0
55+
return os.path.getsize(filepath) > 0
6056

6157

6258
def check_for_code(directory):

0 commit comments

Comments
 (0)