Skip to content

Commit

Permalink
fixed leading comment issues
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdavis2 committed Apr 20, 2022
1 parent 68c94d7 commit a02e31b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
description: removes unused prefixes from .ttl files and sorts the remaining prefixes alphabetically
entry: clean_ttl_hook
language: python
files: '.+\.ttl$'
files: '.*\.ttl$'
13 changes: 7 additions & 6 deletions clean_ttl_hook/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@


# removes unused namespace entries and re-serializes a graph with the prefixes in sorted order
def clean_ttl(input_file_path:Path):
#get a list of all leading comments in the file
def clean_ttl(input_file_path: Path):
# get a list of all leading comments in the file
input_file_path = Path(input_file_path)
comments_list = []
comment_flag = False
with open(input_file_path, "r", encoding='utf-8', errors='ignore') as f:
with open(input_file_path, "r", encoding="utf-8", errors="ignore") as f:
for index, line in enumerate(f):
if len(line.strip()) > 0 and line.strip()[0] == '#' and index == 0:
if len(line.strip()) > 0 and line.strip()[0] == "#" and index == 0:
comments_list.append(line.strip()[1:])
comment_flag = True

elif len(line.strip()) > 0 and line.strip()[0] == '#' and comment_flag:
elif len(line.strip()) > 0 and line.strip()[0] == "#" and comment_flag:
comments_list.append(line.strip()[1:])

elif len(line.strip()) > 0 and line.strip()[0] != '#':
elif len(line.strip()) > 0 and line.strip()[0] != "#":
comment_flag = False

elif not comment_flag:
Expand Down

0 comments on commit a02e31b

Please sign in to comment.